Skip to content
Memory corruption Disclosed report Advanced CVE-2019-11752

Use after free in KeyPath::ExtractKey

A use-after-free flaw exists in IndexedDB key path extraction because appending a value to the key can run a JavaScript getter, and that getter can delete the index while the code still holds a reference to it. An attacker could trigger the freed object to be used again, which may lead to memory corruption or a crash.

zhanjiasong45 Follow

Originally disclosed on Mozilla

  • Fixed in 10 months
  • Paid in 10 months
  • Disclosed after 10 months
Text
Created attachment 9019240
FireFox_IndexedDB_UAF3.html

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))) { // aKey.AppendItem can execute js getter (AppendItem => EncodeJSVal =>  EncodeJSValInternal => JS_GetElement)
      NS_ASSERTION(aKey.IsUnset(), "Encoding error should unset");
      return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
    }
  }

  aKey.FinishArray();

  return NS_OK;
}

aKey.AppendItem can execute js getter, call deleteIndex in the getter will cause UAF.

The original report as published on Mozilla's Bugzilla, by zhanjiasong45. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

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

Impact

An attacker could cause a use-after-free in the browser, which may lead to a crash or potentially exploitable memory corruption.

What the attacker needed

Victim loads a crafted page; JavaScript enabled

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 browser stores data in IndexedDB, it sometimes runs small pieces of your own JavaScript code (called getters) to read values. This report shows that such code can delete the index being processed while the browser is still using it, leaving it pointing at memory that has been freed. That is called a use-after-free, and it 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.

More by zhanjiasong45

View all

3 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.