Stack-use-after-scope in NS_strlen while logging errors in XHR
A stack-use-after-scope bug in Firefox's XHR error logging could cause a crash when a script sets a request header with an invalid name or value. The report shows an AddressSanitizer trace but does not demonstrate exploitation beyond the crash.
Originally disclosed on Mozilla
- Fixed in 4 days
- Paid in 29 days
- Disclosed after 4 days
Created attachment 8869834 Testcase
==10811==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7fff25529080 at pc 0x7faccf02f971 bp 0x7fff25527800 sp 0x7fff255277f8 READ of size 2 at 0x7fff25529080 thread T0 (Web Content) SCARINESS: 14 (2-byte-read-stack-use-after-scope) #0 0x7faccf02f970 in NS_strlen(char16_t const*) xpcom/base/nsCRTGlue.cpp:83:23 #1 0x7faccf00d50a in cvt_S(SprintfStateStr*, char16_t const*, int, int, int) xpcom/string/nsTextFormatter.cpp:522:17 #2 0x7faccf0095c1 in dosprintf(SprintfStateStr*, char16_t const*, __va_list_tag*) xpcom/string/nsTextFormatter.cpp:1139:14 #3 0x7faccf00655e in vsmprintf xpcom/string/nsTextFormatter.cpp:1307:8 #4 0x7faccf00655e in nsTextFormatter::smprintf(char16_t const*, ...) xpcom/string/nsTextFormatter.cpp:1265 #5 0x7faccf25fcae in nsStringBundle::FormatString(char16_t const*, char16_t const**, unsigned int, char16_t**) intl/strres/nsStringBundle.cpp:340:5 #6 0x7faccf25fa63 in nsStringBundle::FormatStringFromName(char16_t const*, char16_t const**, unsigned int, char16_t**) intl/strres/nsStringBundle.cpp:188:10 #7 0x7facd1aec35d in nsContentUtils::FormatLocalizedString(nsContentUtils::PropertiesFile, char const*, char16_t const**, unsigned int, nsXPIDLString&) dom/base/nsContentUtils.cpp:3867:18 #8 0x7facd1aecf99 in nsContentUtils::ReportToConsole(unsigned int, nsACString const&, nsIDocument const*, nsContentUtils::PropertiesFile, char const*, char16_t const**, unsigned int, nsIURI*, nsString const&, unsigned int, unsigned int) dom/base/nsContentUtils.cpp:3932:10 #9 0x7facd5ad43a5 in LogMessage dom/xhr/XMLHttpRequestMainThread.cpp:446:3 #10 0x7facd5ad43a5 in mozilla::dom::XMLHttpRequestMainThread::SetRequestHeader(nsACString const&, nsACString const&) dom/xhr/XMLHttpRequestMainThread.cpp:3115 #11 0x7facd5aef3dd in mozilla::dom::XMLHttpRequestMainThread::SetRequestHeader(nsACString const&, nsACString const&, mozilla::ErrorResult&) dom/xhr/XMLHttpRequestMainThread.h:274:11 #12 0x7facd3482163 in mozilla::dom::XMLHttpRequestBinding::setRequestHeader(JSContext*, JS::Handle<JSObject*>, mozilla::dom::XMLHttpRequest*, JSJitMethodCallArgs const&) objdir-ff-asan/dom/bindings/XMLHttpRequestBinding.cpp:461:9 #13 0x7facd3c97445 in mozilla::dom::GenericBindingMethod(JSContext*, unsigned int, JS::Value*) dom/bindings/BindingUtils.cpp:2954:13 #14 0x7facd9daf3a0 in CallJSNative js/src/jscntxtinlines.h:293:15 #15 0x7facd9daf3a0 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) js/src/vm/Interpreter.cpp:470 #16 0x7facd9d8c0dd in CallFromStack js/src/vm/Interpreter.cpp:521:12 #17 0x7facd9d8c0dd in Interpret(JSContext*, js::RunState&) js/src/vm/Interpreter.cpp:3028 #18 0x7facd9d79488 in js::RunScript(JSContext*, js::RunState&) js/src/vm/Interpreter.cpp:410:12 #19 0x7facd9db1a99 in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value const&, js::AbstractFramePtr, JS::Value*) js/src/vm/Interpreter.cpp:699:15 #20 0x7facd9db2332 in js::Execute(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value*) js/src/vm/Interpreter.cpp:731:12 #21 0x7facda7e28a9 in Evaluate(JSContext*, js::ScopeKind, JS::Handle<JSObject*>, JS::ReadOnlyCompileOptions const&, JS::SourceBufferHolder&, JS::MutableHandleJS::Value) js/src/jsapi.cpp:4633:19 #22 0x7facda7e3600 in Evaluate js/src/jsapi.cpp:4658:12 #23 0x7facda7e3600 in JS::Evaluate(JSContext*, JS::AutoObjectVector&, JS::ReadOnlyCompileOptions const&, JS::SourceBufferHolder&, JS::MutableHandleJS::Value) js/src/jsapi.cpp:4716 #24 0x7facd2011f52 in nsJSUtils::ExecutionContext::CompileAndExec(JS::CompileOptions&, JS::SourceBufferHolder&) dom/base/nsJSUtils.cpp:232:8 #25 0x7facd5b2b722 in mozilla::dom::ScriptLoader::EvaluateScript(mozilla::dom::ScriptLoadRequest*) dom/script/ScriptLoader.cpp:2035:23 #26 0x7facd5b27211 in mozilla::dom::ScriptLoader::ProcessRequest(mozilla::dom::ScriptLoadRequest*) dom/script/ScriptLoader.cpp:1753:10 #27 0x7facd5b0dc57 in mozilla::dom::ScriptLoader::ProcessScriptElement(nsIScriptElement*) dom/script/ScriptLoader.cpp:1455:10 #28 0x7facd5b0a13e in mozilla::dom::ScriptElement::MaybeProcessScript() dom/script/ScriptElement.cpp:149:18 #29 0x7facd10174e0 in AttemptToExecute objdir-ff-asan/dist/include/nsIScriptElement.h:225:18 #30 0x7facd10174e0 in nsHtml5TreeOpExecutor::RunScript(nsIContent*) parser/html/nsHtml5TreeOpExecutor.cpp:698 #31 0x7facd10105c5 in nsHtml5TreeOpExecutor::RunFlushLoop() parser/html/nsHtml5TreeOpExecutor.cpp:499:7 #32 0x7facd101a68b in nsHtml5ExecutorFlusher::Run() parser/html/nsHtml5StreamParser.cpp:129:20 #33 0x7faccf17fe74 in mozilla::SchedulerGroup::Runnable::Run() xpcom/threads/SchedulerGroup.cpp:365:25 #34 0x7faccf1af789 in nsThread::ProcessNextEvent(bool, bool*) xpcom/threads/nsThread.cpp:1302:14 #35 0x7faccf1bb2b0 in NS_ProcessNextEvent(nsIThread*, bool) xpcom/threads/nsThreadUtils.cpp:393:10 #36 0x7faccffeb741 in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) ipc/glue/MessagePump.cpp:96:21 #37 0x7faccff41cbf in RunInternal ipc/chromium/src/base/message_loop.cc:238:10 #38 0x7faccff41cbf in RunHandler ipc/chromium/src/base/message_loop.cc:231 #39 0x7faccff41cbf in MessageLoop::Run() ipc/chromium/src/base/message_loop.cc:211 #40 0x7facd5c4670a in nsBaseAppShell::Run() widget/nsBaseAppShell.cpp:156:27 #41 0x7facd98296fb in XRE_RunAppShell() toolkit/xre/nsEmbedFunctions.cpp:893:22 #42 0x7faccff41cbf in RunInternal ipc/chromium/src/base/message_loop.cc:238:10 #43 0x7faccff41cbf in RunHandler ipc/chromium/src/base/message_loop.cc:231 #44 0x7faccff41cbf in MessageLoop::Run() ipc/chromium/src/base/message_loop.cc:211 #45 0x7facd982918d in XRE_InitChildProcess(int, char**, XREChildData const*) toolkit/xre/nsEmbedFunctions.cpp:709:34 #46 0x5250c2 in content_process_main ipc/contentproc/plugin-container.cpp:64:30 #47 0x5250c2 in main browser/app/nsBrowserApp.cpp:285 #48 0x7face9ebaf44 in __libc_start_main /build/eglibc-MjiXCM/eglibc-2.19/csu/libc-start.c:287 Address 0x7fff25529080 is located in stack of thread T0 (Web Content) at offset 288 in frame #0 0x7facd5ad3dcf in mozilla::dom::XMLHttpRequestMainThread::SetRequestHeader(nsACString const&, nsACString const&) dom/xhr/XMLHttpRequestMainThread.cpp:3090 This frame has 5 object(s): [32, 40) 'doc.i' (line 442) [64, 80) 'ref.tmp.i' (line 446) [96, 192) 'value' (line 3102) [224, 232) 'params' (line 3114) [256, 416) 'ref.tmp' (line 3114) <== Memory access at offset 288 is inside this variable HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext (longjmp and C++ exceptions are supported) SUMMARY: AddressSanitizer: stack-use-after-scope (/mnt/scratch0/clusterfuzz/slave-bot/builds/linux_asan_firefox/custom/firefox/libxul.so+0x1f70970) Shadow bytes around the buggy address: 0x100064a9d1c0: 00 00 00 00 00 00 00 00 f1 f1 f1 f1 00 00 f3 f3 0x100064a9d1d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x100064a9d1e0: 00 00 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1 0x100064a9d1f0: 00 f2 f2 f2 00 00 f2 f2 00 00 00 00 00 00 00 00 0x100064a9d200: 00 00 00 00 f2 f2 f2 f2 00 f2 f2 f2 f8 f8 f8 f8 =>0x100064a9d210:[f8]f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 0x100064a9d220: f3 f3 f3 f3 f3 f3 f3 f3 00 00 00 00 00 00 00 00 0x100064a9d230: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x100064a9d240: f1 f1 f1 f1 00 00 f2 f2 00 00 f2 f2 00 00 f3 f3 0x100064a9d250: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x100064a9d260: 00 00 00 00 f1 f1 f1 f1 00 00 f2 f2 00 00 00 f2 Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb ==10811==ABORTING
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 a temporary string used in error logging is destroyed before the logging function finishes reading it, causing a stack-use-after-scope.
Impact
The bug could crash the browser content process, but the report does not show code execution or any other impact beyond the crash.
What the attacker needed
Victim visits a malicious page; JavaScript enabled
How it was found
- Create an XMLHttpRequest object in a script.
- Call setRequestHeader with an invalid header name or value to trigger error logging.
- Observe the AddressSanitizer stack-use-after-scope crash.
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.
This is a memory safety bug in Firefox. When JavaScript sets a request header on an XMLHttpRequest, the browser logs an error if the header is invalid. The logging code accidentally uses a temporary string after it has been destroyed, which can crash the browser. The report only shows a crash, not a way to run malicious 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.