[M-9] TOCTOU races: duplicate concurrent issuance per IC, rate-limiter undercounting, duplicate client_id rows crash auth #21

Closed
opened 2026-11-14 18:28:50 +01:00 by amiryahaya · 0 comments
Owner

Finding

Check-then-act without transactions: two concurrent enrollments for the same IC both pass 'no active cert' and both issue; rate-limiter find→mutate→save lets concurrent failures undercount (and duplicate identifier rows make {:ok, [attempt | _]} read an arbitrary one); client_id has no unique constraint and singleton-list matching raises MatchError on duplicates.

Evidence

  • lib/mdid_ws/cert_management/enrollment.ex:93-97 → 53 (check vs save)
  • lib/mdid_ws/auth/rate_limiter.ex:55-104
  • lib/mdid_ws/oauth/client_credentials.ex:7 — {:ok, [client]} singleton match

Impact

Duplicate active certificates per IC; lockout threshold effectively exceeded; 500s on token requests.

Fix

  • Wrap rate-limiter record/check in one Mnesia transaction
  • Serialize enrollment per-IC (Registry/:global lock or transaction covering check+write)
  • Unique constraint (or dedup migration) on client_id

Line numbers refer to the initial import commit 282cb11. Source: comprehensive audit, 2026-11-12 (first review of this codebase).

## Finding Check-then-act without transactions: two concurrent enrollments for the same IC both pass 'no active cert' and both issue; rate-limiter find→mutate→save lets concurrent failures undercount (and duplicate identifier rows make `{:ok, [attempt | _]}` read an arbitrary one); `client_id` has no unique constraint and singleton-list matching raises MatchError on duplicates. ## Evidence - `lib/mdid_ws/cert_management/enrollment.ex:93-97 → 53` (check vs save) - `lib/mdid_ws/auth/rate_limiter.ex:55-104` - `lib/mdid_ws/oauth/client_credentials.ex:7` — `{:ok, [client]}` singleton match ## Impact Duplicate active certificates per IC; lockout threshold effectively exceeded; 500s on token requests. ## Fix - [ ] Wrap rate-limiter record/check in one Mnesia transaction - [ ] Serialize enrollment per-IC (Registry/:global lock or transaction covering check+write) - [ ] Unique constraint (or dedup migration) on client_id _Line numbers refer to the initial import commit `282cb11`. Source: comprehensive audit, 2026-11-12 (first review of this codebase)._
Sign in to join this conversation.
No description provided.