Closed Bug 2043109 Opened 5 months ago Closed 5 months ago

Unchecked DocShellLoadState fields allow SystemPrincipal load

Categories

(Core :: DOM: Navigation, defect)

defect

Tracking

()

RESOLVED DUPLICATE of bug 2040160

People

(Reporter: andrew, Unassigned)

Details

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

Attachments

(6 files, 3 obsolete files)

Attached file BUILD.md (obsolete) —

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 ResultPrincipalURI forging 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:
  1. git apply bug-pendingload-replay.patch against a FIREFOX_151_0_RELEASE checkout.
  2. Build debug with --disable-optimize --enable-tests (see BUILD.md).
  3. cd poc-trigger && ./run-parent.sh.
  4. 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 to target.html. Trace output goes to run-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

  1. ValidateWithOriginalState binds only: URI, UnstrippedURI, OriginalURI, BaseURI, TriggeringPrincipal, TriggeringSandboxFlags, TriggeringRemoteType, OriginalURIString, RemoteTypeOverride, source BrowsingContext id.
  2. SecurityFlagsForLoadInfo (netwerk/ipc/DocumentLoadListener.cpp:115) reads the forged PrincipalToInherit and IS_SRCDOC bit, calls nsContentUtils::ChannelShouldInheritPrincipal with aForceInherit=true, and ORs SEC_FORCE_INHERIT_PRINCIPAL into the LoadInfo.
  3. nsDocShell::CreateAndConfigureRealChannelForLoadState (nsDocShell.cpp:9067) writes the forged PrincipalToInherit onto the LoadInfo; at line 9034 the srcdoc fork calls NS_NewInputStreamChannelInternal, returning attacker bytes for the parent-validated URI.
  4. nsScriptSecurityManager::GetChannelResultPrincipal (caps/nsScriptSecurityManager.cpp:354) sees SEC_FORCE_INHERIT_PRINCIPAL and returns LoadInfo::FindPrincipalToInherit — the forged SystemPrincipal.
  5. Document::Reset commits NodePrincipal = SystemPrincipal for the parent-validated load URI (with the supplied patch, the committed documentURI is the forged blob ResultPrincipalURI, even though ValidateWithOriginalState accepted 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.

Flags: sec-bounty?
Attached file source-parent.html —
Attached file target.html —
Attached file run-parent.sh (obsolete) —
Attached file user.js (obsolete) —
Attached file BUILD.md —
Attachment #9590826 - Attachment is obsolete: true
Attached file run-parent.sh —
Attachment #9590830 - Attachment is obsolete: true
Attached file user.js —
Attachment #9590831 - Attachment is obsolete: true
Group: firefox-core-security → dom-core-security
Component: Security → DOM: Navigation
Product: Firefox → Core

nika, how does this sound to you?

Flags: needinfo?(nika)

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?

Flags: needinfo?(nika) → needinfo?(vhilla)

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.

Flags: needinfo?(vhilla)
Status: UNCONFIRMED → RESOLVED
Closed: 5 months ago
Duplicate of bug: CVE-2026-12295
Resolution: --- → DUPLICATE

(In reply to Vincent Hilla [:vhilla] from comment #11)

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.

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.

Flags: sec-bounty? → sec-bounty-
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: