Closed Bug 2023743 Opened 8 months ago Closed 8 months ago

RecvCreateWindowInDifferentProcess: missing principal validation allows sandbox escape via single IPC message

Categories

(Core :: DOM: Navigation, defect)

defect

Tracking

()

RESOLVED DUPLICATE of bug 1860869

People

(Reporter: simonkoeck04, Unassigned)

Details

(Keywords: reporter-external, Whiteboard: [client-bounty-form])

Attachments

(1 file)

ContentParent::RecvCreateWindowInDifferentProcess does not call ValidatePrincipal on the child-supplied aTriggeringPrincipal, and passes aLoadUri = true to CommonCreateWindow. A compromised content process can send SystemPrincipalInfo as the triggering principal along with a chrome:// URI, causing the parent process to load privileged chrome content with full system privileges. This is a complete sandbox escape.

A working end-to-end proof of concept is attached. It spawns /usr/bin/bash from inside the browser sandbox.

Component

Core :: IPC

Version

Trunk (verified on mozilla-central at af3c77e22f)

OS

All

Description

The CreateWindowInDifferentProcess message in PContent.ipdl is a child-to-parent async IPC message. The parent-side handler at dom/ipc/ContentParent.cpp:5575 accepts an nsIPrincipal* aTriggeringPrincipal and an nsIURI* aURIToLoad directly from the content process.

Unlike its sibling handler RecvCreateWindow (line 5462), which calls ValidatePrincipal(aTriggeringPrincipal), RecvCreateWindowInDifferentProcess performs no principal validation at all. It passes the attacker-controlled principal and URI directly to CommonCreateWindow with aLoadUri = true.

A compromised content process sends SystemPrincipalInfo as the triggering principal and a chrome:// URI (e.g., chrome://browser/content/browser.xhtml) as the URI to load. The parent process deserializes SystemPrincipalInfo into a real SystemPrincipal object and proceeds to load the chrome:// URI with it.

Three gaps align to permit the load

Gap 1: No ValidatePrincipal call. RecvCreateWindowInDifferentProcess (line 5575) does not call ValidatePrincipal. For contrast, the adjacent handler RecvCreateWindow (line 5462) does:

// RecvCreateWindow (line 5462), has validation:
if (!ValidatePrincipal(aTriggeringPrincipal)) {
    LogAndAssertFailedPrincipalValidationInfo(aTriggeringPrincipal, __func__);
}

// RecvCreateWindowInDifferentProcess (line 5575), no validation

ValidatePrincipal delegates to ValidatePrincipalCouldPotentiallyBeLoadedBy (ProcessIsolation.cpp:1209), which explicitly rejects SystemPrincipal unless AllowSystem is passed (line 1229-1230):

if (aPrincipal->IsSystemPrincipal()) {
    return aOptions.contains(ValidatePrincipalOptions::AllowSystem);
}

The attached GTest (CreateWindowValidationTest.cpp) confirms this check rejects SystemPrincipal from all content remote types.

Gap 2: aLoadUri = true vs false. RecvCreateWindow passes aLoadUri = false to CommonCreateWindow (line 5542), meaning no URI is loaded even if validation is bypassed. RecvCreateWindowInDifferentProcess passes aLoadUri = true (line 5629), which causes CommonCreateWindow to call browserDOMWin->OpenURIInFrame() (line 5341), actually navigating to the attacker-supplied URI.

Gap 3: Missing triggeringRemoteType propagation. The JavaScript layer in BrowserDOMWindow.sys.mjs (OpenURIInFrame, line 453) does not include triggeringRemoteType in the tab options passed to gBrowser.addTab(). This means nsDocShellLoadState.mTriggeringRemoteType defaults to an empty string. The security check CheckAllowLoadByTriggeringRemoteType (nsContentSecurityManager.cpp:1329) only blocks loads where triggeringRemoteType starts with "web", so an empty string passes (line 1360):

if (!StringBeginsWith(triggeringRemoteType, WEB_REMOTE_TYPE)) {
    return NS_OK;  // empty string passes this check
}

SystemPrincipal unconditionally passes CheckLoadURIWithPrincipal (nsScriptSecurityManager.cpp:709-712).

The only existing URI check is insufficient

RecvCreateWindowInDifferentProcess has one URI check (lines 5598-5619), but it:

  • Only checks for file:// scheme (not chrome://, resource://, or any other privileged scheme)
  • Is gated behind MOZ_DIAGNOSTIC_ASSERT_ENABLED (compiled out in release builds)
  • Is further gated behind a pref (browser.tabs.remote.enforceRemoteTypeRestrictions)

Proof of Concept

End-to-end PoC (spawns bash)

The PoC consists of three components:

  1. Content process patch (patches/01-e2e-poc-content-process.patch): Modifies ContentChild::ProvideWindowCommon to replace the normal CreateWindowInDifferentProcess code path with a hardcoded call that sends SystemPrincipalInfo + a chrome:// URI. This simulates what a compromised content process would do by calling the IPDL-generated method directly.

  2. Chrome payload (poc-escape.html): A chrome:// page registered in browser/base/jar.mn that verifies it has SystemPrincipal, then uses Subprocess.sys.mjs to spawn bash -c "id; echo SANDBOX_ESCAPED; hostname".

  3. Trigger page (poc_trigger.html): A web page that calls window.open("https://example.com", "_blank", "noopener") after 2 seconds. The noopener flag causes the content process to enter the CreateWindowInDifferentProcess code path, where our patch intercepts and sends the crafted message.

Steps to reproduce

# 1. Apply patches
#    - Modify dom/ipc/ContentChild.cpp per patches/01-e2e-poc-content-process.patch
#    - Copy poc-escape.html to browser/base/content/
#    - Add to browser/base/jar.mn:
#        content/browser/poc-escape.html  (content/poc-escape.html)

# 2. Build
./mach build

# 3. Disable popup blocker (write to profile's user.js)
PROFILE="obj-x86_64-pc-linux-gnu/tmp/profile-default"
cat > "$PROFILE/user.js" << 'EOF'
user_pref("dom.disable_open_during_load", false);
user_pref("dom.block_multiple_popups", false);
EOF

# 4. Run
MOZ_HEADLESS=1 ./mach run -- poc_trigger.html

Observed output

[PoC] SENDING CRAFTED IPC: SystemPrincipal + chrome:// URI
[PoC] document.nodePrincipal: [xpconnect wrapped (nsIPrincipal, nsISerializable)]
[PoC] isSystemPrincipal: true
[PoC] SUCCESS: Running with SystemPrincipal in parent process!
[PoC] Spawning /usr/bin/bash ...
[PoC] --- stdout ---
[PoC] uid=1000(simon) gid=100(users) groups=100(users),1(wheel),57(networkmanager),983(me...

[PoC] --- end ---
[PoC] Exit code: 0

GTest (proves the validation gap)

The attached CreateWindowValidationTest.cpp (see also patches/02-gtest-validation-gap.patch) adds three tests to dom/ipc/gtest/:

  • SystemPrincipalRejectedByValidation: Proves ValidatePrincipalCouldPotentiallyBeLoadedBy rejects SystemPrincipal from all content remote types (web, fission, file, extension) unless AllowSystem is explicitly passed.
  • ContentPrincipalAcceptedByValidation: Proves normal content principals pass validation.
  • ChromeURIConstructible: Confirms chrome:// URIs can be constructed for the attack.
./mach build dom/ipc/gtest
./mach gtest "CreateWindowValidation*"

All 3 tests pass, confirming the validation mechanism exists and would reject SystemPrincipal, but RecvCreateWindowInDifferentProcess never invokes it.

Expected Results

The parent process should validate the triggeringPrincipal and reject privileged URI schemes from content processes. Recommended fixes (in order of priority):

  1. Add ValidatePrincipal with blocking enforcement: Add ValidatePrincipal(aTriggeringPrincipal) to RecvCreateWindowInDifferentProcess and return IPC_FAIL (not just log) on failure:
if (!ValidatePrincipal(aTriggeringPrincipal)) {
    return IPC_FAIL(this, "Invalid triggeringPrincipal in "
                          "RecvCreateWindowInDifferentProcess");
}
  1. Reject privileged URI schemes: Add an explicit check blocking chrome://, resource://, and about: (non-web-accessible) URIs in RecvCreateWindowInDifferentProcess or CommonCreateWindow when the caller is a content process.

  2. Propagate triggeringRemoteType: Pass triggeringRemoteType through the BrowserDOMWindow.sys.mjs JavaScript layer into gBrowser.addTab() so that CheckAllowLoadByTriggeringRemoteType can identify content-process-originated loads.

  3. Consider aLoadUri = false: Evaluate whether RecvCreateWindowInDifferentProcess actually needs to load the URI, or whether it can follow RecvCreateWindow's pattern of passing aLoadUri = false.

Note: the existing ValidatePrincipal call in RecvCreateWindow is non-blocking in release builds (it logs and continues). This is a separate defense-in-depth concern. Even if RecvCreateWindowInDifferentProcess added the same non-blocking check, the load would still proceed. Fix #1 above recommends making it blocking (IPC_FAIL).

Impact

A compromised content process can load arbitrary chrome:// URIs in the parent process with full SystemPrincipal privileges. Chrome documents have unrestricted access to:

  • All XPCOM services and privileged APIs
  • The filesystem (via nsIFile / IOUtils)
  • Process execution (via nsIProcess / Subprocess.sys.mjs)
  • All browser data (passwords, cookies, history, bookmarks)
  • The ability to install extensions, modify preferences, and make arbitrary network requests without content security restrictions

This is a complete sandbox escape from a compromised content process to full user-level code execution. A single IPC message is sufficient. The PoC demonstrates spawning an arbitrary process (bash) with the user's full privileges.

Prerequisite

This vulnerability requires code execution in the content process (e.g., via a separate memory corruption vulnerability). This is the standard threat model for browser sandbox escapes: the sandbox exists to contain exactly these compromises. The normal JavaScript code path cannot reach this handler with SystemPrincipal because:

  • triggeringPrincipal is derived from doc->NodePrincipal() (ContentChild.cpp:936), which is always a content principal for web pages
  • With Fission enabled (default), the CreateWindowInDifferentProcess code path is blocked entirely (ContentChild.cpp:1003)

However, a compromised content process can call SendCreateWindowInDifferentProcess directly, bypassing both restrictions. The parent-side handler must validate independently of what the content-side code "should" send.

Relevant Code

  • Vulnerable handler (no validation): dom/ipc/ContentParent.cpp:5575-5639
  • Sibling handler (has validation + aLoadUri=false): dom/ipc/ContentParent.cpp:5447-5572
  • CommonCreateWindow (passes principal through): dom/ipc/ContentParent.cpp:5198-5373
  • ValidatePrincipal: dom/ipc/ContentParent.cpp:1342-1347
  • ValidatePrincipalCouldPotentiallyBeLoadedBy (rejects SystemPrincipal): dom/ipc/ProcessIsolation.cpp:1209-1231
  • IPDL message definition: dom/ipc/PContent.ipdl:1564-1579
  • Content-side call site: dom/ipc/ContentChild.cpp:1052
  • GetCreateWindowParams (principal source): dom/ipc/ContentChild.cpp:896-954
  • OpenURIInFrame (JS, no triggeringRemoteType): browser/modules/BrowserDOMWindow.sys.mjs:453-518
  • triggeringRemoteType check (bypassed): dom/security/nsContentSecurityManager.cpp:1329-1360
  • SystemPrincipal bypass: caps/nsScriptSecurityManager.cpp:709-712
  • Process isolation (chrome:// -> parent): dom/ipc/ProcessIsolation.cpp:261

Note on the PoC's use of a custom chrome:// page

The PoC registers a custom chrome://browser/content/poc-escape.html for
demonstration clarity. A real attacker with content process RCE would not need to
register any files. Firefox ships with existing chrome:// pages (e.g.,
browser.xhtml) that load in the parent process with SystemPrincipal and execute
JavaScript.

Attachments

File Description
poc-escape.html Chrome payload: verifies SystemPrincipal, spawns bash
poc_trigger.html Web page that triggers window.open with noopener
CreateWindowValidationTest.cpp GTest proving the validation gap
patches/01-e2e-poc-content-process.patch Content process patch for end-to-end PoC
patches/02-gtest-validation-gap.patch GTest patch (new file + moz.build)
Flags: sec-bounty?
Group: firefox-core-security → dom-core-security
Component: Security → DOM: Navigation
Product: Firefox → Core

Demonstrating that you can get a chrome:// URL loaded in the parent process is not sufficient to demonstrate a sandbox escape. The browser loads chrome:// files in the parent process all of the time. You need to demonstrate that the compromised content process can actually do something bad.

It looks like I did file a bug about this particular message a few years ago, bug 1860869. I'm not sure how much that overlaps with this or not. There's also an older bug about removing this message entirely, bug 1800120.

Depends on: 1800120
See Also: → 1860869

Your POC set-up includes the pref dom.block_multiple_popups which hasn't existed since 2024 (removed in bug 1933321).

Your "sandbox escape" requires installing a compromised chrome:// file which goes beyond the allowed assumption of a compromised content process. To be valid you would have to have shown launching bash using a resource that is currently shipped with Firefox, or demonstrate how you could register/install that chrome file from a compromised content process. Installing the chrome:// resource already requires a sandbox escape, so it can't be used as the basis for a different "sandbox escape" demonstration.

Status: UNCONFIRMED → RESOLVED
Closed: 8 months ago
Resolution: --- → INVALID

The sandbox escape part is invalid, but the missing validation is still true (but known). It's not a powerful primitive

Duplicate of bug: 1860869
Flags: sec-bounty? → sec-bounty-
Resolution: INVALID → DUPLICATE
See Also: 1860869 →
No longer depends on: 1800120
Group: dom-core-security
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: