Skip to content

feat: collect security key PINs via 'collect-webauthn-pin' session event - #53351

Closed
SeraVault wants to merge 1 commit into
electron:mainfrom
SeraVault:feat/webauthn-pin-collection
Closed

SeraVault wants to merge 1 commit into
electron:mainfrom
SeraVault:feat/webauthn-pin-collection

Conversation

@SeraVault

Copy link
Copy Markdown

Description of Change

On platforms without a system-level WebAuthn UI — notably Linux — a security key that requires user verification currently cannot complete a WebAuthn request in Electron. Chromium's FIDO layer asks its embedder to collect the PIN through FidoRequestHandlerBase::Observer::SupportsPIN() / CollectPIN(); ElectronAuthenticatorRequestClientDelegate leaves those at the content-layer defaults (no PIN support), so the request stalls with nowhere to ask for the PIN. (On Windows the OS's own WebAuthn dialogs handle this; on macOS the Touch ID / platform-passkeys paths from #51255 cover platform authenticators.)

This PR implements the PIN observer hooks and bridges them to a new session event, collect-webauthn-pin, following the pattern established by select-webauthn-account:

session.defaultSession.on('collect-webauthn-pin', async (event, details, callback) => {
  // details: { relyingPartyId, reason, error, minPinLength, attemptsRemaining, frame }
  const pin = await showPinDialog(details) // app-drawn UI
  callback(pin) // or callback() to cancel → page gets NotAllowedError
})

Design notes:

  • Strictly opt-in. SupportsPIN() reports true only while a listener is registered for the event. Apps that don't listen keep today's behavior exactly — in particular, userVerification: 'preferred' requests keep completing without UV where the authenticator allows it, rather than being routed into a PIN exchange nothing can service.
  • Local validation before the authenticator is touched. Entries are checked with device::pin::ValidatePIN and the event re-fires with error set (too-short, invalid-characters, …) instead of consuming one of the authenticator's limited retry attempts on a PIN that cannot possibly be accepted — mirroring what Chrome's PIN dialog does inline. A well-formed but wrong PIN re-fires with error: 'wrong-pin' and an updated attemptsRemaining.
  • reason covers all three CTAP PIN ceremonies (challenge, set, change), so keys that require an initial PIN, or a PIN change after a minimum-length increase, also work.
  • StartBioEnrollment() is dismissed immediately (the equivalent of Chrome's "skip" button, posted asynchronously per the observer contract). Without this, enabling PIN support would make makeCredential on a biometric-capable but unenrolled key (e.g. a fresh YubiKey Bio) hang waiting on enrollment UI that never appears.
  • OnRetryUserVerification() is intentionally not surfaced: the token requester re-polls the authenticator automatically, so it is purely informational. It could be exposed as a follow-up event if there's interest, as could FinishCollectToken() (a "PIN accepted, now touch your key" signal).

The event/emit plumbing (session lookup, weak-pointer guards around synchronous callback re-entry, cancel-on-no-listener) deliberately matches SelectAccount in the same file.

Status / why this is a draft: this change has not yet been built against a full Electron checkout or exercised against hardware. I'm setting up an Electron build to verify compilation and to test end-to-end on Linux with FIDO2 keys that have a PIN set (the failing case that motivated this). I'll mark the PR ready once that's done — early feedback on the API shape is very welcome in the meantime.

Testing: the added spec covers the opt-in guarantee that can run in CI (a registered collect-webauthn-pin listener flips SupportsPIN() on, and must not change the outcome of a request the authenticator satisfies with its own UV — the event must not fire). The PIN exchange itself can't be driven by the CDP virtual authenticator, which fakes UV internally, so that path is verified against real hardware.

Per the AI contribution policy: this change was written with Claude Code (model claude-fable-5); the commit carries a Co-Authored-By trailer. I have reviewed the change and am responsible for it.

Checklist

Release Notes

Notes: Added the collect-webauthn-pin session event, enabling apps to collect a security key's PIN so that WebAuthn requests requiring user verification can complete on platforms without system WebAuthn UI (e.g. Linux).

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Aug 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ This PR contains unsigned commits. This repository enforces commit signatures
for all incoming PRs. To get your PR merged, please sign those commits
(git rebase --exec 'git commit -S --amend --no-edit -n' @{upstream}) and force push them to this branch
(git push --force-with-lease)

For more information on signing commits, see GitHub's documentation on Telling Git about your signing key.

@github-actions github-actions Bot added the needs-signed-commits Currently some or all of the commits in this PR are not signed label Aug 31, 2026
@SeraVault
SeraVault force-pushed the feat/webauthn-pin-collection branch from 77c75e8 to 01699eb Compare August 31, 2026 23:08
Chromium's FIDO layer asks its embedder to collect a PIN through
FidoRequestHandlerBase::Observer::SupportsPIN()/CollectPIN(). Electron's
authenticator request delegate left those at the content-layer defaults
(no PIN support), so on platforms without a system WebAuthn UI — notably
Linux — a security key that requires user verification could never
complete a request: there was nowhere to ask for the PIN.

Implement the PIN observer hooks and bridge them to a new session event,
'collect-webauthn-pin', following the same pattern as
'select-webauthn-account':

- SupportsPIN() reports true only while a listener is registered for the
  event, so PIN collection is strictly opt-in and existing apps keep
  their current behavior (e.g. userVerification 'preferred' requests
  continue to complete without UV rather than being routed into a PIN
  exchange nothing can service).
- CollectPIN() emits the event with the relying party id, the reason
  ('challenge' | 'set' | 'change'), the error from a failed previous
  attempt, the authenticator's minimum PIN length, and the remaining
  attempts before hard lock. The listener answers through a callback;
  calling it with no arguments cancels the request.
- Entries are validated locally with device::pin::ValidatePIN before
  being sent to the authenticator, re-emitting the event with 'error'
  set instead of consuming one of the limited retry attempts on a PIN
  that cannot possibly be accepted — mirroring Chrome's PIN dialog.
- StartBioEnrollment() dismisses inline biometric enrollment
  immediately (the equivalent of Chrome's "skip" button) so that
  makeCredential on a biometric-capable but unenrolled key proceeds
  instead of waiting on UI that will never appear.

Co-Authored-By: Claude Fable 5 <[email protected]>
@SeraVault
SeraVault force-pushed the feat/webauthn-pin-collection branch from 01699eb to 4af03c3 Compare August 31, 2026 23:28
@MarshallOfSound

Copy link
Copy Markdown
Member

This change won't be reviewed until the PR has signed commits and is ready for CI to run (signed commits are a pre-req here)

@MarshallOfSound

Copy link
Copy Markdown
Member

Closing this out as it's in conflict and the request for signed commits has been ignored

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

Labels

needs-signed-commits Currently some or all of the commits in this PR are not signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants