M1-audit: Redis OTP store ships the non-atomic verify race on the production path #89

Closed
opened 2026-11-07 08:40:54 +01:00 by amiryahaya · 2 comments
Owner

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.

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.
Author
Owner

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.

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.
Author
Owner

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.

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.
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
primatekuntech/failsulit#89
No description provided.