Use After Free in IndexedDB
A use-after-free flaw existed in IndexedDB index update handling: a JavaScript getter triggered during array element access could delete the index and free a locale string that the code then kept using. An attacker could exploit this to corrupt memory in the browser process, potentially leading to code execution.
Originally disclosed on Mozilla
- Fixed in 33 days
- Paid in 40 days
- Disclosed after 33 days
Created attachment 9088647
IndexedDB_UAF.html
'''cpp
void IDBObjectStore::AppendIndexUpdateInfo(
int64_t aIndexID, const KeyPath& aKeyPath, bool aUnique, bool aMultiEntry,
const nsCString& aLocale, JSContext* aCx, JS::Handle<JS::Value> aVal,
nsTArray<IndexUpdateInfo>& aUpdateInfoArray, ErrorResult& aRv) {
const bool localeAware = !aLocale.IsEmpty();
if (!aMultiEntry) {
...
return;
}
JS::Rooted<JS::Value> val(aCx);
if (NS_FAILED(aKeyPath.ExtractKeyAsJSVal(aCx, aVal, val.address()))) {
return;
}
bool isArray;
if (!JS_IsArrayObject(aCx, val, &isArray)) {
IDB_REPORT_INTERNAL_ERR();
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
return;
}
if (isArray) {
JS::Rooted<JSObject*> array(aCx, &val.toObject());
uint32_t arrayLength;
if (NS_WARN_IF(!JS_GetArrayLength(aCx, array, &arrayLength))) {
IDB_REPORT_INTERNAL_ERR();
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
return;
}
for (uint32_t arrayIndex = 0; arrayIndex < arrayLength; arrayIndex++) {
JS::Rooted<JS::Value> arrayItem(aCx);
if (NS_WARN_IF(!JS_GetElement(aCx, array, arrayIndex, &arrayItem))) { // JS_GetElement can trigger js getter, call deleteIndex here will free `aLocale`.
IDB_REPORT_INTERNAL_ERR();
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
return;
}
Key value;
auto result = value.SetFromJSVal(aCx, arrayItem, aRv);
if (!result.Is(Ok, aRv) || value.IsUnset()) {
// Not a value we can do anything with, ignore it.
aRv.SuppressException();
continue;
}
IndexUpdateInfo* updateInfo = aUpdateInfoArray.AppendElement();
updateInfo->indexId() = aIndexID;
updateInfo->value() = value;
if (localeAware) {
auto result =
value.ToLocaleBasedKey(updateInfo->localizedValue(), aLocale, aRv);// UAF occurs!
if (NS_WARN_IF(!result.Is(Ok, aRv))) {
if (result.Is(Invalid, aRv)) {
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
}
return;
}
}
}
} else {
...
}
}
'''
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
What the attacker needed
Victim visits a malicious web page; page uses IndexedDB with a multiEntry index
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a web page stores data in the browser's built-in database (IndexedDB), the browser reads values from JavaScript arrays. A page can attach a getter, a function that runs automatically when a value is read. That function can delete the index, which frees memory the browser code is still holding, so later use touches freed memory. This kind of bug can crash the browser or, in the worst case, let an attacker run their own code.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.