Closed Bug 2046997 Opened 5 months ago Closed 5 months ago

UXSS via PDocumentChannel IPC — ValidateWithOriginalState does not check PrincipalToInherit or SrcdocData (sibling of Bug 2046558, different entry point)

Categories

(Core :: DOM: Navigation, defect)

defect

Tracking

()

RESOLVED DUPLICATE of bug 2035756

People

(Reporter: satyamasd, Unassigned)

References

Details

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

Attachments

(4 files)

Attached file poc.patch —

Description

This is a sibling of Bug 2046558 that I filed yesterday. That bug showed that session history IPC lets a compromised renderer inject an arbitrary principal via RecvSetActiveSessionHistoryEntry. While tracing through related code paths, I found that the same class of injection is possible through the DocumentChannel IPC path — and would require a separate fix.

The problem

When a content process initiates a document load, it sends a DocShellLoadStateInit to the parent via PDocumentChannelConstructor. The parent validates some fields but not all of them.

I looked at ValidateWithOriginalState() in nsDocShellLoadState.cpp and found that for parent-initiated loads that round-trip through the content process, it compares the returned state against the original. It checks URI, triggering principal, sandbox flags, remote type, and a few others — but it does not check PrincipalToInherit, SrcdocData, or InternalLoadFlags. There are FIXME comments in the code acknowledging this gap.

For child-initiated loads (where there's no original state to compare against), the only validation is that TriggeringRemoteType matches the sender, plus the srcdoc/URI consistency check added by Bug 2040160 (which passes here since we set URI = about:srcdoc). PrincipalToInherit is accepted as-is.

How it's exploited

A compromised renderer targets any of its own iframes. The crafted load request contains:

  • URI = about:srcdoc
  • SrcdocData = attacker's HTML with script
  • PrincipalToInherit = victim origin (e.g. https://victim.com)
  • The IS_SRCDOC internal load flag

The parent accepts these fields without validation. Since the URI is about:srcdoc and there's a PrincipalToInherit, the channel gets SEC_FORCE_INHERIT_PRINCIPAL. CheckForIncoherentResultPrincipal doesn't catch this because it doesn't have a condition for about:srcdoc inheriting an HTTP principal — same gap that Bug 2046558 relies on. The attacker's HTML then executes with full access to the victim's origin, cookies, and DOM.

Relationship to Bug 2046558

Both bugs exploit the same fundamental gap — PrincipalToInherit flows from IPC to document principal without validation. But they enter through different doors:

  • Bug 2046558 enters through the session history IPC handlers (RecvSetActiveSessionHistoryEntry).
  • This bug enters through the DocumentChannel IPC path (PDocumentChannelConstructor via PNecko). The attacker targets its own BC, so ownership checks alone don't help — the missing piece is that ValidateWithOriginalState and the child-initiated load path don't validate PrincipalToInherit.

Fixing Bug 2046558 at its entry point does not fix this path — they need separate fixes.

Steps to Reproduce

The attached poc.patch adds a test-only method testOnlyCraftedDocChannelLoad to Element (same pattern as the PoC for Bug 2046558). This method simulates what a compromised renderer would do: it calls nsDocShell::InternalLoad with a crafted nsDocShellLoadState containing a victim-origin PrincipalToInherit. The load goes through the full DocumentChannel IPC pipeline to the parent, which accepts it without validating the principal.

Note on PoC method: The method calls InternalLoad directly instead of LoadURI because LoadURI calls SetupInheritingPrincipal() which unconditionally overwrites PrincipalToInherit with TriggeringPrincipal — a content-process-side safety measure. A real compromised renderer would bypass this entirely by crafting the PDocumentChannelConstructor IPC message directly. Calling InternalLoad simulates that bypass.

Build & run

cd mozilla-unified
git apply poc.patch
./mach build

# Start two HTTP servers (attacker on 8000, victim on 8001):
python3 serve_poc.py

# Open the PoC:
./mach run http://localhost:8000/poc_validate.html

The attacker page at localhost:8000 creates an iframe, then calls testOnlyCraftedDocChannelLoad on it. This sends an about:srcdoc load through DocumentChannel IPC with PrincipalToInherit set to http://localhost:8001 (the victim). After ~1 second, the iframe displays injected content running as the victim's origin.

Expected Results

  1. ValidateWithOriginalState should also validate PrincipalToInherit, SrcdocData, and InternalLoadFlags against the original state
  2. For child-initiated loads, PrincipalToInherit should be validated against the sender's process
  3. CheckForIncoherentResultPrincipal should catch about:srcdoc inheriting an HTTP principal as defense-in-depth

Actual Results

The iframe shows:

window.origin: http://localhost:8001           ← victim origin
document.URI: about:srcdoc
Same-origin fetch to victim succeeded, length: 166
Cookies (victim origin): poc_injected=true

The attacker page at localhost:8000 injected HTML+JS that executes with full victim-origin (localhost:8001) privileges — including same-origin fetch and cookie access. The parent page can no longer access iframe.contentDocument (returns null), confirming the iframe genuinely became cross-origin.

Affected Versions

Tested on Firefox Nightly (latest as of 2026-06-11).

Impact

  • Prerequisites: Compromised renderer (standard Fission threat model). No user interaction needed. No special page structure needed — any iframe owned by the attacker's process works.
  • Impact: Full UXSS — attacker-controlled JavaScript executes in victim origin with access to cookies, localStorage, and same-origin DOM
Flags: sec-bounty?
Attached file serve_poc.py —
Attached file poc_validate.html —
Group: firefox-core-security → dom-core-security
Component: Security → DOM: Navigation
Product: Firefox → Core

vhilla: is this a dupe of bug 2034682 / bug 2035756? We knew those were still problems even when we fixed the bug 2040160 part.

Flags: needinfo?(vhilla)

Yes, it's a duplicate. Though the PoC is broken as it has to be <\/script> instead of <\\/script>.

Status: UNCONFIRMED → RESOLVED
Closed: 5 months ago
Duplicate of bug: 2035756
Flags: needinfo?(vhilla)
Resolution: --- → DUPLICATE
Flags: sec-bounty? → sec-bounty-
See Also: → CVE-2026-15719
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: