Use-After-Free in StyleSheet::mAdopters with document or shadow root
Firefox's adoptedStyleSheets implementation desynchronises a JavaScript array from the C++ StyleSheet::mAdopters list, leaving a dangling pointer after a ShadowRoot is freed. An attacker can trigger this from content JavaScript without user interaction and reclaim the freed memory with controlled data to achieve controlled memory writes.
Originally disclosed on Mozilla
- Fixed in 9 days
- Paid in 15 days
- Disclosed after 9 days
A use-after-free exists in Firefox's adoptedStyleSheets implementation. The ObservableArray backing ShadowRoot.adoptedStyleSheets uses a plain JS Array whose indices are subject to prototype setter interception. An attacker can exploit this to desynchronize the backing array from the C++ StyleSheet::mAdopters list, leaving a dangling raw pointer after the ShadowRoot is freed. Subsequent stylesheet mutations dereference this pointer into freed heap memory.
The vulnerability is triggered entirely from content JavaScript with no user interaction. The freed memory can be reclaimed with attacker-controlled data, enabling controlled memory writes within the content process.
Attached deliverables:
1. adoptedstylesheets-shadowroot-stale-adopter-uaf-min3.xhtml -- Minimal PoC (ASAN crash)
2. forcedirty-addr.xhtml -- Write primitive to attacker-specified address (Requires Infoleak)
3. asan-report.txt -- Minimal PoC ASAN stack trace
4. uaf-spray-write.txt -- Forcedirty PoC GDB session showing register control
Affected Versions: Firefox Nightly, Release (tested on build f8c6433acfd27bcf33dd362940cb6b13d68e32fb)
Affected Component: layout/style/StyleSheet.cpp, dom/base/Element.cpp
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 ObservableArray backing adoptedStyleSheets uses a plain JS Array whose indices can be intercepted by prototype setters, so the JS view and the C++ adopter list fall out of sync.
Impact
The freed memory can be reclaimed with attacker-controlled data, enabling controlled memory writes within the content process; the write primitive requires an infoleak.
What the attacker needed
Victim loads attacker page; no user interaction needed
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 adds a stylesheet to a shadow root, the browser keeps two records of it: one in JavaScript and one in the browser's own memory. The report says these two records can be made to disagree, so the browser later uses a memory slot that has already been freed. Because the attacker can put their own data in that freed slot, they may be able to control what the browser writes.
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.