Closed Bug 2041964 Opened 6 months ago Closed 6 months ago

Compromised content can forge `nsIPrincipal` argument to `PBrowser::InvokeDragSession`, causing chrome-side drop handler to treat dropped URLs as triggered by an attacker-chosen origin (file:// drop bypass + cross-origin triggering-principal injection)

Categories

(Core :: DOM: Copy & Paste and Drag & Drop, defect)

defect

Tracking

()

RESOLVED DUPLICATE of bug 1500946

People

(Reporter: geeknik, Unassigned)

Details

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

Attachments

(1 file)

Description

A compromised Firefox content process can cause the parent process to use an attacker-controlled nsIPrincipal as the triggering principal for any URL load that originates from the user dropping content onto the chrome UI (tab strip, URL bar, etc.). The chrome drop handler subsequently passes that principal to Services.scriptSecurityManager.checkLoadURIWithPrincipal, allowing URL loads that the real source origin would otherwise be denied — most cleanly demonstrated by dropping a file:/// URL from an HTTP(S) attacker page.

BrowserParent::RecvInvokeDragSession (dom/ipc/BrowserParent.cpp:3912) accepts a content-supplied nsIPrincipal* aPrincipal argument and forwards it to the parent's drag session state without authenticating it against the sending child process. Every comparable principal-accepting IPC method in ContentParent.cpp calls ValidatePrincipal (see ContentParent.cpp:3243, :3443, :5502, :5880, etc.). RecvInvokeDragSession is the missing case.

The forged principal then propagates through the drag/drop machinery into a chrome JavaScript trust decision.

Code path

  1. dom/ipc/BrowserParent.cpp:3912 (RecvInvokeDragSession) constructs RemoteDragStartData with aPrincipal directly. No ValidatePrincipal call.
  2. dom/events/EventStateManager.cpp:2982-2990 chrome branch of DetermineDragTargetAndDefaultData reads the principal back out via RemoteDragStartData::AddInitialDnDDataTo.
  3. dom/events/RemoteDragStartData.cpp:39-83 returns the forged mPrincipal to the caller and also seeds DataTransfer::SetDataWithPrincipalFromOtherProcess with it.
  4. dom/events/EventStateManager.cpp:3160-3179 DoDefaultDragStart passes the forged principal to nsIDragService::InvokeDragSessionWithImage(... aPrincipal ...) (or the selection/remote-image variants).
  5. widget/nsBaseDragService.cpp:313 nsBaseDragSession::InvokeDragSession stores it as mTriggeringPrincipal = aPrincipal.
  6. dom/events/DataTransfer.cpp:419-437 DataTransfer::GetMozTriggeringPrincipalURISpec returns the forged principal's ASCII spec to JS callers via the mozTriggeringPrincipalURISpec getter.
  7. dom/base/ContentAreaDropListener.sys.mjs:167-209 _getTriggeringPrincipalFromDataTransfer reads aDataTransfer.mozTriggeringPrincipalURISpec and calls Services.scriptSecurityManager.createContentPrincipal(uri, {}) from the forged value. The sourceNode-based branch above does not apply because for any remote-initiated drag the source node in the chrome process is the <browser> element, which the listener intentionally filters out.
  8. dom/base/ContentAreaDropListener.sys.mjs:127-164 _validateURI then calls secMan.checkLoadURIWithPrincipal(forgedPrincipal, droppedURI, flags). A forged file:// principal trivially passes this check for file:// URIs, where the actual HTTP(S) source principal would be rejected.
  9. browser/components/tabbrowser/content/drag-and-drop.js:644-677 handle_drop calls dropLinks(event, true) and getTriggeringPrincipal(event), then invokes gBrowser.loadTabs(urls, { triggeringPrincipal, policyContainer, ... }). The forged principal becomes the triggering principal of the newly-opened tab.

The chrome-side filter at ContentAreaDropListener.sys.mjs:171-187 explicitly bypasses sourceNode.nodePrincipal when sourceNode.localName === "browser", which is exactly the case for every drag whose source is in a content process. That branch was added intentionally — it explains in the comment that the source node's principal is the embedder's top-level principal and not the actual drag-source principal — but the fallback it uses (mozTriggeringPrincipalURISpec → forged value) inherits the unvalidated content-supplied data.

Impact

  • Drag-to-load file:// from HTTP(S) attacker page. Without the forge, Services.droppedLinkHandler.dropLinks rejects a drop of file:///etc/passwd (or any file:// URL) onto the tab strip because the HTTP attacker principal cannot pass checkLoadURIWithPrincipal. With the forge, the chrome layer believes the drag was triggered by a file:// principal and the URL loads in a new tab. This is the classic "drag-and-drop to read arbitrary local files" primitive. The user only needs to drag content from the attacker page and drop it on a chrome drop target — a single-gesture UI flow.
  • Triggering-principal injection for any same-origin URL. Any HTTPS origin can be forged (e.g. https://accounts.google.com). The URL is opened with that origin as triggeringPrincipal, affecting CSP-inheritance, Sec-Fetch-Site, Referer, and any permission/audit logic that consults the triggering principal.
  • Policy container is also content-supplied. The same IPC handler accepts nsIPolicyContainer aPolicyContainer without validation. Although the PoC focuses on the principal, the policy container flows along the same path; an attacker can also forge the loaded URL's CSP context.
  • Cross-origin permission consumption (potential). Any chrome flow downstream of loadTabs that consults the triggering principal — e.g. URL-bar autofill, Permission lookups, anti-tracking heuristics — receives the forged value. Not fully enumerated; flagging for reviewer attention.
  • Defense-in-depth violation. Even setting impact aside, the IPC handler is the only Recv* method in BrowserParent/ContentParent that takes a principal and skips ValidatePrincipal. The same fix landed for sibling handlers (see ContentParent.cpp:3243 for the transferable-data-principal validation).

Proof of concept

Attached: browser_drag_forged_principal.js (browser mochitest).

Registered in browser/components/tabbrowser/test/browser/dragdrop/browser.toml.

Four tasks, sixteen subtests:

  1. test_forged_principal_is_returned_by_drop_listener — proves dt.mozTriggeringPrincipalURISpec returns the forged URI verbatim and Services.droppedLinkHandler.getTriggeringPrincipal(event) returns the forged file:// principal. Then verifies that checkLoadURIWithPrincipal accepts the forged file:// principal for a file:// URL while rejecting the real attacker HTTP principal for the same URL.
  2. test_forged_principal_is_used_by_tabbrowser_droplinks — proves Services.droppedLinkHandler.dropLinks(event, /*disallowInherit=*/true) (the exact API call made by browser/components/tabbrowser/content/drag-and-drop.js:624) accepts the file:/// URL when the forged principal is in place.
  3. test_attacker_principal_alone_cannot_drop_file_url — negative control: with only the real HTTP attacker principal as triggeringPrincipal, dropLinks throws and the URL is rejected. Confirms the attack prerequisite is exactly "forge a principal whose origin can load the target URL".
  4. test_forged_chrome_origin_is_trusted_too — proves the primitive is not restricted to file://. Any content principal flows through (PoC uses https://accounts.google.com).

Reproduction:

./mach lint browser/components/tabbrowser/test/browser/dragdrop/browser_drag_forged_principal.js
./mach test browser/components/tabbrowser/test/browser/dragdrop/browser_drag_forged_principal.js

Result on the verified-on tree: TEST PASS, Subtests passed 16/16, Unexpected 0.

The test uses MockRegistrar to install the in-tree MockDragService so that no native drag-and-drop is triggered. It manipulates dragSession.triggeringPrincipal directly to simulate the post-IPC state that a compromised content process would produce. The IPC-layer attack itself (sending a forged PBrowser::InvokeDragSession from a content process) is not directly exercisable from a mochitest because there is no scripted path that lets content call SendInvokeDragSession with an arbitrary principal — the C++ nsDragServiceProxy::InvokeDragSessionImpl uses mSourceNode->NodePrincipal(). The bug is therefore exploitable today by:

  • A compromised content process (e.g. via a memory-safety bug in content) sending a hand-crafted IPC message.
  • An IPC-layer fuzzer.
  • Any future content code path that grows the ability to pass an arbitrary principal to SendInvokeDragSession.

The PoC isolates the chrome-side trust chain to demonstrate that the only thing standing between "compromised content sends a forged IPC" and "chrome JS loads file:// from an HTTP page" is the missing ValidatePrincipal check. Mozilla bounty precedent (and the sibling RecvLoadURIExternal finding) has historically paid for missing-validation IPC bugs in this class even when the IPC-layer forge requires a compromised-content assumption.

Suggested fix direction

In BrowserParent::RecvInvokeDragSession (dom/ipc/BrowserParent.cpp:3912):

  1. Validate aPrincipal against the sending child via the existing pattern:

    if (!Manager()->ValidatePrincipal(
            aPrincipal, {ValidatePrincipalOptions::AllowNullPtr,
                         ValidatePrincipalOptions::AllowExpanded})) {
      ContentParent::LogAndAssertFailedPrincipalValidationInfo(
          aPrincipal, __func__);
    }
    

    This matches the pattern at dom/ipc/ContentParent.cpp:3243 (transferable data principal), :3443 (requesting principal), :5502 (triggering principal for LoadURIExternal), etc.

  2. Validate aPolicyContainer analogously, since it travels the same code path and is consumed by the same chrome JS chain.

Defense in depth in dom/base/ContentAreaDropListener.sys.mjs:167:

  1. Document explicitly that mozTriggeringPrincipalURISpec reflects an unvalidated content-supplied value when the drag originated in a remote process, and consider gating its use on a parent-side authoritative source (e.g. the BrowserParent's tracked source WindowContext's principal, looked up in the parent rather than read off the DataTransfer). The current pattern of "filter out <browser> source nodes and trust mozTriggeringPrincipalURISpec instead" hides the trust-boundary crossing from reviewers.

The above is a sketch; a Mozilla developer is better placed to choose between "validate at IPC entry" and "derive in parent from authoritative source" approaches.

Verified on

Local Firefox source tree at commit 2bd78d82d0128abc12df9900b6cb264f92adb9d0 (main, 2026-05-23). The code path involves long-standing call sites; this is not a recent regression. Earlier and later Nightly builds are expected to share the same missing validation.

Flags: sec-bounty?

POC, 4 tasks / 16 subtests, all passing, ESLint clean

Group: firefox-core-security → dom-core-security
Component: Security → DOM: Copy & Paste and Drag & Drop
Product: Firefox → Core
Status: NEW → RESOLVED
Closed: 6 months ago
Duplicate of bug: 2039244
Resolution: --- → DUPLICATE
Flags: sec-bounty? → sec-bounty-
Duplicate of bug: 1500946
No longer duplicate of bug: 2039244
Group: dom-core-security
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: