Skip to content

fix(auth): rate limit passkey sign-in and magic link polling, refuse revoked OAuth sign-ins - #643

Open
Bccorb wants to merge 2 commits into
mainfrom
fix/sign-in-flow-limits
Open

Bccorb wants to merge 2 commits into
mainfrom
fix/sign-in-flow-limits

Conversation

@Bccorb

@Bccorb Bccorb commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Part of #600 (L-API-7, L-API-8).

L-API-7: flow limits on passkey sign-in and magic link polling

  • POST /webauthn/login/start and POST /webauthn/login/finish (webauthnLoginIdentityLimiter, webauthnLoginIpLimiter):
    • 10 per attempt per window.
    • Per address: ten times flow_rate_limits.otp.perIp, which is 100 by default. A deployment that raised the OTP per-address limit for carrier NAT or an office gets a matching rise here.
  • GET /magic-link/check (magicLinkCheckLimiter): 300 per attempt per window. The client polls every five seconds over the fifteen-minute life of a link, which is 180 checks.
  • No limit spans an account's attempts. A pre-auth token comes from an email address alone, so a stranger could spend an account-wide cap and block the owner's sign-in.
  • The window is flow_rate_limits.windowSeconds. The per-attempt allowances are fixed, because a new flow_rate_limits key needs a types release.
  • Route middleware runs before the decoy switch in defineRoute, and the keys use the token's subject, so a decoy and a real account get the same answers.
  • Issuing a WebAuthn challenge now deletes that user's spent and expired challenge rows. Only live rows are ever read.
  • A login/start that matches no credential on the account, or arrives on a token with no attempt id, is recorded as webauthn_login_failed rather than login_failed, so it no longer counts toward lockout. The login_failed let anyone holding a pre-auth token lock the owner out by asking for a credential id the account does not have.

L-API-8: OAuth sign-in refuses revoked accounts

  • resolveOAuthUser checks users.revoked on every path that returns an existing account (a linked identity, an imported user matched by external id, or an email match). It throws OAuthAccountRevokedError before any claim or link.
  • The callback answers 403 login_method_disabled, the same answer it gives other accounts that may not use the method, and logs oauth_login_failed with the reason account_revoked.

Contract

  • New 429 answers on the three limited routes, with the existing TOO_MANY_REQUESTS_BODY, as on every other flow limiter.
  • The OAuth callback can now answer 403 login_method_disabled for a revoked account. That status and body were already in its schema.
  • The audit event type for a refused passkey start changes from login_failed to webauthn_login_failed. It now counts toward sign-in failure metrics as a passkey failure rather than as a generic login failure.
  • openapi.json and src/generated/api.ts are regenerated for the updated OAuth callback description.

Tests

  • tests/integration/rateLimit/identityFlowLimits.spec.ts: per-attempt allowances, a stranger's attempts not reaching the owner's, the address fallback, and the address cap following otp.perIp.
  • tests/unit/services/webauthnChallengeService.spec.ts: challenge collection before issue.
  • tests/integration/webauthn/webauthn.spec.ts: a refused start is not a lockout failure.
  • tests/integration/oauth/oauth.spec.ts: revoked accounts are refused on the email-match and linked-identity paths, before claiming or linking.

…revoked OAuth sign-ins

Passkey login start and finish and the magic link check had only the global
limiter. Login start also left a challenge row behind on every call and
recorded a lockout-counting login_failed for a credential id the account does
not have. OAuth sign-in never checked users.revoked.
…ess cap

A cap across an account's attempts let a stranger with pre-auth tokens from the
owner's address block the owner's passkey sign-in. The limits are now per
attempt, with a per-address cap derived from flow_rate_limits.otp.perIp so a
deployment that raised it for shared addresses raises this with it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant