Skip to content

ui-react: passkey ceremonies use native WebAuthn JSON APIs with an owned abort signal instead of @simplewebauthn/browser #2556

Open

Description

@schlessera

Context

The client runs every WebAuthn ceremony through @simplewebauthn/browser (packages/ui-react/src/lib/passkeys.ts:1-58, dependency packages/ui-react/package.json:56). Guide security/passkeys, §4: "do NOT substitute third-party library wrappers (such as SimpleWebAuthn's startAuthentication/startRegistration) on the client — call the native WebAuthn browser APIs directly." Library recommendations there "apply to the server-side … only".

The wrapper hides the request lifecycle, which causes four defects:

  1. Unmount does not abort. loginWithPasskey and registerPasskey check signal only between steps (passkeys.ts:39-47, 52-57). navigator.credentials.get/create receives the library's own singleton signal, not ours. A pending conditional get() therefore outlives the login screen's effect cleanup (login-screen.tsx:110), and leaving the Security tab does not cancel an open registration prompt.
  2. A cancelled button prompt kills autofill. Starting the button ceremony (onPasskeyClick, login-screen.tsx:130-146) makes the library abort the pending conditional request. The conditional catch treats that AbortError as a cancel (lines 101-104), and the effect runs once per root (line 111). After one cancelled button prompt, the password field never offers passkeys again. Guide security/passkey-authentication: "Abort any ongoing form autofill (Conditional Get) calls before invoking the passkey prompt". Its example re-arms after the cancel ("Re-arm Conditional autofill Suggestions after cancelled explicit button prompts").
  3. A Proxy hack. To start the sign-in guard only once the user has picked a credential, the screen wraps api in a Proxy that intercepts passkeyLoginVerify (login-screen.tsx:90-97).
  4. Weak capability detection and error mapping. browserSupportsWebAuthn() is the only gate (passkey-tab.tsx:39, consumed by passkey-list.tsx:43). A duplicate registration (InvalidStateError from excludeCredentials, packages/ui-server/src/middleware/passkeys.ts:485-488) surfaces as the raw library message. Guide security/passkey-registration lists "InvalidStateError: A matching passkey already exists".

The library's JSON types also leak into the published API. BrainApi.passkeyLoginOptions/LoginVerify/RegisterOptions/RegisterVerify are typed with import("@simplewebauthn/browser")…JSON (api-report/ui-react.txt:1529-1534; source packages/ui-react/src/lib/api-client.ts:709-748). TypeScript 6's lib.dom.d.ts declares the same JSON types natively: PublicKeyCredentialRequestOptionsJSON, PublicKeyCredentialCreationOptionsJSON, AuthenticationResponseJSON, RegistrationResponseJSON.

Support: the parse*FromJSON/toJSON() APIs exist in Chrome Android 129, Samsung Internet 28 and Firefox Android 119. getClientCapabilities() exists in Chrome Android 133, Samsung 29 and Firefox Android 135. The epic has the support table.

Scope

  • Rewrite packages/ui-react/src/lib/passkeys.ts on native APIs. Use PublicKeyCredential.parseRequestOptionsFromJSON / parseCreationOptionsFromJSON, navigator.credentials.get/create({ publicKey, signal, mediation? }) and credential.toJSON(). The caller's AbortSignal goes straight into get/create.
  • Fallback when the parse methods or toJSON are absent (older Samsung Internet or WebView builds): use an internal base64url codec in the same file, no new dependency. It converts the binary fields listed in the WebAuthn L3 JSON mapping in both directions.
  • Add passkeyCapabilities(): Promise<{ webauthn; conditionalGet; platformAuthenticator }>. It uses PublicKeyCredential.getClientCapabilities() (conditionalGet, passkeyPlatformAuthenticator). Where that method is missing, it falls back to isConditionalMediationAvailable() and isUserVerifyingPlatformAuthenticatorAvailable(). Where PublicKeyCredential itself is missing, everything is false.
  • In LoginScreen:
  • In PasskeyTab/PasskeyList:
    • Gate the Add button on capabilities.webauthn. Keep security keys and hybrid allowed: the management flow omits authenticatorAttachment, per guide security/passkey-registration §6.
    • Map InvalidStateError to "This device already has a passkey for this site."
    • Abort an open registration when the tab's lifetime ends.
  • Retype the four BrainApi passkey methods with the DOM lib JSON types. Remove @simplewebauthn/browser from packages/ui-react/package.json and the lockfile. Regenerate api-report/.

Out of scope

Acceptance criteria

  • packages/ui-react has no import of @simplewebauthn/browser. It is gone from package.json and bun.lock, and api-report/ui-react.txt no longer mentions it.
  • A type test (*.test-d.ts, like packages/ui-react/tests/block-contract.test-d.ts) shows the old library JSON types and the new DOM JSON types are mutually assignable for all four BrainApi passkey methods. If they are not, stop: the change is breaking, and needs the breaking label and a maintainer ruling on this issue before merging.
  • Real-Chrome runtime test (Playwright, CDP virtual authenticator, real ui-server routes) passes each of these:
    • Password-plus-passkey screen: cancel a button ceremony (virtual authenticator with no user verification) and the next focus of the password field still offers the passkey (conditional get re-armed). Fails before the change.
    • Unmounting the login screen while a conditional get is pending aborts it: the pending request rejects with AbortError, and a new ceremony on the next mount succeeds.
    • Button sign-in and Security-tab registration both verify against the unchanged server using native toJSON() output.
    • Registering a second time on the same virtual authenticator shows the InvalidStateError message.
  • A unit test runs the fallback codec: with parseRequestOptionsFromJSON, parseCreationOptionsFromJSON and PublicKeyCredential.prototype.toJSON deleted from the page, it round-trips options and responses. The runtime suite repeats one sign-in with those three removed via page.addInitScript. Restore the complete property descriptors afterwards.
  • Android support: with getClientCapabilities deleted, capability detection falls back to the two older static methods. With PublicKeyCredential absent, the passkey button and Add button are hidden and the password form still works. Unit-tested.
  • The PR records a mutation for the re-arm test: drop the re-arm call, watch the named test fail, restore.

Verification

bun run test packages/ui-react/tests/passkey-login-runtime.test.ts   # BRAIN_REQUIRE_CHROME=1
bun run test packages/ui-react/tests/passkeys.test.ts
bun run test
bun run api-report && git diff --exit-code api-report/ || true   # read the diff
bun run typecheck
bun run lint
bun run check:pack

Contract impact

  • This touches the integration contract, so it needs the contract label, a CONTRACT: commit prefix, and the doc updated in the same commit. The BrainApi passkey method signatures in the package API change their type source. Record it in docs/integration-contract/package-api.md as additive if the type test proves mutual assignability.
  • This changes a published package's behaviour, so it needs a changeset. It also changes @schlessera/brain-ui-react's dependencies, so load the release skill before landing and refresh the lockfile.

Activity

  1. added
    type: fix
    area: ui-react
    priority: p2
    agent-ready
    contract
    on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyarea: ui-reactcontractpriority: p2type: fix

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions