Closed Bug 2025530 Opened 7 months ago Closed 3 months ago

Sandbox escape: [@ PopupAndRedirectBlockingParent::unblockRedirect] uses forged SystemPrincipal as triggeringPrincipal

Categories

(Toolkit :: Popup Blocker, defect)

Desktop
All
defect

Tracking

()

RESOLVED DUPLICATE of bug 2027207
152 Branch
Tracking Status
firefox-esr115 --- wontfix
firefox-esr140 153+ fixed
firefox152 --- fixed

People

(Reporter: bugmon, Assigned: nika)

References

(Blocks 1 open bug)

Details

(5 keywords, Whiteboard: [prefs-checked])

Attachments

(6 files)

VULNERABILITY: Unvalidated triggeringPrincipal in PopupAndRedirectBlockingParent.unblockRedirect()

Root Cause (PopupAndRedirectBlockingParent.sys.mjs:173-183)

unblockRedirect(aBrowsingContext, aInnerWindowId, aRedirectURISpec) {
    const sourceWG = aBrowsingContext.currentWindowGlobal;
    if (!sourceWG || sourceWG.innerWindowId != aInnerWindowId) {
      return;
    }
    const uri = Services.io.newURI(aRedirectURISpec);
    aBrowsingContext.top.loadURI(uri, {
      triggeringPrincipal: sourceWG.documentPrincipal,  // ← UNVALIDATED
    });
}

The JS actor reads sourceWG.documentPrincipal from a WindowGlobalParent and uses it directly as the triggeringPrincipal for CanonicalBrowsingContext.loadURI(). It assumes this principal is trustworthy because it came from the parent-side WindowGlobal state. This assumption is false.

Enabling Weakness: Non-Fatal Principal Validation

WindowGlobalParent.mDocumentPrincipal is set from child-supplied data at WindowGlobalParent.cpp:129:

wgp->mDocumentPrincipal = aInit.principal();

The parent validates this at BrowserParent.cpp:1401:

if (!Manager()->ValidatePrincipal(aInit.principal(), validationOptions)) {
    ContentParent::LogAndAssertFailedPrincipalValidationInfo(aInit.principal(), __func__);
}
// Execution CONTINUES - WGP created with whatever child sent

LogAndAssertFailedPrincipalValidationInfo (ContentParent.cpp:1333-1337):

#ifdef DEBUG
  MOZ_ASSERT(false, "Receiving unexpected Principal");
#endif

In release builds (and this ASAN fuzzing build — confirmed MOZ_DEBUG not defined), validation failure is logging + telemetry only. A compromised content process can send SystemPrincipal in WindowGlobalInit.principal() — validation fails, is logged, but the WindowGlobalParent is created anyway with SystemPrincipal stored as mDocumentPrincipal.

The content process also needs to handle OnNewDocument (WindowGlobalChild.cpp:222) which sends UpdateDocumentPrincipal — RecvUpdateDocumentPrincipal (WindowGlobalParent.cpp:467) does IPC_FAIL on mismatch, so the forge must be consistent across both messages (handled by keying on stable BrowsingContext name).

Attacker Control of redirectURISpec

aRedirectURISpec is fully attacker-controlled. Flow: unblockFirstRedirect() → getBlockedRedirect() (line 154) → actor.sendQuery("GetBlockedRedirect") → child process responds. The child's response is structured-cloned into the parent, and redirect.redirectURISpec is extracted (line 159) with no validation.

Combined Impact: SystemPrincipal-Triggered Load of Attacker URI

With SystemPrincipal as triggeringPrincipal:

  1. CheckLoadURIWithPrincipal passes for any URI — System can load chrome://, privileged about:, file://, etc.
  2. nsDocShellLoadState constructor (nsDocShellLoadState.cpp:269): since called from parent process, mTriggeringRemoteType = NOT_REMOTE_TYPE. This bypasses AssertProcessCouldTriggerLoadIfSystem (line 1081) which only fires for web remote types.
  3. ProcessIsolation.cpp:277: chrome:// returns IsolationBehavior::Parent in the FIRST pass. The SystemPrincipal→ForceWebRemoteType guard at line 754 is never reached because behavior is already Parent, not WebContent.
  4. DocumentLoadListener.cpp:2479: Final validation explicitly passes ValidatePrincipalOptions::AllowSystem — SystemPrincipal accepted.
  5. Process switch to parent. Attacker-chosen chrome:// page loads in parent process with SystemPrincipal.

Demonstrated Primitive

The PoC demonstrates (with crashed_parent: true and ChromeUtils::ReleaseAssert in the stack):

  • Content process forges SystemPrincipal (stderr: [EXPLOIT] C++: Forging SystemPrincipal at WindowGlobalChild::Create/OnNewDocument)
  • JS actor calls loadURI(attackerURI, {triggeringPrincipal: SystemPrincipal})
  • Attacker's redirectURISpec (chrome://global/content/pwn-testvector.html#<payload>) loaded in PARENT process
  • The attacker-controlled URL fragment is visible in the parent-process crash message, proving end-to-end data flow

Shipping Code-Execution Sinks (Real-World Chain)

The PoC uses a test-vector chrome page. A real attacker would target shipping sinks:

about:devtools-toolbox?type=process (AboutDevToolsToolboxRegistration.sys.mjs, no URI_SAFE_FOR_UNTRUSTED_CONTENT, no URI_MUST_LOAD_IN_CHILD → PARENT + SYSTEM):

  • commands-from-url.js:173-175: DevToolsServer.init() + connectPipe() — NO pref checks (bypasses devtools.chrome.enabled AND devtools.debugger.remote-enabled, both false on release)
  • commands-from-url.js:124: DevToolsServer.allowChromeProcess = true — persistent global flag
  • commands-from-url.js:127: CommandsFactory.forMainProcess({client}) — target = browser.xhtml (confirmed by browser_commands_from_url.js:65-68)
  • toolbox.js:966,2428: On open, _listenAndApplyConfigurationPref() → getThreadOptions() → reads asyncStore.pendingBreakpoints from IndexedDB (indexeddb://fx-devtools) → updateConfiguration(threadConfiguration) sends to ThreadActor
  • thread-utils.js:62-91: sanitizeBreakpoints() validates ONLY location/generatedLocation — does NOT strip options.condition or options.logValue
  • breakpoint.js:136: When breakpoint hits, frame.eval(condition, {hideFromDebugger: true}) — attacker-controlled code executes in browser.xhtml's debuggee frame

The indexeddb://fx-devtools IDB is shared across all DevTools instances and uses openForPrincipal (ChromeOnly) — content-process chrome JS (the compromised child actor) can write to it. Attacker plants a breakpoint with generatedLocation.sourceUrl = any frequently-executed parent module (e.g., resource://gre/modules/Timer.sys.mjs) and options.condition = payload. Loading about:devtools-toolbox?type=process applies it; next module execution → frame.eval(payload) in parent.

about:memory?file=<path> (nsAboutRedirector.cpp:148, PARENT + SYSTEM): Arbitrary file read via File.createFromFileName() / NetUtil.newChannel({loadUsingSystemPrincipal: true}). On Windows, ?file=\\attacker.com\share\x.gz triggers SMB with user's NTLM credentials (hash leak / relay).

User Interaction Requirement

The vulnerable unblockRedirect() is reached via unblockFirstRedirect(), called from:

  • PopupAndRedirectBlockerObserver.toggleAllowPopupsForSite() — user clicks "Allow pop-ups for [site]" in the standard popup blocker notification menupopup
  • browser-sitePermissionPanel.js:_createBlockedRedirectText() — user clicks the text-link in the permission panel

This is a 1-click sandbox escape. The notification shown is the standard "Firefox prevented this site from redirecting" banner — a high-credibility UI element that users routinely interact with. The PoC includes a test harness setTimeout(() => unblockFirstRedirect()) to simulate this click for automated reproduction (equivalent to BrowserTestUtils.synthesizeMouseAtCenter in a mochitest).

Actor Registration Permits Broad Attack Surface

ActorManagerParent.sys.mjs:488-505: allFrames: true, no matches, no remoteTypes, no messageManagerGroups. The actor can be instantiated from any frame in any content process. Combined with the popup blocker's standard behavior (any window.open() without user gesture creates the actor), there is no constraint on which sites can drive this vulnerability.

Fix

unblockRedirect() must not trust sourceWG.documentPrincipal as a load-capability grant. Options:

  1. Use a null principal or explicitly construct a content principal from sourceWG.documentURI instead of reading the stored principal
  2. Validate sourceWG.documentPrincipal.isSystemPrincipal === false and !nsContentUtils.IsExpandedPrincipal(...) before using it
  3. Derive the triggering principal from aBrowsingContext.top.currentWindowGlobal.documentPrincipal (the load target) rather than the source frame — this is what the user expects semantically (the redirect was blocked for the tab, not the iframe)

Additionally, BrowserParent::RecvNewWindowGlobal should hard-fail (kill content process) on ValidatePrincipal() failure rather than just logging, making this entire class of attack impossible.

Attached file Crash stack trace —
Attached patch Patch — — Splinter Review
Attached file Testcase: index.html —
Group: core-security → firefox-core-security

unblockRedirect() could also check if the URL is something webby using loadflags, no?

Prefs check: dom.disable_open_during_load=true and privacy.popups.showBrowserMessage=true are both the shipping Firefox Desktop default (browser/app/profile/firefox.js:1202,1209); browser.dom.window.dump.enabled is diagnostic-only for the [EXPLOIT] trace output. Reproduces in default config.

Whiteboard: [prefs-checked]

This doesn't seem great but I'm not sure how bad this actually is.

Product: Firefox → Toolkit
Component: General → Popup Blocker
Flags: needinfo?(gijskruitbosch+bugs)
OS: Unspecified → All
Hardware: Unspecified → Desktop

Verified by reproduction: applied the exploit patch, confirmed crashed_parent: true with ChromeUtils::ReleaseAssert from the chrome:// test vector, added this fix on top, re-ran — no crash (C++ principal forge still active per stderr, load rejected at the JS check).

The fix:

  • !principal?.isContentPrincipal → return. Blocked framebusting navigations only originate from web content (see BrowsingContext::CheckFramebusting — it bails for parent-process loads and for system-principal sources). Using an allowlist (isContentPrincipal) rather than a denylist (!isSystemPrincipal && !isExpandedPrincipal) so any future principal type is rejected by default.
  • triggeringRemoteType: sourceWG.domProcess?.remoteType. Defense-in-depth: makes nsDocShellLoadState treat the load as content-triggered instead of defaulting to NOT_REMOTE_TYPE, activating AssertProcessCouldTriggerLoadIfSystem in diagnostic builds. Same pattern as ClickHandlerParent.sys.mjs.

Re: comment 7 (scheme loadflags) — with a content triggering principal, CheckLoadURIWithPrincipal inside loadURI already blocks chrome://, privileged about:, and file://. An explicit scheme filter could be added as additional belt-and-braces but the principal check closes the escape.

Not fixing BrowserParent::RecvNewWindowGlobal (the underlying non-fatal validation) here — that's a broader change that likely affects other consumers of documentPrincipal and deserves its own bug.

This is the analysis tool's suggested fix. Feel welcome to adopt it as a starting point and evolve it as needed to meet our coding standards.

The window global's parent side principal being inaccurate / forgeable feels like something we should fix in the implementation of WindowGlobalParent, not in the consuming actors. We have made other actor fixes that rely on the parent process side information not being child-process-forgeable. The actor should maybe be using this.manager to access the window global but by the sounds of it that wouldn't be enough on its own anyway.

Nika, can you help take a look and suggest a more in-depth fix?

Flags: needinfo?(gijskruitbosch+bugs) → needinfo?(nika)

(In reply to :Gijs (he/him) from comment #12)

The window global's parent side principal being inaccurate / forgeable feels like something we should fix in the implementation of WindowGlobalParent, not in the consuming actors. We have made other actor fixes that rely on the parent process side information not being child-process-forgeable. The actor should maybe be using this.manager to access the window global but by the sounds of it that wouldn't be enough on its own anyway.

Nika, can you help take a look and suggest a more in-depth fix?

Yes, I agree that we should fix the issue of a forgeable principal in WindowGlobalParent first. I have some wip changes I'm planning to post in bug 2027207 soon to turn the checks into fatal checks, and I also am hoping to do some work in another bug soon to be able to validate the principals even more thoroughly, though I haven't been able to find the time to post them yet.

Depends on: 2027207
Flags: needinfo?(nika)

bug 2027207 was fixed, can bugmon check if this same vulnerability would still work? I believe the answer might be "no" given comment 13, but I haven't investigated in detail.

Flags: needinfo?(choller)
Flags: needinfo?(choller) → needinfo?(mdauer)

This is no longer reproducible after the fixes in Bug 2027207. We may look into additional hardening by checking that the triggering principal is either content or null, but the root cause is fixed IMO.

Status: UNCONFIRMED → RESOLVED
Closed: 3 months ago
Flags: needinfo?(mdauer)
Resolution: --- → FIXED
Assignee: nobody → nika
Group: mozilla-employee-confidential
Target Milestone: --- → 152 Branch
Group: mozilla-employee-confidential, firefox-core-security → core-security-release
No longer depends on: 2027207
Duplicate of bug: 2027207
Resolution: FIXED → DUPLICATE
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: