Publish a union for the WebAuthn error codes - #52
Merged
Conversation
Closes #51 The auth API returns machine-readable codes as the whole of an error body's error field on the WebAuthn endpoints, and this package did not publish them, so every consumer redeclared the list and no consumer found out when the API added one. OAUTH_ERROR_CODES already solves this for the OAuth surface, and the React SDK leans on it: a local Record<OAuthErrorCode, true> stops compiling when the upstream union changes. The WebAuthn codes had no such union, so the equivalent SDK helper declared its own and its membership map only checked itself. That is the same silent drift that let the API's authenticator_policy default fall behind this package's schema twice. One union covers all five rather than a narrower one for the registration policy refusals. A consumer asks a single question, is this a code I know, and the grouping does not have to be revisited when a code is added on a different endpoint. It does put a client bug, prf_output_not_allowed, next to deployment policy refusals, which are different in kind, and a consumer that cares about that distinction can still narrow further. The prose failures are deliberately absent rather than forgotten, and the code says so.
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.
Closes #51.
Publishes
WEBAUTHN_ERROR_CODES,WebAuthnErrorCodeSchemaandWebAuthnErrorCodefor the machine-readable codes the auth API returns as thewhole of an error body's
errorfield:attachment_not_allowedGET /webauthn/register/startsynced_passkey_not_allowedPOST /webauthn/register/finishauthenticator_not_allowedPOST /webauthn/register/finishprf_requiredPOST /webauthn/register/finishprf_output_not_allowedPOST /webauthn/login/finishEnumerated by reading
src/controllers/webauthn.tsandsrc/services/authenticatorPolicyService.tsinseamless-auth-api, not frommemory. Every other failure on those endpoints answers with prose
(
Not allowed,Missing challenge,Registration failed verification), so theyare deliberately absent, and the code comment says so rather than leaving the
next reader to wonder.
Why
This mirrors
OAUTH_ERROR_CODESand exists for the same reason. A consumer thatdeclares its own copy has no way to find out when the API adds a code: it
degrades to generic messaging and nothing fails anywhere.
The React SDK already relies on the OAuth version working this way:
That map stops compiling when the upstream union changes. Its WebAuthn
counterpart (fells-code/seamless-auth-react#133) had to declare a local union, so
its map only checks itself. This is the same class of silent drift that let the
API's
authenticator_policydefault fall behind this package's schema twice inrecent releases.
One decision worth reviewing
One union covers all five codes rather than a narrower one for the registration
policy refusals only.
For: a consumer asks a single question, "is this a code I know", and the grouping
does not need revisiting when a code is added on a different endpoint.
Against: it puts a client bug (
prf_output_not_allowed, which means the clientsent PRF output it should never have transmitted) next to deployment policy
refusals, which are a different kind of thing. A consumer that cares can still
narrow further on top of this union.
I went with the single union. Happy to split it if you would rather the type
carried that distinction.
Tests
Three cases in
src/schemas/webauthn/schema.test.ts: every published codeparses, an unpublished one throws, and a
Record<WebAuthnErrorCode, true>iscompared against the list so the union and the array cannot drift from each
other. That last one is the property that makes the consumer-side check
meaningful, so it is worth asserting here rather than assuming.
Checks
npm run typecheck,npm run lint,npm run format:checkandnpm testallpass (211 tests).
npm run buildsucceeds and the symbols are present indist/schemas/webauthn/schema.d.ts.Ripple
Additive, so a minor bump, and nothing changes for a consumer that does not
import it. Once released:
seamless-auth-apican dropAuthenticatorRefusalfromsrc/services/authenticatorPolicyService.tsand the bareprf_requiredliteral in
src/controllers/webauthn.tsseamless-auth-reactcan swap its local union for this one and restore thecompile-time exhaustiveness check, replacing the note in its AGENTS.md that
currently records the drift risk