fix(identity): M2 identity-surface P1 batch — TOTP enumeration, register/verify ordering, decrypt 401s, wallet admin MFA (#110 items 4/5/7/8) #114

Merged
amiryahaya merged 1 commit from fix/identity-p1-batch into main 2026-11-08 05:09:24 +01:00
Owner

M2 identity-surface P1 batch from the M1.5 close audit (#110, umbrella #101). Four fixes:

A — TOTP verify enumeration closed (TotpVerify.cs): unknown email / known-without-TOTP / known-with-TOTP now produce indistinguishable 401s (was: 400 'TOTP is not set up' censused accounts + mapped TOTP enrollment).

B — EmailRegisterVerify hardened: invitation validated BEFORE the OTP consumption (a wrong invitation no longer burns the victim's pending code — each burn was an unthrottled, unaudited kill of their onboarding; the response flipped 401→404 when a guess landed, confirming the code). Plus RequireRateLimiting('auth-otp') — it was the only public verify endpoint with no partition.

C — TOTP decrypt exceptions degrade to 401 + audit (security.totp_decrypt_failed): corrupt/rotated encryption material was an unhandled 500 = silent TOTP-population lockout with zero telemetry.

D — wallet sign-in applies the admin MFA gate (Authenticate.cs): a TOTP-enabled admin signing in via wallet now mints an mfa-pending session, never a full one — mirroring OidcVerify/OidcCallback.

Verification

TDD: 5 tests first — RED ×3 (enumeration, decrypt 500, OTP burn; 2 passed as controls). One pre-existing test updated (SameCodeSecondTime now expects any 4xx on replay — invitation state surfaces pre-OTP by design).

Suite 919 / 0 failed / 39 skipped (Release ×2 + Debug) · coverage gate 86.38% ≥ 80

M2 identity-surface P1 batch from the M1.5 close audit (#110, umbrella #101). Four fixes: **A — TOTP verify enumeration closed** (TotpVerify.cs): unknown email / known-without-TOTP / known-with-TOTP now produce indistinguishable 401s (was: 400 'TOTP is not set up' censused accounts + mapped TOTP enrollment). **B — EmailRegisterVerify hardened**: invitation validated BEFORE the OTP consumption (a wrong invitation no longer burns the victim's pending code — each burn was an unthrottled, unaudited kill of their onboarding; the response flipped 401→404 when a guess landed, confirming the code). Plus RequireRateLimiting('auth-otp') — it was the only public verify endpoint with no partition. **C — TOTP decrypt exceptions degrade to 401 + audit** (security.totp_decrypt_failed): corrupt/rotated encryption material was an unhandled 500 = silent TOTP-population lockout with zero telemetry. **D — wallet sign-in applies the admin MFA gate** (Authenticate.cs): a TOTP-enabled admin signing in via wallet now mints an mfa-pending session, never a full one — mirroring OidcVerify/OidcCallback. ## Verification TDD: 5 tests first — **RED ×3** (enumeration, decrypt 500, OTP burn; 2 passed as controls). One pre-existing test updated (SameCodeSecondTime now expects any 4xx on replay — invitation state surfaces pre-OTP by design). Suite **919 / 0 failed / 39 skipped** (Release ×2 + Debug) · coverage gate **86.38% ≥ 80**
fix(identity): M2 identity-surface P1 batch — TOTP enumeration, register/verify ordering + limiter, decrypt 401s, wallet admin MFA gate (#110 items 4/5/7/8 + #104 follow-up)
All checks were successful
Security CI / security-scan (pull_request) Successful in 2m47s
API CI / build-and-test (pull_request) Successful in 3m54s
60eeb0803b
A — TOTP verify enumeration closed (TotpVerify.cs:40-44): unknown email,
known-without-TOTP, and known-with-TOTP now produce indistinguishable
401s (was: 400 'TOTP is not set up' censused accounts + mapped TOTP
enrollment for phishing targets). Test asserts stable fields only
(trace_id is per-request).

B — EmailRegisterVerify hardened (EmailRegisterVerify.cs):
- RequireRateLimiting('auth-otp') added — it was the only public verify
  endpoint with no partition
- invitation validated BEFORE the OTP consumption — a wrong invitation
  no longer burns the victim's pending code (each burn was an
  unthrottled, unaudited kill of their onboarding; response flipped
  401→404 the moment a guess landed, confirming the code)
- Existing SameCodeSecondTime test updated: a spent invitation now
  surfaces as 404 pre-OTP — either way reuse fails, seat not granted

C — TOTP decrypt/backup-code exceptions degrade to 401 + audit
(security.totp_decrypt_failed) instead of unhandled 500: a rotated/
corrupt encryption key was a silent TOTP-population lockout with no
telemetry.

D — wallet sign-in applies the admin MFA gate (Authenticate.cs): a
TOTP-enabled admin signing in via wallet now mints an mfa-pending
session (never a full one), mirroring OidcVerify/OidcCallback. Wallet
authenticate response gains mfa_required.

Also: Authenticate handler takes ISessionStore for the mfa session mint.

TDD: 5 tests first — RED ×3 (enumeration, decrypt 500, OTP burn) + 2
passed naturally (membership-count control). Suite 919 / 0 failed / 39
skipped (Release ×2 + Debug); gate 86.38% ≥ 80.
Sign in to join this conversation.
No description provided.