Unchecked DocShellLoadState fields allow SystemPrincipal load
Categories
(Core :: DOM: Navigation, defect)
Tracking
()
People
(Reporter: andrew, Unassigned)
Details
(Keywords: reporter-external, Whiteboard: [client-bounty-form])
Attachments
(6 files, 3 obsolete files)
Summary
nsDocShellLoadState::ValidateWithOriginalState (docshell/base/nsDocShellLoadState.cpp:1348) only binds 10 of ~30 fields in the DocShellLoadStateInit returned by a content process. A compromised content process can mutate the unchecked fields (PrincipalToInherit, INTERNAL_LOAD_FLAGS_IS_SRCDOC, SrcdocData, ChannelInitialized, and ResultPrincipalURI. ResultPrincipalURI is not required for the 151 primitive, but the supplied cross-version patch forges it unconditionally because it is required on Nightly 153.) between nsDocShellLoadState construction and SendPDocumentChannelConstructor. The parent accepts the forged loadstate and commits attacker-controlled srcdoc with NodePrincipal = SystemPrincipal for a parent-validated HTTP load URI; with the supplied cross-version patch, documentURI follows the forged blob ResultPrincipalURI. ChromeUtils.importESModule succeeds inside that document. The patch simulates the stated compromised-content-process primitive; this is not web-content-only exploitable.
Product / Component
Core :: DOM: Navigation (alternatively Core :: Security: Process Sandboxing).
Version
- Firefox 151.0 (FIREFOX_151_0_RELEASE, 79eeaf756b8c, BuildID 20260525145636) — reproduces with the supplied 5-field cross-version patch. A 151-only 4-field variant also works if
ResultPrincipalURIforging is removed. - Nightly 153.0a1 (BuildID 20260526002706) — reproduces with the same 5-field patch; the forged
ResultPrincipalURI = blob:...bypasses the allow-list added in commit 800b6c20e481 (Bug 2027207).
OS
All. Confirmed on macOS 26 (arm64). Affected code is platform-independent.
Steps to Reproduce
Reproduction bundle attached (firefox-151-bug-pendingload-replay.tar), containing:
bug-pendingload-replay.patch— applies cleanly to FIREFOX_151_0_RELEASE.BUILD.md— build/run procedure.source-parent.html,target.html— static pages served by the runner.profile/user.js,run-parent.sh— profile and harness.
Steps:
git apply bug-pendingload-replay.patchagainst a FIREFOX_151_0_RELEASE checkout.- Build debug with
--disable-optimize --enable-tests(see BUILD.md). cd poc-trigger && ./run-parent.sh.- The runner serves the directory on 127.0.0.1:8765, launches the built Firefox via Marionette, opens
source-parent.html, arms the harness, and navigates the tab totarget.html. Trace output goes torun-parent-demo.log.
Actual Results
Key lines from run-parent-demo.log (PIDs/nonces vary):
[child] forging mLoadState: uri=http://127.0.0.1:8765/target.html?n=...
[child] mutation complete, PrincipalToInherit.IsSystem=1 IS_SRCDOC=1 srcdocLen=522 ChannelInitialized=0
[child] forged ResultPrincipalURI=blob:https://example.invalid/bplr-fake-uuid
[parent] ValidateWithOriginalState PASSED URI=http://127.0.0.1:8765/target.html?n=... PrincipalToInherit.IsSystem=1 IS_SRCDOC=1
[parent] SecurityFlagsForLoadInfo: SEC_FORCE_INHERIT_PRINCIPAL=1
[child] Document::SetPrincipals IsSystem=1 origin=[System Principal] docURI=blob:https://example.invalid/bplr-fake-uuid
console.log: "BPLR-RUNTIME-PARENT: ChromeUtils.importESModule SUCCEEDED"
The ValidateWithOriginalState PASSED line is the validator accepting the forged loadstate. Everything after follows mechanically.
On debug builds the parent later aborts via MOZ_ASSERT(false, "Receiving unexpected Principal") in ContentParent::LogAndAssertFailedPrincipalValidationInfo. That assert is #ifdef DEBUG; the release branch logs and falls through, constructing WindowGlobalParent with the system principal anyway. The ChromeUtils.importESModule success is logged before any debug tripwire fires.
Expected Results
ValidateWithOriginalState should reject changes to PrincipalToInherit, the srcdoc bit (INTERNAL_LOAD_FLAGS_IS_SRCDOC), SrcdocData, ResultPrincipalURI/KeepResultPrincipalURIIfSet, and any ChannelInitialized transition (a steering field that causes the parent to consume child-replayed state differently) — returning a mismatch string and triggering aActor->FatalError — or the downstream nsDocShell code should not trust any of these child-supplied fields.
Root Cause
ValidateWithOriginalStatebinds only: URI, UnstrippedURI, OriginalURI, BaseURI, TriggeringPrincipal, TriggeringSandboxFlags, TriggeringRemoteType, OriginalURIString, RemoteTypeOverride, source BrowsingContext id.SecurityFlagsForLoadInfo(netwerk/ipc/DocumentLoadListener.cpp:115) reads the forgedPrincipalToInheritandIS_SRCDOCbit, callsnsContentUtils::ChannelShouldInheritPrincipalwithaForceInherit=true, and ORsSEC_FORCE_INHERIT_PRINCIPALinto the LoadInfo.nsDocShell::CreateAndConfigureRealChannelForLoadState(nsDocShell.cpp:9067) writes the forgedPrincipalToInheritonto the LoadInfo; at line 9034 the srcdoc fork callsNS_NewInputStreamChannelInternal, returning attacker bytes for the parent-validated URI.nsScriptSecurityManager::GetChannelResultPrincipal(caps/nsScriptSecurityManager.cpp:354) seesSEC_FORCE_INHERIT_PRINCIPALand returnsLoadInfo::FindPrincipalToInherit— the forged SystemPrincipal.Document::ResetcommitsNodePrincipal = SystemPrincipalfor the parent-validated load URI (with the supplied patch, the committeddocumentURIis the forged blobResultPrincipalURI, even thoughValidateWithOriginalStateaccepted the HTTP load URI).
Nightly 153.0a1 Note
Commit 800b6c20e481 (Bug 2027207) tightens TriggerRedirectToRealChannel so ContentParent::ValidatePrincipal is only called with AllowSystem when the channel's final URI scheme is blob:, chrome:, or automation-only about:blank. The allow-list reads NS_GetFinalChannelURI (nsNetUtil.cpp:2367), which prefers LoadInfo::ResultPrincipalURI. ResultPrincipalURI is not in the validator's binding set, so forging it to a blob: string satisfies the allow-list and the same SystemPrincipal/srcdoc capability chain completes on 153 (documentURI presentation differs depending on ResultPrincipalURI). This is a defense-in-depth tightening, not a root-cause fix.
Fix direction: extend ValidateWithOriginalState to also bind PrincipalToInherit, PartitionedPrincipalToInherit, the INTERNAL_LOAD_FLAGS_IS_SRCDOC bit, SrcdocData, ResultPrincipalURI, KeepResultPrincipalURIIfSet, and ChannelInitialized (the steering field that causes the parent to consume child-replayed state differently), or recompute these parent-side from authoritative state.
Updated•5 months ago
|
Comment 10•5 months ago
|
||
I believe :vhilla already has patches up to fix this bug in another bug, but redirecting to confirm that this isn't also covering other fields which vhilla's patches missed?
Comment 11•5 months ago
|
||
It's reproducible and would be fixed by bug 2040160.
We hijack a parent-initiated navigation to modify srcdoc data and some principals. Because it's parent initiated, the remote type is empty and bug 2034682 won't help.
Unlike bug 2040160, this bug goes through ValidateWithOriginalState. That method does validate the URI, but this bug gets around that by setting ResultPrincipalURI. As comment 0 says, this means we get ValidatePrincipalOptions::AllowSystem in TriggerRedirectToRealChannel.
ValidateWithOriginalState already has a fixme comment to do more checks. Do we have a bug for that? My patches aren't covering that method, but I also don't see a direct need for that given this bug would still be fixed.
Updated•5 months ago
|
Updated•5 months ago
|
Updated•5 months ago
|
Comment 13•5 months ago
|
||
(In reply to Vincent Hilla [:vhilla] from comment #11)
ValidateWithOriginalStatealready has a fixme comment to do more checks. Do we have a bug for that? My patches aren't covering that method, but I also don't see a direct need for that given this bug would still be fixed.
I didn't identify a specific other bug that covers it, but it's in the scope of the existing bug 1670242. bug 2012284 also took advantage of ResultPrincipalURI in a different IPC API.
Updated•1 month ago
|
Description
•