Repository navigation
fix: attribute hid, usb and serial device permissions to the requesting frame - #53629
Closed
codebytere wants to merge 11 commits into
Closed
codebytere wants to merge 11 commits into
codebytere wants to merge 11 commits into
Conversation
[WebHID][WebUSB] Pass the frame to CanRequestDevicePermission() https://chromium-review.googlesource.com/c/chromium/src/+/8364427
ElectronHidDelegate and ElectronUsbDelegate received the top-level document's origin from content and passed a null frame to the permission check handler, so a check from a cross-origin iframe delegated allow="hid"/"usb" reported the embedder's origin, no requestingUrl, isMainFrame false and a null webContents. Derive the origin from the requesting frame and pass the frame through, as the serial delegate does, so the handler sees the frame that is asking and HasDevicePermission matches the grants the choosers store under that frame's origin.
MarshallOfSound
approved these changes
Sep 6, 2026
MarshallOfSound
approved these changes
Sep 6, 2026
VerteDinde
approved these changes
Sep 6, 2026
…n-requesting-frame
Follow-on to the check-handler change so that all hid/usb device permission paths agree on the requesting document: * carry a second patch that constructs HidService/WebUsbServiceImpl with the requesting frame's origin, so forget(), usb/hid-device-revoked, the FIDO allow-list, protected interface classes and content's OnPermissionRevoked comparison use the origin the grant was stored under * notify content's OnPermissionRevoked from the chooser contexts so open connections held by other documents of the origin are closed * gate HasDevicePermission on the hid/usb permission check, so denying the check for a document also cuts off getDevices()/open() * with setDevicePermissionHandler installed, do not consult or populate the internal ephemeral grant set; pass details.frame to the handler * pass details.origin and details.frame to setUSBProtectedClassesHandler * refuse opaque-origin requesters before any handler runs * drop the smart-card auto-grant keyed on Chrome extension IDs * docs: setPermissionCheckHandler webContents/requestingUrl wording, new frame/origin fields
Do not refuse opaque-origin requesters on the app's behalf; instead give setPermissionCheckHandler a live details.frame so the app can attribute the check itself (frame.origin, frame.parent, frame.top) even when the requesting document's origin has no URL form.
* record every chooser selection for the session and report it to setDevicePermissionHandler as details.selected (with the deviceId the chooser reported for hid), so the handler is consulted for every device yet can honour selections; without a handler a selection is a grant as before * revoke: copy the origin, always clear the ephemeral entry (usb), and notify content from a posted task so app JS never runs under the caller's stack * guard UsbChooserController against the select-usb-device handler destroying the requesting frame * UsbChooserContextFactory: serve in-memory partitions (WebUSB was a no-op there) * usb DeviceInfoToValue: interfaces is a list, configuration sits on the device * de-duplicate persistent device grants * docs: selected/securityOrigin wording, example honours selections
* select-serial-port, serial-port-added and serial-port-removed carry the
requesting frame
* HasPortPermission is gated on the serial permission check, passes the
frame and details.selected/portId to setDevicePermissionHandler, and
consults the handler for ports without a persistent id
* forget() notifies content so other documents' connections close;
SerialService compares against the requesting frame's origin (patch)
* forward OnPortConnectedStateChanged so navigator.serial fires
connect/disconnect for Bluetooth serial ports
* observe every session's SerialChooserContext, not only the first
* delete SerialChooserController with its frame and guard the
select-serial-port handler destroying it
* testing: in-process fake HID/USB/serial managers behind
process._linkedBinding('electron_common_testing') and
spec/api-device-permissions-spec.ts covering attribution across main
frame / cross-origin iframe / sandboxed iframe, chooser identity,
handler veto, check gating, cross-document revocation, chooser
handler destroying the window, usb details shape, protected classes
identity, serial-port-added frame and connect/disconnect
The check handler docs describe embeddingOrigin, but only the permissions.query path set it; hid/usb/serial (and other delegate-driven) checks left it undefined, so a handler keyed on the embedder failed open for subframes. Derive it from the requesting frame's main frame whenever a frame is present and the caller has not supplied one.
…ents hid-device-revoked, usb-device-revoked, usb-device-added and usb-device-removed now identify the frame like their serial and hid counterparts; the carried patch hands the frame to UsbDelegate::RevokeDevicePermissionWebInitiated() for that.
Member
|
Splitting this: the narrow hid/usb check-handler fix (backportable) and the wider per-frame device permission changes (46 only) are going up as two PRs off our branches. Thanks for the start here. |
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Change
Device permission decisions for WebHID, WebUSB and Web Serial were attributed inconsistently: the
hid/usbcheck handler saw the top-level origin with a nullwebContents/frame, grants were stored under one origin and looked up or revoked under another,select-serial-portcarried no frame,setDevicePermissionHandlerwas bypassed for devices without a persistent id (and had no frame),forget()never reached other documents' open connections, and WebUSB silently did nothing in in-memory partitions. This makes every hid/usb/serial decision carry the requesting frame and agree on its origin.setPermissionCheckHandler(hid/usb/serial),setDevicePermissionHandler,setUSBProtectedClassesHandler,select-hid-device/select-usb-device/select-serial-port,serial-port-added/removedand*-revokedall identify the requesting frame (details.frame/ trailingframeargument) and its origin — including cross-origin and sandboxed (opaque-origin) subframes, which are reported as-is for the app to decide on.HidService/WebUsbServiceImpl/SerialServiceare keyed on the requesting frame's origin (two carried patches; theCanRequestDevicePermission(rfh)one is upstreamed as https://crrev.com/c/8364427), so grant, check,forget(), revoked events, FIDO/protected-class decisions andOnPermissionRevokeduse one origin.forget()notifies content, closing the device in every document of that origin;HasDevicePermission/HasPortPermissionare gated on the permission check; chooser selections are always recorded and reported tosetDevicePermissionHandlerasdetails.selected(+deviceId/portId) so the handler is consulted for every device but can honour selections.SerialServices were ever notified),OnPortConnectedStateChangedforwarded, controller deleted with its frame; USB: in-memory partitions get aUsbChooserContext, chooser-handler re-entrancy guard,details.device.configurations[].interfacesis an array; smart-card extension-ID auto-grant removed.spec/api-device-permissions-spec.ts(28 cases: attribution per topology, chooser identity, handler veto, check gating, cross-document revocation, chooser handler destroying the window, usb details shape, protected-classes identity, serial-port-added frame, connect/disconnect), plus cross-origin / opaque subframe check-handler specs inapi-session-spec.ts.Checklist
npm testpassesRelease Notes
Notes: Fixed
hid,usbandserialpermission checks, device grants and revocations being attributed to the wrong frame or origin;setPermissionCheckHandler,setDevicePermissionHandler,setUSBProtectedClassesHandler,select-serial-portandserial-port-added/-removednow receive the requestingframe,setDevicePermissionHandlerreceivesdetails.selected, and WebUSB works in in-memory partitions.