fix(api-auth): M8 audit batch 2 — email_verified fail-closed, wallet replay bound, OIDC replay gaps (#214) #217

Merged
amiryahaya merged 1 commit from fix/m8-api-auth into main 2026-11-17 13:38:17 +01:00
Owner

M8-close audit remediation batch 2 (#214 findings M8-2, M8-17, M8-18a/b/c).

M8-2 (account takeover): OidcTokenValidator treated a MISSING email_verified claim as verified (!= "false"); IDA-09 requires reject-unless-true. Validator now fails closed; OidcCallback and OidcVerify reject unverified emails uniformly (audit event + 401) before email auto-linking; provisioning carries the real claim. FakeIdpServer mirrors real providers (always emits email_verified + iat).

M8-17 (replay + lockout amplifier): PostgresSessionStore gains a per-account session cap (Ssdid:Sessions:MaxPerAccount, default 10) with newest-wins eviction — a replay loop can no longer ride the GLOBAL MaxSessions cap into a platform-wide 503, and the real user's next login evicts an attacker's oldest session. Residual (documented): the frozen wallet VC does not sign the login challenge — challenge-bound signing lands with the wallet-flow rework.

M8-18a: ConsumeChallenge deletes conditioned on the stored challenge value and requires the affected-row count — two concurrent consumers can no longer both win.

M8-18b: /oidc/verify rejects id_tokens with iat older than 5 minutes (leaked-token replay bound; no client change needed). OidcClaims gains IssuedAt (parsed from iat).

M8-18c: the PKCE verifier no longer rides the signed state through the browser (authorize redirect → callback carried verifier + code in clear to an interceptor). It is stored server-side in SessionChallenges keyed by the state nonce and consumed atomically at the callback; both authorize endpoints store it before redirecting; ChallengeTtlMinutes raised to 10 to match the state TTL.

Tests: OidcVerifyInvariants +2 (unverified rejected, stale rejected); BootstrapGateTests remain green; full suite 1084 green + coverage gate 87.61% ≥ 80% in Release.

Part of the M8-close FIX-ALL (umbrella #215, audit #214).

M8-close audit remediation batch 2 (#214 findings M8-2, M8-17, M8-18a/b/c). **M8-2 (account takeover)**: OidcTokenValidator treated a MISSING email_verified claim as verified (`!= "false"`); IDA-09 requires reject-unless-true. Validator now fails closed; OidcCallback and OidcVerify reject unverified emails uniformly (audit event + 401) before email auto-linking; provisioning carries the real claim. FakeIdpServer mirrors real providers (always emits email_verified + iat). **M8-17 (replay + lockout amplifier)**: PostgresSessionStore gains a per-account session cap (`Ssdid:Sessions:MaxPerAccount`, default 10) with newest-wins eviction — a replay loop can no longer ride the GLOBAL MaxSessions cap into a platform-wide 503, and the real user's next login evicts an attacker's oldest session. Residual (documented): the frozen wallet VC does not sign the login challenge — challenge-bound signing lands with the wallet-flow rework. **M8-18a**: ConsumeChallenge deletes conditioned on the stored challenge value and requires the affected-row count — two concurrent consumers can no longer both win. **M8-18b**: /oidc/verify rejects id_tokens with iat older than 5 minutes (leaked-token replay bound; no client change needed). OidcClaims gains IssuedAt (parsed from iat). **M8-18c**: the PKCE verifier no longer rides the signed state through the browser (authorize redirect → callback carried verifier + code in clear to an interceptor). It is stored server-side in SessionChallenges keyed by the state nonce and consumed atomically at the callback; both authorize endpoints store it before redirecting; ChallengeTtlMinutes raised to 10 to match the state TTL. Tests: OidcVerifyInvariants +2 (unverified rejected, stale rejected); BootstrapGateTests remain green; full suite 1084 green + coverage gate 87.61% ≥ 80% in Release. Part of the M8-close FIX-ALL (umbrella #215, audit #214).
fix(api-auth): M8 audit batch 2 — email_verified fail-closed, wallet replay bound, OIDC replay gaps (#214)
All checks were successful
Security CI / security-scan (pull_request) Successful in 3m7s
API CI / migrations (pull_request) Successful in 3m47s
API CI / build-and-test (pull_request) Successful in 14m11s
d348cd1be9
M8-2: OidcTokenValidator treated a MISSING email_verified claim as
verified (!= "false") — IDA-09 says reject unless explicitly true. The
validator now fails closed, OidcCallback and OidcVerify reject
unverified emails uniformly (audit + 401, mirroring IdpCallback), and
provisioning carries the real claim instead of a hardcoded true. The
fake IdP test server now always emits email_verified=true, mirroring
real providers (Google/Microsoft always include it).

M8-17: PostgresSessionStore gains a per-account session cap (default 10,
Sessions:MaxPerAccount) with newest-wins eviction — a replay loop can no
longer ride the GLOBAL MaxSessions cap into a platform-wide 503 lockout,
and the real user's next login evicts an attacker's oldest session.
Residual: the frozen wallet VC does not sign the login challenge —
documented; challenge-bound signing lands with the wallet-flow rework.

M8-18a: ConsumeChallenge now deletes conditioned on the stored challenge
value and requires the affected-row count — two concurrent consumers can
no longer both win.

M8-18b: /oidc/verify (direct id_token surface, no nonce protocol)
rejects tokens with iat older than 5 minutes — a leaked token can no
longer mint sessions for its whole 1-hour life. OidcClaims gains
IssuedAt (parsed from iat).

M8-18c: the PKCE verifier no longer rides the signed state through the
browser (authorize redirect → callback carried verifier + code in
_clear_ for an interceptor). It is stored server-side in SessionChallenges
keyed by the state nonce and consumed atomically at the callback;
ChallengeTtl raised to 10 min in appsettings to match the state TTL.

Full server suite: 1085 green.
Sign in to join this conversation.
No description provided.