Skip to content

feat: attribute hid, usb and serial device permissions to the requesting frame - #53657

Open
MarshallOfSound wants to merge 6 commits into
mainfrom
feat/device-permissions-requesting-frame
Open

MarshallOfSound wants to merge 6 commits into
mainfrom
feat/device-permissions-requesting-frame

Conversation

@MarshallOfSound

@MarshallOfSound MarshallOfSound commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

Description of Change

Stacked on #53656 (base branch fix/hid-usb-check-requesting-frame; retarget to main once that lands). Main-only for 46: this changes observable behaviour and is recorded in docs/breaking-changes.md.

Makes every WebHID / WebUSB / Web Serial decision identify the requesting frame and agree on its origin, and documents the model:

  • setPermissionCheckHandler gets details.frame and details.embeddingOrigin on every frame-scoped check; setDevicePermissionHandler gets details.frame and details.selected (+ deviceId / portId as the chooser reported them); setUSBProtectedClassesHandler gets details.origin / details.frame; select-serial-port, serial-port-added/removed, usb-device-added/removed, hid-device-revoked and usb-device-revoked carry the requesting frame.
  • The hid / usb / serial check gates getDevices() / open() as well as the chooser; chooser selections are always recorded and reported to setDevicePermissionHandler (which is now consulted for every device); forget() closes the device in every document of the origin (chooser contexts notify content; carried patch keys SerialService on the requesting frame and hands the frame to UsbDelegate::RevokeDevicePermissionWebInitiated).
  • Serial: every session's SerialChooserContext is observed (only the first was, so connect/disconnect/revocation were dead elsewhere); OnPortConnectedStateChanged forwarded; chooser controller deleted with its frame. USB: in-memory partitions get a UsbChooserContext (WebUSB was a no-op there and requestDevice() could crash, fixes [Bug]: navigator.usb.requestDevice() crashes the browser process (SIGSEGV) on a named session partition #52383); chooser-handler re-entrancy guard; details.device.configurations[].interfaces is an array; smart-card extension-ID auto-grant removed.
  • Tests: in-process fake HID/USB/serial device managers behind the testing binding and spec/api-device-permissions-spec.ts (attribution per topology, chooser identity, handler veto, check gating, cross-document revocation, chooser handler destroying the window, usb details shape, protected classes, *-added frames, serial connect/disconnect).
  • Docs: new docs/tutorial/permissions.md describing Electron's web permission model, how it differs from Chrome's top-level-site model and how to key on frame.top.origin to match Chrome; breaking-changes.md entry for 46.

Checklist

  • PR description included and stakeholders cc'd
  • npm test passes
  • tests are changed or added
  • relevant documentation is changed or added

Release Notes

Notes:

  • hid, usb and serial permission handlers and events now identify the requesting frame via details.frame or a trailing frame argument.
  • setDevicePermissionHandler now receives details.selected.
  • Denying the hid, usb or serial permission check now blocks access to already-granted devices.
  • forget() now closes the device in every document of the origin.
  • WebUSB now works in in-memory partitions.

@MarshallOfSound
MarshallOfSound requested review from a team as code owners September 7, 2026 07:22
@MarshallOfSound MarshallOfSound added semver/minor backwards-compatible functionality no-backport labels Sep 7, 2026
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Sep 7, 2026
@MarshallOfSound MarshallOfSound added the backport-check-skip Skip trop's backport validity checking label Sep 7, 2026
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Sep 7, 2026
Base automatically changed from fix/hid-usb-check-requesting-frame to main September 7, 2026 15:45
@MarshallOfSound
MarshallOfSound force-pushed the feat/device-permissions-requesting-frame branch from d081f7f to a62f42b Compare September 7, 2026 15:52
@MarshallOfSound MarshallOfSound self-assigned this Sep 7, 2026
@MarshallOfSound
MarshallOfSound force-pushed the feat/device-permissions-requesting-frame branch 2 times, most recently from 28a6f9a to 5e42fe7 Compare September 10, 2026 03:25
MarshallOfSound and others added 6 commits September 17, 2026 23:20
…rame

* setPermissionCheckHandler receives details.frame and details.embeddingOrigin
  for every frame-scoped check
* HasDevicePermission is gated on the hid/usb permission check, so denying
  the check also hides granted devices from getDevices()/open()
* chooser selections are always recorded and reported to
  setDevicePermissionHandler as details.selected, with details.frame and, for
  hid, the deviceId the chooser reported; without a handler a selection is a
  grant as before
* forget() notifies content from a posted task so every document of the
  origin drops the device; the carried patch hands the frame to
  UsbDelegate::RevokeDevicePermissionWebInitiated and keys SerialService on
  the requesting frame as well
* hid-device-revoked, usb-device-revoked, usb-device-added and
  usb-device-removed carry the requesting frame
* setUSBProtectedClassesHandler receives details.origin and details.frame
* UsbChooserContextFactory serves in-memory partitions (WebUSB was a no-op
  there); UsbChooserController guards against its handler destroying the
  frame; usb details.device.configurations[].interfaces is a list and
  configuration sits on the device; persistent grants are de-duplicated
* the smart-card auto-grant keyed on Chrome extension IDs is removed
* 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, details.selected and portId to setDevicePermissionHandler and
  consults it for ports without a persistent id
* forget() notifies content so other documents' connections close
* forward OnPortConnectedStateChanged so navigator.serial fires
  connect/disconnect for Bluetooth serial ports
* observe every session's SerialChooserContext, not only the first one used
* delete SerialChooserController with its frame and guard against its
  handler destroying the frame
Add in-process fake HID, USB and serial device managers behind
process._linkedBinding('electron_common_testing') and
spec/api-device-permissions-spec.ts, which drives requestDevice/requestPort,
open, getDevices and forget from the main frame, a cross-origin iframe and a
sandboxed iframe and asserts what every handler and event receives, plus
revocation across documents, handler veto, check gating, chooser handlers
destroying the window, usb details shape, protected-classes identity,
serial-port-added / usb-device-added frames and serial connect/disconnect.
…hange

Add docs/tutorial/permissions.md covering which frame each permission and
device handler is told about, how that differs from Chrome's top-level-site
model, and how to key on the top-level site instead; link it from the
devices, security and examples pages; add the breaking-changes entry.
@MarshallOfSound
MarshallOfSound force-pushed the feat/device-permissions-requesting-frame branch from 5e42fe7 to 56cc1b5 Compare September 17, 2026 23:26
@release-clerk

release-clerk Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Release note looks good now.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-check-skip Skip trop's backport validity checking no-backport semver/minor backwards-compatible functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: navigator.usb.requestDevice() crashes the browser process (SIGSEGV) on a named session partition

1 participant