ScreenshotsHelperParent proxies GetElementRectFromPoint to any child BrowsingContext — cross-origin layout probe (elementFromPoint + bounding-rect) for any BCG member
Categories
(Firefox :: Screenshots, defect)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox-esr115 | --- | unaffected |
| firefox-esr140 | --- | wontfix |
| firefox150 | --- | wontfix |
| firefox151 | --- | wontfix |
| firefox152 | --- | fixed |
People
(Reporter: pakhunov.anton.n, Assigned: niklas)
References
(Blocks 1 open bug)
Details
(4 keywords, Whiteboard: [adv-main152-])
Attachments
(1 external file)
Summary
ScreenshotsHelperParent::receiveMessage accepts a bcId from the sending content process and forwards the GetElementRectFromPoint query to whatever BrowsingContext that id names, returning the answer to the sender. There is no check that the sender owns (or even shares a group with) the target BrowsingContext, and the child-side handler has no consent / UI-state gate of its own.
// browser/components/screenshots/ScreenshotsUtils.sys.mjs
export class ScreenshotsHelperParent extends JSWindowActorParent {
receiveMessage(message) {
switch (message.name) {
case "ScreenshotsHelper:GetElementRectFromPoint": {
let cxt = BrowsingContext.get(message.data.bcId);
return cxt.currentWindowGlobal
.getActor("ScreenshotsHelper")
.sendQuery("ScreenshotsHelper:GetElementRectFromPoint", message.data);
}
}
return null;
}
}
The child responder has no gate either — it just runs elementFromPoint/getBoundingClientRect on its own document and returns the rect:
// browser/components/screenshots/ScreenshotsHelperChild.sys.mjs
export class ScreenshotsHelperChild extends JSWindowActorChild {
receiveMessage(message) {
if (message.name === "ScreenshotsHelper:GetElementRectFromPoint") {
return this.getBestElementRectFromPoint(message.data);
}
return null;
}
async getBestElementRectFromPoint(data) {
let { x, y } = data;
x -= this.contentWindow.mozInnerScreenX;
y -= this.contentWindow.mozInnerScreenY;
let { ele, rect } = await getElementFromPoint(x, y, this.document);
if (!rect) rect = getBestRectForElement(ele, this.document);
// ... translate back to screen coords ...
return rect;
}
}
The actor is registered in DesktopActorRegistry.sys.mjs with allFrames: true and only gated by enablePreference: "screenshots.browser.component.enabled" (which defaults to enabled in shipping builds). No matches, no remoteTypes.
Attack
Setup: attacker's compromised renderer is in the same BrowsingContextGroup as a victim document — the standard opener/popup/iframe scenario we've been using for BCG-wide hijacks. BrowsingContext ids of group members are broadcast, so the attacker knows bank.com's BC id V.
The attacker sends, through its own ScreenshotsHelper JSActor:
const res = await windowGlobalChild.getActor("ScreenshotsHelper")
.sendQuery("ScreenshotsHelper:GetElementRectFromPoint",
{ bcId: V, x, y });
// res = { left, right, top, bottom } of whatever element is at (x,y) in bank.com's window
Parent picks up bank.com's WindowGlobalParent, hands the query to its ScreenshotsHelper child. That child runs getElementFromPoint on bank.com's real document and returns the element's on-screen rect back through the promise. No screenshots UI needs to be open in the victim, no user gesture, nothing in bank.com is notified.
By sweeping (x, y) the attacker rebuilds a coarse element-level layout map of the cross-origin document — positions and sizes of whatever the victim shows at each pixel. Practical uses:
- Detecting auth state from layout: logged-out
bank.comand logged-inbank.comdon't lay out the same; a small grid of samples is enough to tell them apart. - Locating specific UI elements (transfer button, confirm dialog, CSRF-able form) before driving a clickjacking or pointer-lock-based attack on the iframe.
- Confirming which account is logged in on sites whose layout varies with user data (name length, avatar presence).
Cross-origin getBoundingClientRect / elementFromPoint is normally blocked by the same-origin policy for precisely this reason. ScreenshotsHelperParent gives it back over IPC.
Fix
The parent should only proxy the query to the same WindowGlobalParent the message came from, or verify the target BC is owned by the sending content process. Something like:
receiveMessage(message) {
switch (message.name) {
case "ScreenshotsHelper:GetElementRectFromPoint": {
let cxt = BrowsingContext.get(message.data.bcId);
if (!cxt || cxt.currentWindowGlobal?.domProcess !== this.manager.domProcess) {
return null;
}
return cxt.currentWindowGlobal
.getActor("ScreenshotsHelper")
.sendQuery("ScreenshotsHelper:GetElementRectFromPoint", message.data);
}
}
return null;
}
Additionally the child could refuse to respond unless the screenshots UI is actually active for its top-level browser (ScreenshotsUtils.getUIPhase(topBrowser) !== UIPhases.CLOSED), since this helper only exists to support the overlay flow.
Version
mozilla-central HEAD.
Updated•7 months ago
|
Updated•7 months ago
|
Comment 1•7 months ago
|
||
Not exactly a "principal" that's involved here, but conceptually part of the same hardening. Firefox's current site isolation immediate goal is to prevent spectre-type attacks from legitimate web content against other sites. We eventually want to harden this to include protection against compromised renderers, but our current focus for the "compromised renderer" threat is for sandbox escapes, not cross-site information attacks.
Comment 2•7 months ago
|
||
If the premise given here stands up at all, the mitigation is pretty trivial and I/we could patch it anyway? If only to reduce noise from further reports. Let me know. I'm happy to review a patch or create one.
Comment 3•7 months ago
|
||
The parent should only proxy the query to the same WindowGlobalParent the message came from, or verify the target BC is owned by the sending content process. Something like:
This mitigation won't work because we actually need cross-process access e.g. if we want to screenshot a cross-origin iframe.
Additionally the child could refuse to respond unless the screenshots UI is actually active for its top-level browser (ScreenshotsUtils.getUIPhase(topBrowser) !== UIPhases.CLOSED), since this helper only exists to support the overlay flow.
This would be a reasonable mitigation, we should probably do generally. But it doesn't fully address the problem. The attacker could probe the API until screenshot mode is entered.
We could also restrict the GetElementRectFromPoint to only work in the same browsing context tree so that at least an attacker can't query stuff outside of the current tab. Websites can block being embedded in iframes, so at least they can protect themselves against this (and many other) attack(s).
Perhaps there is a more fundamental fix that I'm missing. Can we avoid the content process having to query data for arbitrary BCs somehow? Can we do more from the parent side?
Comment 4•7 months ago
|
||
Bug 2008912 added checking for BCs sent over IPC, but that won't help if a bare ID is sent like this. Maybe just sending the BC itself would work?
Comment 5•7 months ago
|
||
(In reply to Emma Zühlcke [:emz] from comment #3)
We could also restrict the
GetElementRectFromPointto only work in the same browsing context tree so that at least an attacker can't query stuff outside of the current tab. Websites can block being embedded in iframes, so at least they can protect themselves against this (and many other) attack(s).Perhaps there is a more fundamental fix that I'm missing. Can we avoid the content process having to query data for arbitrary BCs somehow? Can we do more from the parent side?
cc-ing in Niklas who wrote this. AIUI when we're handling pointer events, we're trying to identify a candidate block element (and handle <iframe>s) in order to outline which element the user wants to crop their screenshot to. This is in handleElementHover.
We had considered just dropping this mechanism for picking the crop rectangle when we ported over from the web extension, but it turns out a good 1/3 of users elect to crop this way - rather than drag/drop the rectangle markers "manually".
| Assignee | ||
Comment 6•7 months ago
|
||
Updated•7 months ago
|
Comment 8•6 months ago
|
||
Updated•6 months ago
|
Updated•6 months ago
|
Updated•5 months ago
|
Updated•5 months ago
|
Updated•2 months ago
|
Description
•