M1-audit: Redis OTP store ships the non-atomic verify race on the production path #89
Labels
No labels
epic
phase-0
phase-1
phase-2
phase-3
phase-4
phase-5
phase-6
phase-7
phase-8
phase-9
priority/P0
priority/P1
priority/P2
type/backend
type/client
type/docs
type/ops
type/security
type/spike
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
primatekuntech/failsulit#89
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
B-6 (#37) fixed OTP atomicity for InMemoryOtpStore only; RedisOtpStore.ConsumeAttemptAsync (OtpService.cs:135-159) is still get→compare→remove — and Redis is what Program.cs tells production to configure. The deferral was documented (→ M2 Redis hardening); this audit ESCALATES it: the production path carries the exact session-minting race #37 fixed elsewhere.
Trigger: double-fired verify with the same valid code (Redis) → two sessions; attempt counting also undercounts.
Fix: Lua INCR/compare/DEL via the registered IConnectionMultiplexer. Escalate from M2 to M1.5 first-tasks.
RE-SCOPED per ADR-011 (Postgres-only server state, adopted into M2 scope 2026-11-08 — docs/redesign 02-architecture.md §17, dev plan v1.8 task 2.9): the fix is no longer 'make the Redis OTP store atomic with INCR/Lua' — the Redis OTP store is being REMOVED. New fix shape: a PostgresOtpStore whose consume is a single atomic statement (UPDATE otp_codes SET attempts = attempts + 1 WHERE key = @k AND code = @code AND attempts < @max AND expires_at > now() RETURNING ...) — race closed by the database, transactional with everything else, no Lua, no second consistency story. The IOtpStore seam stays. RedisOtpStore + its fixtures are removed with the compose service in the same slice. Same acceptance intent, better shape: the non-atomic production path ceases to exist rather than being patched.
CLOSED by PR #122 (squash-merged as
b5e90e3; PR runs api-ci 12005 + security-ci 12006 green; coverage 87.57%). Per the ADR-011 re-scope: PostgresOtpStore now owns OTP persistence — the consume is a single-statement atomic conditional DELETE (two concurrent correct codes cannot both pass), the attempt bump is a single conditional UPDATE capped at maxAttempts, and lock-burn/expiry-sweep are conditional DELETEs. The non-atomic RedisOtpStore production path was DELETED, not patched. Same SQL runs on the SQLite test harness and production Postgres (no dual-store test surface). 7 new invariant tests in PostgresOtpStoreTests; suite 939/0/39 Release+Debug. Slice 1 of umbrella #120.