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)
Tracking
()
People
(Reporter: geeknik, Unassigned)
Details
(Keywords: reporter-external, Whiteboard: [client-bounty-form])
Attachments
(1 file)
|
11.28 KB,
text/javascript
|
Details |
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
dom/ipc/BrowserParent.cpp:3912(RecvInvokeDragSession) constructsRemoteDragStartDatawithaPrincipaldirectly. NoValidatePrincipalcall.dom/events/EventStateManager.cpp:2982-2990chrome branch ofDetermineDragTargetAndDefaultDatareads the principal back out viaRemoteDragStartData::AddInitialDnDDataTo.dom/events/RemoteDragStartData.cpp:39-83returns the forgedmPrincipalto the caller and also seedsDataTransfer::SetDataWithPrincipalFromOtherProcesswith it.dom/events/EventStateManager.cpp:3160-3179DoDefaultDragStartpasses the forged principal tonsIDragService::InvokeDragSessionWithImage(... aPrincipal ...)(or the selection/remote-image variants).widget/nsBaseDragService.cpp:313nsBaseDragSession::InvokeDragSessionstores it asmTriggeringPrincipal = aPrincipal.dom/events/DataTransfer.cpp:419-437DataTransfer::GetMozTriggeringPrincipalURISpecreturns the forged principal's ASCII spec to JS callers via themozTriggeringPrincipalURISpecgetter.dom/base/ContentAreaDropListener.sys.mjs:167-209_getTriggeringPrincipalFromDataTransferreadsaDataTransfer.mozTriggeringPrincipalURISpecand callsServices.scriptSecurityManager.createContentPrincipal(uri, {})from the forged value. ThesourceNode-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.dom/base/ContentAreaDropListener.sys.mjs:127-164_validateURIthen callssecMan.checkLoadURIWithPrincipal(forgedPrincipal, droppedURI, flags). A forgedfile://principal trivially passes this check forfile://URIs, where the actual HTTP(S) source principal would be rejected.browser/components/tabbrowser/content/drag-and-drop.js:644-677handle_dropcallsdropLinks(event, true)andgetTriggeringPrincipal(event), then invokesgBrowser.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.dropLinksrejects a drop offile:///etc/passwd(or anyfile://URL) onto the tab strip because the HTTP attacker principal cannot passcheckLoadURIWithPrincipal. With the forge, the chrome layer believes the drag was triggered by afile://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 astriggeringPrincipal, 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 aPolicyContainerwithout 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
loadTabsthat consults the triggering principal — e.g. URL-bar autofill,Permissionlookups, 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 inBrowserParent/ContentParentthat takes a principal and skipsValidatePrincipal. The same fix landed for sibling handlers (seeContentParent.cpp:3243for 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:
test_forged_principal_is_returned_by_drop_listener— provesdt.mozTriggeringPrincipalURISpecreturns the forged URI verbatim andServices.droppedLinkHandler.getTriggeringPrincipal(event)returns the forgedfile://principal. Then verifies thatcheckLoadURIWithPrincipalaccepts the forgedfile://principal for afile://URL while rejecting the real attacker HTTP principal for the same URL.test_forged_principal_is_used_by_tabbrowser_droplinks— provesServices.droppedLinkHandler.dropLinks(event, /*disallowInherit=*/true)(the exact API call made bybrowser/components/tabbrowser/content/drag-and-drop.js:624) accepts thefile:///URL when the forged principal is in place.test_attacker_principal_alone_cannot_drop_file_url— negative control: with only the real HTTP attacker principal astriggeringPrincipal,dropLinksthrows and the URL is rejected. Confirms the attack prerequisite is exactly "forge a principal whose origin can load the target URL".test_forged_chrome_origin_is_trusted_too— proves the primitive is not restricted tofile://. Any content principal flows through (PoC useshttps://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):
-
Validate
aPrincipalagainst 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 forLoadURIExternal), etc. -
Validate
aPolicyContaineranalogously, 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:
- Document explicitly that
mozTriggeringPrincipalURISpecreflects 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 sourceWindowContext's principal, looked up in the parent rather than read off the DataTransfer). The current pattern of "filter out<browser>source nodes and trustmozTriggeringPrincipalURISpecinstead" 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.
| Reporter | ||
Comment 1•6 months ago
|
||
POC, 4 tasks / 16 subtests, all passing, ESLint clean
Updated•6 months ago
|
Updated•6 months ago
|
Updated•5 months ago
|
Updated•5 months ago
|
Updated•17 days ago
|
Description
•