Use After Free in indexedDB
A use-after-free flaw exists in Firefox's IndexedDB key path extraction, where a JavaScript getter callback can free the KeyPath object while it is still being used. An attacker could trigger this to corrupt memory, potentially leading to code execution.
Originally disclosed on Mozilla
- Fixed in 3 months
- Paid in 4 months
- Disclosed after 3 months
Created attachment 8973400
FireFox_IndexDB_UAF.html
User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
Steps to reproduce:
run firefox with attached html
Actual results:
https://searchfox.org/mozilla-central/source/dom/indexedDB/KeyPath.cpp#323
nsresult
KeyPath::ExtractKey(JSContext* aCx, const JS::Value& aValue, Key& aKey) const
{
uint32_t len = mStrings.Length();
JS::Rooted<JS::Value> value(aCx);
aKey.Unset();
for (uint32_t i = 0; i < len; ++i) {
nsresult rv = GetJSValFromKeyPathString(aCx, aValue, mStrings[i],
value.address(),
DoNotCreateProperties, nullptr,
nullptr);
if (NS_FAILED(rv)) {
return rv;
}
if (NS_FAILED(aKey.AppendItem(aCx, IsArray() && i == 0, value))) {
NS_ASSERTION(aKey.IsUnset(), "Encoding error should unset");
return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
}
}
aKey.FinishArray();
return NS_OK;
}
GetJSValFromKeyPathString can execute js callback by setting a getter. In the callback, one can call deleteIndex free the KeyPath now using, which make mStrings invalid.
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
Root cause
Likely the code iterates over mStrings while calling into JavaScript that can re-enter and free the KeyPath, leaving a dangling reference.
Impact
A use-after-free could crash the browser and may be exploitable for code execution, though the report does not demonstrate that.
What the attacker needed
Victim opens a crafted HTML page
How it was found
- Open the attached HTML file in Firefox.
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.
IndexedDB is a browser database that stores data in the page. Firefox reads a 'key path' to find where in an object the key lives, and reading that value can run JavaScript you supplied. If that JavaScript deletes the index mid-read, Firefox keeps using memory it has already freed, which is a use-after-free and can crash or be abused.
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.