Skip to content
Memory corruption Disclosed report Advanced CVE-2026-12291

Use-after-free in ScriptLoadHandler::DoOnStreamComplete via dangling `this` captured by `notifyStop` ScopeExit

A use-after-free occurs in Firefox's ScriptLoadHandler::DoOnStreamComplete because a ScopeExit lambda captures `this` and runs after attacker-controlled script has executed, allowing the object to be freed by the cycle collector. An attacker could trigger a heap-buffer-overflow read through the dangling pointer, potentially leading to memory corruption.

Zijie Zhao Follow

Originally disclosed on Mozilla

  • Fixed in 27 days
  • Paid in 51 days
  • Disclosed after 27 days

Created attachment 9582989 poc.zip

Steps to reproduce:

With an asan build of firefox:

  • unzip poc.zip && cd poc && python server.py
  • MOZ_FORCE_DISABLE_E10S=1 MOZ_DISABLE_CONTENT_SANDBOX=1 ./path/to/asan/firefox --headless --no-remote --profile "$(mktemp -d)" http://127.0.0.1:8899/poc.html

Actual results:

==2093010==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x70287a0a3d48 at pc 0x6fa869b543af bp 0x7ffc698c1410 sp 0x7ffc698c1408
READ of size 8 at 0x70287a0a3d48 thread T0
    #0 0x6fa869b543ae in get .../firefox/obj-ff-asan/dist/include/mozilla/RefPtr.h:312:27
    #1 0x6fa869b543ae in operator-> .../firefox/obj-ff-asan/dist/include/mozilla/RefPtr.h:342:12
    #2 0x6fa869b543ae in operator() .../firefox/obj-ff-asan/dom/script/./../../../dom/script/ScriptLoadHandler.cpp:510:13
    #3 0x6fa869b543ae in ~ScopeExit .../firefox/obj-ff-asan/dist/include/mozilla/ScopeExit.h:104:7
    #4 0x6fa869b543ae in mozilla::dom::ScriptLoadHandler::DoOnStreamComplete(nsIChannel*, nsresult, unsigned int, unsigned char const*) .../firefox/obj-ff-asan/dom/script/./../../../dom/script/ScriptLoadHandler.cpp:595:1
    #5 0x6fa869b51cf1 in mozilla::dom::ScriptLoadHandler::OnStreamComplete(nsIIncrementalStreamLoader*, nsISupports*, nsresult, unsigned int, unsigned char const*) .../firefox/obj-ff-asan/dom/script/./../../../dom/script/ScriptLoadHandler.cpp:415:12
    #6 0x6fa85e02708e in nsIncrementalStreamLoader::OnStopRequest(nsIRequest*, nsresult) .../firefox/obj-ff-asan/netwerk/base/./../../../netwerk/base/nsIncrementalStreamLoader.cpp:86:20
    #7 0x6fa85e123def in mozilla::net::nsStreamListenerTee::OnStopRequest(nsIRequest*, nsresult) .../firefox/obj-ff-asan/netwerk/base/./../../../netwerk/base/nsStreamListenerTee.cpp:52:28
    #8 0x6fa85edc8b7f in mozilla::net::nsHttpChannel::ContinueOnStopRequest(nsresult, bool, bool) .../firefox/obj-ff-asan/netwerk/protocol/http/./../../../../netwerk/protocol/http/nsHttpChannel.cpp:10374:16
    #9 0x6fa85edc5bb8 in mozilla::net::nsHttpChannel::ContinueOnStopRequestAfterAuthRetry(nsresult, bool, bool, bool, mozilla::net::HttpTransactionShell*) .../firefox/obj-ff-asan/netwerk/protocol/http/./../../../../netwerk/protocol/http/nsHttpChannel.cpp
    #10 0x6fa85edc34cd in mozilla::net::nsHttpChannel::OnStopRequest(nsIRequest*, nsresult) .../firefox/obj-ff-asan/netwerk/protocol/http/./../../../../netwerk/protocol/http/nsHttpChannel.cpp:9995:12
    #11 0x6fa85e03da78 in nsInputStreamPump::OnStateStop() .../firefox/obj-ff-asan/netwerk/base/./../../../netwerk/base/nsInputStreamPump.cpp:735:15
    #12 0x6fa85e03bc52 in nsInputStreamPump::OnInputStreamReady(nsIAsyncInputStream*) .../firefox/obj-ff-asan/netwerk/base/./../../../netwerk/base/nsInputStreamPump.cpp:442:21
    #13 0x6fa85dba3c87 in operator() .../.mozbuild/sysroot-x86_64-linux-gnu/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_function.h:622:14
    #14 0x6fa85dba3c87 in PipeCallbackRunnable::Run() .../firefox/obj-ff-asan/xpcom/io/./../../../xpcom/io/nsPipe3.cpp:74:7
    #15 0x6fa85dc1401a in mozilla::RunnableTask::Run() .../firefox/obj-ff-asan/xpcom/threads/./../../../xpcom/threads/TaskController.cpp:719:16
    #16 0x6fa85dc02ea5 in mozilla::TaskController::RunTask(mozilla::Task*) .../firefox/obj-ff-asan/xpcom/threads/./../../../xpcom/threads/TaskController.cpp:210:19
    #17 0x6fa85dc0a011 in mozilla::TaskController::DoExecuteNextTaskOnlyMainThreadInternal(mozilla::detail::BaseAutoLock<mozilla::Mutex&> const&) .../firefox/obj-ff-asan/xpcom/threads/./../../../xpcom/threads/TaskController.cpp:1358:20
    #18 0x6fa85dc07a58 in mozilla::TaskController::ExecuteNextTaskOnlyMainThreadInternal(mozilla::detail::BaseAutoLock<mozilla::Mutex&> const&) .../firefox/obj-ff-asan/xpcom/threads/./../../../xpcom/threads/TaskController.cpp:1181:15
    #19 0x6fa85dc08076 in mozilla::TaskController::ProcessPendingMTTask(bool) .../firefox/obj-ff-asan/xpcom/threads/./../../../xpcom/threads/TaskController.cpp:655:36
    #20 0x6fa85dc0b061 in operator() .../firefox/obj-ff-asan/xpcom/threads/./../../../xpcom/threads/TaskController.cpp:347:37

The exact ASan error might differ based on timing.

Tested on commit a353242aeafd.

Expected results:

No ASan error.

Analysis

DoOnStreamComplete installs a ScopeExit that touches this:

https://searchfox.org/firefox-main/rev/a353242aeafd56b2c21a2c0672ecb51ea1b81142/dom/script/ScriptLoadHandler.cpp#509-510

C++
  auto notifyStop = MakeScopeExit(
      [&] { mRequest->GetScriptLoadContext()->NotifyStop(aChannel, rv); });

[&] captures this so mRequest resolves. After installing the ScopeExit, DoOnStreamComplete runs the script, which is attacker JS. That JS detaches its own iframe and spins the event loop with sync XHR; the cycle collector frees the now-unreferenced ScriptLoadHandler (and with it, the ScriptLoadRequest held only by mRequest). When the ScopeExit fires on unwind, this is dangling and the lambda reads through it into freed memory.

Note (not reproduced): ScriptLoader::EvaluateScriptElement has the same shape one frame deeper — a raw Document* ownerDoc captured by a ScopeExit whose body runs after the same arbitrary JS (ScriptLoader.cpp:3147-3148, 3201-3205). It might be worth a look.

This was found while analyzing commit 1331fe5d7.

Please let me know if I can provide any extra information, thanks!

The original report as published on Mozilla's Bugzilla, by Zijie Zhao. 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

Root cause

A ScopeExit lambda captures `this` by reference and dereferences it after running attacker-controlled script that can cause the owning object to be freed.

Impact

The dangling pointer read could lead to memory corruption, though the exact ASan error may vary with timing and the report does not demonstrate code execution.

What the attacker needed

ASan Firefox build; e10s and content sandbox disabled; victim loads attacker page

How it was found

  1. Build Firefox with AddressSanitizer and unpack the proof-of-concept archive.
  2. Start the bundled Python server that hosts the test page.
  3. Launch the ASan Firefox in headless mode with the content sandbox and e10s disabled, pointing at the local test page.
  4. Observe the AddressSanitizer heap-buffer-overflow report.

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 loads a script, Firefox uses an internal object to track that load. A cleanup routine was set up to run at the end, but it kept a pointer to that object without keeping it alive. If the script itself causes the object to be thrown away before the cleanup runs, the cleanup then reads from memory that has already been freed, which is a use-after-free bug.

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 Zijie Zhao

View all

2 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.