RecvCreateWindowInDifferentProcess: missing principal validation allows sandbox escape via single IPC message
Categories
(Core :: DOM: Navigation, defect)
Tracking
()
People
(Reporter: simonkoeck04, Unassigned)
Details
(Keywords: reporter-external, Whiteboard: [client-bounty-form])
Attachments
(1 file)
|
6.29 KB,
application/zip
|
Details |
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 (notchrome://,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:
-
Content process patch (
patches/01-e2e-poc-content-process.patch): ModifiesContentChild::ProvideWindowCommonto replace the normalCreateWindowInDifferentProcesscode path with a hardcoded call that sendsSystemPrincipalInfo+ achrome://URI. This simulates what a compromised content process would do by calling the IPDL-generated method directly. -
Chrome payload (
poc-escape.html): A chrome:// page registered inbrowser/base/jar.mnthat verifies it hasSystemPrincipal, then usesSubprocess.sys.mjsto spawnbash -c "id; echo SANDBOX_ESCAPED; hostname". -
Trigger page (
poc_trigger.html): A web page that callswindow.open("https://example.com", "_blank", "noopener")after 2 seconds. Thenoopenerflag causes the content process to enter theCreateWindowInDifferentProcesscode 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
ValidatePrincipalCouldPotentiallyBeLoadedByrejectsSystemPrincipalfrom all content remote types (web, fission, file, extension) unlessAllowSystemis 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):
- Add
ValidatePrincipalwith blocking enforcement: AddValidatePrincipal(aTriggeringPrincipal)toRecvCreateWindowInDifferentProcessand returnIPC_FAIL(not just log) on failure:
if (!ValidatePrincipal(aTriggeringPrincipal)) {
return IPC_FAIL(this, "Invalid triggeringPrincipal in "
"RecvCreateWindowInDifferentProcess");
}
-
Reject privileged URI schemes: Add an explicit check blocking
chrome://,resource://, andabout:(non-web-accessible) URIs inRecvCreateWindowInDifferentProcessorCommonCreateWindowwhen the caller is a content process. -
Propagate
triggeringRemoteType: PasstriggeringRemoteTypethrough theBrowserDOMWindow.sys.mjsJavaScript layer intogBrowser.addTab()so thatCheckAllowLoadByTriggeringRemoteTypecan identify content-process-originated loads. -
Consider
aLoadUri = false: Evaluate whetherRecvCreateWindowInDifferentProcessactually needs to load the URI, or whether it can followRecvCreateWindow's pattern of passingaLoadUri = 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:
triggeringPrincipalis derived fromdoc->NodePrincipal()(ContentChild.cpp:936), which is always a content principal for web pages- With Fission enabled (default), the
CreateWindowInDifferentProcesscode 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) |
Updated•8 months ago
|
Comment 1•8 months ago
|
||
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.
Comment 2•8 months ago
|
||
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.
Comment 3•8 months ago
|
||
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.
Comment 4•8 months ago
|
||
The sandbox escape part is invalid, but the missing validation is still true (but known). It's not a powerful primitive
Updated•2 months ago
|
Description
•