RecvPBroadcastChannelConstructor accepts forged PrincipalInfo without process-isolation validation — real-time cross-origin BroadcastChannel eavesdrop and message injection demonstrated
Categories
(Core :: DOM: Workers, defect)
Tracking
()
People
(Reporter: sundersingh7747, Unassigned)
References
()
Details
(Keywords: reporter-external, Whiteboard: [client-bounty-form])
Attachments
(1 file)
|
366.45 KB,
application/x-gzip
|
Details |
Component: Core :: DOM: Workers
Filed against: mozilla-firefox/firefox main @ commit e374045fac6f19383a04d087d2930ced5c1551fe — Firefox Nightly 152.0a1
Severity claim: sandbox escape, Highest Impact tier. Per Mozilla's bounty matrix footnote 0, invoking an IPC method from a compromised content process with attacker-controlled parameters qualifies for Highest Impact regardless of the downstream primitive. This report demonstrates a distinct downstream primitive in this report: real-time bidirectional interception of cross-origin BroadcastChannel traffic, with injection of forged messages that arrive at victim listeners indistinguishable from legitimate same-origin events.
I have been auditing BackgroundParentImpl IPC handlers for the missing principal-validation pattern introduced by Bug 2020535. That fix added a five-line ValidatePrincipalCouldPotentiallyBeLoadedBy guard to RecvCreateMLSTransaction. The same guard was missing at other handlers in the same file. This report covers RecvPBroadcastChannelConstructor.
The impact of this bug is categorically different from storage-class sandbox escapes. Persistent storage attacks require knowledge of what the victim stores and leave artifacts on disk. BroadcastChannel requires no prior knowledge of what the victim transmits and operates in real time — the attacker passively receives whatever messages flow between the victim's own tabs. The injection primitive delivers commands that the victim's JavaScript cannot distinguish from messages sent by legitimate same-origin tabs, because MessageEvent.origin reflects the channel's registered origin, not the sender's true process identity.
The gap
BackgroundParentImpl::RecvPBroadcastChannelConstructor (ipc/glue/BackgroundParentImpl.cpp:845) accepts three arguments from the calling content process: aPrincipalInfo, aOrigin, and aChannel. It does not call dom::ValidatePrincipalCouldPotentiallyBeLoadedBy(aPrincipalInfo, cph->GetRemoteType(), {}).
The handler does invoke a check — CheckPrincipalRunnable — but this check only verifies internal consistency between the two attacker-supplied IPC arguments. It reconstructs a principal from aPrincipalInfo using PrincipalInfoToPrincipal, calls GetOrigin() on the result, and compares it to aOrigin. Since both arguments are attacker-controlled and passed as a self-consistent forged pair, this check provides no security: a compromised content process supplies aPrincipalInfo = victim's ContentPrincipalInfo and aOrigin = victim's origin string in lockstep, the reconstruction produces the victim's origin, the comparison succeeds, and no KillHard fires.
// BackgroundParentImpl.cpp:807-835 — CheckPrincipalRunnable::Run
auto principalOrErr = PrincipalInfoToPrincipal(mPrincipalInfo);
// ...
nsAutoCString origin;
nsresult rv = principalOrErr.unwrap()->GetOrigin(origin);
// ...
if (NS_WARN_IF(!mOrigin.Equals(origin))) {
// Only fires if the two *attacker-supplied* fields are inconsistent.
// A coordinated forge trivially passes.
contentParent->KillHard("BroadcastChannel killed: origins do not match.");
return NS_OK;
}
This is architecturally distinct from the other handlers in this class, which had no check at all. Here, Mozilla's engineers added a check but the check interrogates the wrong relationship — it verifies (forged principal → reconstructed origin) == (forged origin string), rather than verifying (actual calling process RemoteType) is permitted to host (forged principal origin).
The correct relationship to check is what ValidatePrincipalCouldPotentiallyBeLoadedBy enforces: the calling process's Fission RemoteType must be capable of hosting the claimed principal. A process with RemoteType=webIsolated=http://127.0.0.1 cannot legitimately host a principal for http://localhost:9200, and the function would reject it. That check is absent.
Downstream routing — why the actor grants cross-origin access
AllocPBroadcastChannelParent (ipc/glue/BackgroundParentImpl.cpp:769) constructs the actor's routing key from the two IPC arguments:
nsString originChannelKey;
// The format of originChannelKey is:
// <channelName>|<origin+OriginAttributes>
originChannelKey.Assign(aChannel);
originChannelKey.AppendLiteral("|");
originChannelKey.Append(NS_ConvertUTF8toUTF16(aOrigin));
return new BroadcastChannelParent(originChannelKey);
BroadcastChannelService::RegisterActor (BroadcastChannelService.cpp:58) inserts this actor into a hashtable keyed by originChannelKey. When any actor calls PostMessage, the service iterates every entry under that key and delivers the message to each:
// BroadcastChannelService.cpp:85-119
for (uint32_t i = 0; i < parents->Length(); ++i) {
BroadcastChannelParent* parent = parents->ElementAt(i);
if (parent == aParent) { continue; }
// OtherChildID() is used only for refcounting — not as a delivery filter.
(void)parent->SendNotify(aData);
}
There is no ContentParentId filter, no RemoteType filter, and no per-principal re-validation at delivery time. Every actor registered under "auth-sync|http://localhost:9200" — whether registered by a legitimate victim tab or by a forged attacker actor — receives every message posted to that channel.
A forged attacker actor registered under the victim's key therefore:
- Receives every message the victim's legitimate tabs broadcast — token refreshes, session state updates, coordination signals, logout triggers, anything transmitted over that channel name.
- Sends messages that every genuine victim tab receives as
MessageEventevents. The receiving page'sMessageEvent.originis set from the channel'smOriginForEvents, which is bound to the receiving principal at actor construction, not re-derived from the sender. Victim code that trustsevent.originto gate sensitive logic will treat injected messages as fully authoritative.
Proof of concept
Build and threat model: Firefox Nightly 152.0a1 at commit e374045fac6f19383a04d087d2930ced5c1551fe, built locally. The content-side patch (30-bc-child-forge.diff) modifies BroadcastChannel::Constructor in dom/broadcastchannel/BroadcastChannel.cpp at the production SendPBroadcastChannelConstructor call site (line 370 post-patch, inside BroadcastChannel::Constructor, not the automation-only UnpartitionedTestingChannel path). When MOZ_POC_BC_FORGE_TO is set, the patch substitutes a forged (PrincipalInfo, origin) pair for the victim target into the outgoing IPC. No new IPC capability is granted — only the argument values change. The parent-side patch (31-bc-parent-instrumentation.diff) adds read-only printf_stderr instrumentation at both the RecvPBroadcastChannelConstructor entry and inside CheckPrincipalRunnable::Run to capture the calling process's RemoteType and the result of the consistency check.
Phase 1 — baseline: Firefox launched without the env var. Victim tab at http://localhost:9200 creates BroadcastChannel('auth-sync') and broadcasts {type: 'session-refresh', token: 'VICTIM_SESSION_TOKEN_<timestamp>'} every two seconds. This establishes the victim's actor under the routing key auth-sync|http://localhost:9200 and confirms the baseline broadcast pattern via exfil to http://localhost:9300.
Phase 2 — attack: Firefox relaunched with MOZ_POC_BC_FORGE_TO=http://localhost:9200. Both the attacker tab (http://127.0.0.1:9100) and victim tab (http://localhost:9200) are opened simultaneously. The attacker tab's BroadcastChannel('auth-sync') constructor fires the forge immediately at t≈0, registering a forged actor under auth-sync|http://localhost:9200. The victim tab creates its legitimate actor under the same key at t≈1s. At t≈2s the attacker wires onmessage and sends a forged {type: 'force-logout'} injection.
Parent stderr — the IPC validator gap:
[POC-BC-CHILD] forged principal -> http://localhost:9200 (real origin was http://127.0.0.1:9100)
[POC-BC-PARENT] RecvPBroadcastChannelConstructor:
content_process_remote_type=webIsolated=http://127.0.0.1
received_principal_origin=http://localhost:9200
received_aOrigin=http://localhost:9200
channel=auth-sync
ValidatePrincipalCouldPotentiallyBeLoadedBy=NOT CALLED
[POC-BC-PARENT-CHECK] CheckPrincipalRunnable::Run:
reconstructed_origin=http://localhost:9200
mOrigin=http://localhost:9200
match=YES
CONSISTENCY_CHECK_PASSES_NO_REMOTETYPE_CHECK
A content process whose Fission RemoteType is webIsolated=http://127.0.0.1 claimed a principal for http://localhost:9200. The parent accepted it. The consistency check passed without consulting GetRemoteType(). The attacker actor is now live in the service routing table alongside the victim's legitimate actor.
Exfil log — bidirectional cross-origin compromise (representative subset):
// Injection: attacker sends, victim receives as trusted same-origin event
[2026-05-17T15:29:15Z] EXFIL stage=victim_received_injected
data={"type":"force-logout","injected_by":"attacker",
"attacker_origin":"http://127.0.0.1:9100"}
e_origin=http://localhost:9200
// Eavesdrop: victim sends, attacker receives
[2026-05-17T15:29:16Z] EXFIL stage=EAVESDROP
data={"type":"session-refresh",
"token":"VICTIM_SESSION_TOKEN_1779031756723_1",
"origin":"http://localhost:9200"}
e_origin=http://127.0.0.1:9100
[2026-05-17T15:29:18Z] EXFIL stage=EAVESDROP
data={"token":"VICTIM_SESSION_TOKEN_1779031758723_2"...}
[2026-05-17T15:29:20Z] EXFIL stage=EAVESDROP
data={"token":"VICTIM_SESSION_TOKEN_1779031760915_3"...}
// ... 12 total EAVESDROP events, one per victim broadcast cycle
The verdict printed by the PoC runner:
EAVESDROP_CONFIRMED (attacker received 12 victim broadcasts)
INJECTION_CONFIRMED (victim received 2 attacker broadcasts)
The e_origin=http://localhost:9200 field in the victim_received_injected entry is MessageEvent.origin as seen by the victim page's onmessage handler — the browser-reported origin of the message sender. It shows the victim's own origin, not the attacker's 127.0.0.1:9100. The victim has no API-level means to detect the forgery.
Bonus observation: a second forge line appears in the parent log:
[POC-BC-PARENT] RecvPBroadcastChannelConstructor:
content_process_remote_type=webIsolated=http://127.0.0.1^userContextId=5
received_principal_origin=http://localhost:9200
ValidatePrincipalCouldPotentiallyBeLoadedBy=NOT CALLED
The validator is absent even when the calling process carries a container identity (userContextId=5). The gap is structural across all content process variants.
Real-world impact
BroadcastChannel is used in production for:
- Session token distribution: password managers and SSO-aware apps broadcast refresh tokens and session identifiers between tabs to avoid redundant server round-trips. A compromised renderer intercepts these tokens silently and continuously.
- Logout-everywhere signals: web apps broadcast a logout event to all open tabs so each can clear local state and redirect. An attacker can inject a forged logout signal, or conversely, suppress a legitimate one by not forwarding it. The latter allows a tab to remain authenticated after the user intends to be logged out.
- PWA inter-tab state synchronization: offline-capable apps use BroadcastChannel to coordinate cache invalidation, UI state, and background sync triggers between service worker clients. Injected messages drive these state machines into attacker-chosen states.
- Leadership election: some tab-coordination patterns elect a "leader" tab via BroadcastChannel. An attacker actor can participate in the election and win it, taking control of whichever privileged tab role the leader holds.
Unlike storage-class attacks, the attacker requires no advance knowledge of what the victim transmits. The forged actor registers passively and receives whatever flows through the channel. Detection by the victim is not possible at the JavaScript layer.
Suggested fix
Add the same five-line guard used in Bug 2020535 at the entry of RecvPBroadcastChannelConstructor, before the CheckPrincipalRunnable dispatch:
mozilla::ipc::IPCResult BackgroundParentImpl::RecvPBroadcastChannelConstructor(
PBroadcastChannelParent* actor, const PrincipalInfo& aPrincipalInfo,
const nsACString& aOrigin, const nsAString& aChannel) {
AssertIsInMainProcess();
AssertIsOnBackgroundThread();
RefPtr<ThreadsafeContentParentHandle> parent =
BackgroundParent::GetContentParentHandle(this);
if (parent && !dom::ValidatePrincipalCouldPotentiallyBeLoadedBy(
aPrincipalInfo, parent->GetRemoteType(), {})) {
dom::ContentParent::LogAndAssertFailedPrincipalValidationInfo(
aPrincipalInfo, __func__);
return IPC_FAIL(this, "Principal validation failed");
}
// existing CheckPrincipalRunnable dispatch follows ...
The CheckPrincipalRunnable can remain as a defense-in-depth consistency check after this guard lands, but the RemoteType cross-check is the actual security boundary.
Evidence bundle
Attached as SUBMIT-BC.tar.gz. Contents:
Patches:
30-bc-child-forge.diff— content-side forge patch (dom/broadcastchannel/BroadcastChannel.cpp, productionSendPBroadcastChannelConstructorcall site only). Env-var-gated; no behavioral change in unmodified Firefox.31-bc-parent-instrumentation.diff— parent-sideprintf_stderrinstrumentation atRecvPBroadcastChannelConstructorentry andCheckPrincipalRunnable::Run. Read-only.
Smoking-gun logs:IPC-VALIDATOR-GAP.log— parent stderr:POC-BC-CHILD,POC-BC-PARENT,POC-BC-PARENT-CHECKlines showing the forge accepted and the consistency check bypassed.SMOKING-GUN-bc.log— exfil:EAVESDROPevents with victim session tokens,INJECTEDconfirmation,victim_received_injectedshowing forged message received by victim withe_origin=http://localhost:9200.
PoC source:poc-source/attacker/index.html— attacker pagepoc-source/victim/index.html— victim pagepoc-source/exfil_server.py— capture serverrun-bc-poc.sh— two-phase runner
Reproduction
1. Check out mozilla-firefox/firefox @ e374045fac6f19383a04d087d2930ced5c1551fe
2. Apply 30-bc-child-forge.diff and 31-bc-parent-instrumentation.diff
3. ./mach build binaries
4. python3 poc-source/exfil_server.py (port 9300)
5. python3 -m http.server 9200 (from poc-source/victim/)
6. python3 -m http.server 9100 (from poc-source/attacker/, bind 127.0.0.1)
7. MOZ_POC_BC_FORGE_TO=http://localhost:9200 \
./obj-x86_64-pc-linux-gnu/dist/bin/firefox \
--profile /tmp/bc-poc-profile \
http://127.0.0.1:9100/ http://localhost:9200/
8. Wait ~20s. Observe exfil server for EAVESDROP and victim_received_injected entries.
9. grep P2-attack.stderr for POC-BC-PARENT lines.
Updated•6 months ago
|
Updated•5 months ago
|
Updated•1 month ago
|
Description
•