Repository navigation
Description
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:
- Unmount does not abort.
loginWithPasskeyandregisterPasskeychecksignalonly between steps (passkeys.ts:39-47,52-57).navigator.credentials.get/createreceives the library's own singleton signal, not ours. A pending conditionalget()therefore outlives the login screen's effect cleanup (login-screen.tsx:110), and leaving the Security tab does not cancel an open registration prompt. - 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 conditionalcatchtreats thatAbortErroras 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. Guidesecurity/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"). - A Proxy hack. To start the sign-in guard only once the user has picked a credential, the screen wraps
apiin aProxythat interceptspasskeyLoginVerify(login-screen.tsx:90-97). - Weak capability detection and error mapping.
browserSupportsWebAuthn()is the only gate (passkey-tab.tsx:39, consumed bypasskey-list.tsx:43). A duplicate registration (InvalidStateErrorfromexcludeCredentials,packages/ui-server/src/middleware/passkeys.ts:485-488) surfaces as the raw library message. Guidesecurity/passkey-registrationlists "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.tson native APIs. UsePublicKeyCredential.parseRequestOptionsFromJSON/parseCreationOptionsFromJSON,navigator.credentials.get/create({ publicKey, signal, mediation? })andcredential.toJSON(). The caller'sAbortSignalgoes straight intoget/create. - Fallback when the parse methods or
toJSONare 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 usesPublicKeyCredential.getClientCapabilities()(conditionalGet,passkeyPlatformAuthenticator). Where that method is missing, it falls back toisConditionalMediationAvailable()andisUserVerifyingPlatformAuthenticatorAvailable(). WherePublicKeyCredentialitself is missing, everything is false. - In
LoginScreen:- Give the conditional request its own
AbortController. - The button flow aborts it before its own
get(). After aNotAllowedError/AbortErrorcancel or a failed button ceremony, it re-arms conditional UI. Keep the gate from ui-react: a passkey-only login screen starts conditional UI with no autofill field and burns the options rate limit #2555: conditional UI runs only while awebauthninput is rendered. - Effect cleanup aborts both controllers.
- Replace the Proxy with an explicit hook, e.g.
loginWithPasskey(api, { signal, conditional, onSelected }), called afterget()resolves and before verify.
- Give the conditional request its own
- In
PasskeyTab/PasskeyList:- Gate the Add button on
capabilities.webauthn. Keep security keys and hybrid allowed: the management flow omitsauthenticatorAttachment, per guidesecurity/passkey-registration§6. - Map
InvalidStateErrorto "This device already has a passkey for this site." - Abort an open registration when the tab's lifetime ends.
- Gate the Add button on
- Retype the four
BrainApipasskey methods with the DOM lib JSON types. Remove@simplewebauthn/browserfrompackages/ui-react/package.jsonand the lockfile. Regenerateapi-report/.
Out of scope
@simplewebauthn/serverand every server route. The server must verify the nativetoJSON()output unchanged.- Signal API calls (ui-react: deleted and unknown passkeys are never signalled to the credential manager #2559), the post-login passkey offer (ui-react: offer an explicit platform passkey after a password sign-in #2563), Immediate UI mode (
uiMode: 'immediate'; guidesecurity/quick-sign-insrules it out for a dedicated sign-in page), and conditional create. - Adding a polyfill package, including the
webauthn-polyfillsthe guides suggest. - Visual changes to the login screen or the Security tab.
Acceptance criteria
-
packages/ui-reacthas no import of@simplewebauthn/browser. It is gone frompackage.jsonandbun.lock, andapi-report/ui-react.txtno longer mentions it. - A type test (
*.test-d.ts, likepackages/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 fourBrainApipasskey methods. If they are not, stop: the change is breaking, and needs thebreakinglabel 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
getre-armed). Fails before the change. - Unmounting the login screen while a conditional
getis pending aborts it: the pending request rejects withAbortError, 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
InvalidStateErrormessage.
- 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
- A unit test runs the fallback codec: with
parseRequestOptionsFromJSON,parseCreationOptionsFromJSONandPublicKeyCredential.prototype.toJSONdeleted from the page, it round-trips options and responses. The runtime suite repeats one sign-in with those three removed viapage.addInitScript. Restore the complete property descriptors afterwards. - Android support: with
getClientCapabilitiesdeleted, capability detection falls back to the two older static methods. WithPublicKeyCredentialabsent, 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:packContract impact
- This touches the integration contract, so it needs the
contractlabel, aCONTRACT:commit prefix, and the doc updated in the same commit. TheBrainApipasskey method signatures in the package API change their type source. Record it indocs/integration-contract/package-api.mdas 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 thereleaseskill before landing and refresh the lockfile.
Activity