EventSource MessageEvent.origin reports stale pre-redirect origin after cross-origin redirect, bypassing e.origin checks
Categories
(Core :: DOM: Networking, defect)
Tracking
()
People
(Reporter: tjr, Assigned: jjaschke)
Details
(Keywords: ai-involved, sec-moderate, testcase, Whiteboard: [adv-main155+r][adv-esr153.2+r])
Attachments
(4 files, 3 external files)
EventSourceImpl::ParseURL (dom/base/EventSource.cpp:546-565) computes the web-exposed origin serialization once from the URL passed to the EventSource constructor and stores it in mOrigin. When the connection is redirected, EventSourceImpl::AsyncOnChannelRedirect (dom/base/EventSource.cpp:832-878) accepts the redirect (http/https scheme check only; cross-origin targets are admitted under CORS because the channel is opened with nsILoadInfo::SEC_REQUIRE_CORS_INHERITS_SEC_CONTEXT, dom/base/EventSource.cpp:1033-1034) and updates mHttpChannel — and mSrc for permanent redirects — but never recomputes mOrigin. EventSourceImpl::DispatchAllMessageEvents (dom/base/EventSource.cpp:1537-1539) then initializes every MessageEvent with the stale mOrigin. The WHATWG HTML server-sent-events dispatch steps require the event's origin attribute to be the serialization of the origin of the event stream's final URL (the URL after redirects). Consequence: if a page on a victim origin opens an EventSource to a same-origin URL that redirects (e.g. via an open redirect) to an attacker-controlled SSE endpoint served with Access-Control-Allow-Origin: *, every delivered message carries the victim origin in e.origin. The recommended defensive pattern of checking e.origin on message events therefore passes on attacker-controlled data. This was reproduced empirically on the current tree with no source modifications: a page on http://localhost:8808 opened new EventSource("/redirect") which 302-redirected to http://127.0.0.1:8808/sse (a genuinely different origin, confirmed independently in-page via fetch().url); the attacker sentinel arrived with e.origin=http://localhost:8808.
Build Info
- Branch: main
- Revision: ca6e9493686b3e5ed1cddb8d3a3974068463df71
- Timestamp: 2026-07-29T00:55:15+00:00
Affected Code
File: dom/base/EventSource.cpp, line 546-566
nsAutoString origin;
rv = nsContentUtils::GetWebExposedOriginSerialization(srcURI, origin);
NS_ENSURE_SUCCESS(rv, rv);
...
mSrc = std::move(srcURI);
mOrigin = std::move(origin); // set once from the constructor URL; ParseURL is only called from Init (line 596)
File: dom/base/EventSource.cpp, line 861-877
// update our channel
mHttpChannel = do_QueryInterface(aNewChannel);
NS_ENSURE_STATE(mHttpChannel);
SetupHttpChannel();
...
if ((aFlags & nsIChannelEventSink::REDIRECT_PERMANENT) != 0) {
rv = NS_GetFinalChannelURI(mHttpChannel, getter_AddRefs(mSrc));
NS_ENSURE_SUCCESS(rv, rv);
}
// NOTE: mOrigin is never recomputed here
File: dom/base/EventSource.cpp, line 1537-1539
event->InitMessageEvent(nullptr, message->mEventName, CanBubble::eNo,
Cancelable::eNo, jsData, mOrigin, mLastEventID,
nullptr, Sequence<OwningNonNull<MessagePort>>());
mOrigin is assigned exactly once at construction time and reused for every dispatched message; the redirect hook never updates it. grep shows mOrigin appears only at lines 248 (declaration), 565 (assignment), and 1538 (use).
Exploit Chain
- Victim page on origin A calls new EventSource(url) where url is a same-origin (origin A) endpoint the attacker can make redirect, e.g. an open redirect.
- EventSourceImpl::ParseURL stores mOrigin = serialization of origin A (dom/base/EventSource.cpp:546-565).
- The endpoint 302-redirects to an attacker SSE endpoint on origin B that serves Content-Type: text/event-stream with Access-Control-Allow-Origin: *; AsyncOnChannelRedirect accepts the redirect under CORS but does not update mOrigin (dom/base/EventSource.cpp:832-878).
- Attacker-controlled events from origin B are dispatched to the victim page with e.origin = origin A (dom/base/EventSource.cpp:1537-1539).
- A consumer guard of the form e.origin === location.origin (or an allow-list of trusted origins) passes, and the victim page processes attacker-controlled data as if it came from its own origin.
Steps to Reproduce
- Build Firefox ASAN from an unmodified tree (mozconfig.linux.asan.fuzzing).
- Start the bundled two-origin server: python3 sse_server.py (binds 0.0.0.0:8808; http://localhost:8808 is the victim origin hosting /victim.html and an open redirect at /redirect -> http://127.0.0.1:8808/sse; http://127.0.0.1:8808 is the attacker origin serving /sse as text/event-stream with Access-Control-Allow-Origin: * and payload 'data: CLAUDITOR_SENTINEL_9f3c2a71').
- Run testcase.html under browser_evaluator with prefs {"browser.dom.window.dump.enabled": true} (logging only); the testcase navigates to http://localhost:8808/victim.html.
- Observe in stderr the proof lines: e.origin=http://localhost:8808 while the independently-fetched final response URL origin is http://127.0.0.1:8808, and the attacker sentinel data passed the 'e.origin === location.origin' guard.
Security Impact
- Severity: Moderate
- Attacker capability: Injection of attacker-controlled SSE message data past an e.origin check in web content: messages actually served by an attacker origin are delivered with the victim origin in MessageEvent.origin, so origin-based trust decisions made by the consuming page are made on false provenance. No memory corruption and no process-boundary crossing is involved.
- Preconditions: The victim origin must expose a redirect the attacker can point at their SSE endpoint (e.g. an open redirect) at the URL the victim passes to new EventSource(); the attacker endpoint must serve text/event-stream with permissive CORS (Access-Control-Allow-Origin: * suffices for a non-credentialed EventSource); and the victim page must rely on e.origin for trust decisions on SSE message events.
ASAN Report
Non-crash logic-bug class; evidence is the proof string captured from browser stderr on an unmodified build:
[Child 6505: Main Thread]: I/console log: "VICTIM-PAGE-LOADED origin=http://localhost:8808"
[Child 6505: Main Thread]: I/console log: "EVENTSOURCE-POC e.origin=http://localhost:8808 page.origin=http://localhost:8808 final-response-url-origin=http://127.0.0.1:8808 data=CLAUDITOR_SENTINEL_9f3c2a71"
[Child 6505: Main Thread]: I/console log: "POC-CONFIRMED: CLAUDITOR_SENTINEL_9f3c2a71 | attacker SSE data delivered with stale pre-redirect origin: e.origin=http://localhost:8808 (victim) but actual final endpoint origin=http://127.0.0.1:8808 (attacker); 'e.origin === location.origin' guard PASSED on attacker data"
Server request log confirms the sentinel body was served only for Host 127.0.0.1:8808 (/sse); /redirect on localhost:8808 returned a bodyless 302.
| Reporter | ||
Comment 1•3 months ago
|
||
| Reporter | ||
Comment 2•3 months ago
|
||
| Reporter | ||
Comment 3•3 months ago
|
||
| Reporter | ||
Comment 4•3 months ago
|
||
| Reporter | ||
Comment 5•3 months ago
|
||
This bug was filed automatically by an AI-powered security testing tool. The analysis, testcase, and any suggested patches were generated by an AI model and have NOT been verified by a human.
Please review all details carefully before triaging. The issue was confirmed by an independent verifier, but for non-ASAN issues, the verifier has been made less strict. Additionally, the root cause analysis and suggested fix may contain errors.
| Reporter | ||
Updated•3 months ago
|
| Assignee | ||
Comment 6•2 months ago
|
||
Updated•2 months ago
|
| Assignee | ||
Updated•2 months ago
|
Updated•2 months ago
|
Comment 7•2 months ago
|
||
:jjaschke, please update all release status flags to reflect the affected/unaffected/disabled state correctly. Which branches (beta, release, and/or ESR) are affected by this flaw?
| Assignee | ||
Updated•2 months ago
|
Comment 9•2 months ago
|
||
| bugherder | ||
Comment 10•2 months ago
|
||
The patch landed in nightly and beta is affected, along with ESR.
:jjaschke, is this bug important enough to require an uplift?
- If yes, please nominate the patch for beta and ESR approvals.
- See https://wiki.mozilla.org/Release_Management/Requesting_an_Uplift for documentation on how to request an uplift.
- If no, please set
status-firefox155and the ESR status flag(s) towontfix.
For more information, please visit BugBot documentation.
Comment 11•2 months ago
|
||
Depending on the timing of the uplift request and risk, this may not make Fx155.
We can update the flags if it doesn't make Fx155, it would then ship later with Fx156 and the corresponding ESR153
Comment 12•2 months ago
|
||
firefox-beta Uplift Approval Request
- User impact if declined/Reason for urgency: Origin leaking after cross-origin redirect
- Code covered by automated testing?: yes
- Fix verified in Nightly?: yes
- Needs manual QE testing?: no
- Steps to reproduce for manual QE testing:
- Risk associated with taking this patch: low
- Explanation of risk level: The change is fairly trivial.
- String changes made/needed?: no
- Is Android affected?: yes
| Assignee | ||
Comment 13•2 months ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D320456
Comment 14•2 months ago
|
||
firefox-esr153 Uplift Approval Request
- User impact if declined/Reason for urgency: Origin leaking after cross-origin redirect
- Code covered by automated testing?: yes
- Fix verified in Nightly?: yes
- Needs manual QE testing?: no
- Steps to reproduce for manual QE testing:
- Risk associated with taking this patch: low
- Explanation of risk level: The change is fairly trivial.
- String changes made/needed?: no
- Is Android affected?: yes
| Assignee | ||
Comment 15•2 months ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D320456
| Assignee | ||
Updated•2 months ago
|
Updated•2 months ago
|
Updated•2 months ago
|
Updated•2 months ago
|
Comment 16•2 months ago
|
||
| uplift | ||
Updated•2 months ago
|
Updated•2 months ago
|
Comment 17•2 months ago
|
||
| uplift | ||
Updated•2 months ago
|
Updated•2 months ago
|
Updated•5 days ago
|
Description
•