Repository navigation
[M2.2c2] Enforce shared authentication attempt limits - #45
Merged
Merged
Conversation
6 tasks done
samuelmbabhazi
force-pushed
the
feat/m2.2c1-identity-commands
branch
from
November 5, 2026 12:14
8384abf to
426973c
Compare
samuelmbabhazi
changed the base branch from
feat/m2.2c1-identity-commands
to
main
November 5, 2026 12:14
samuelmbabhazi
force-pushed
the
feat/m2.2c2-auth-throttling
branch
from
November 5, 2026 12:15
bef50e9 to
2a43b7b
Compare
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 5, 2026
## Task M2.2c3a, part of #21. Depends on #45; base `feat/m2.2c2-auth-throttling`. ## What changed and why Enqueue identity emails atomically with account/credential/audit changes using pg-boss and its upstream Prisma transaction adapter. Email addresses, credentials and expiration are envelope-encrypted with authenticated data tied to the job id. A separate worker retries delivery up to five times with capped backoff, skips expired credentials and sanitizes every persisted worker error. Add the pg-boss lifecycle owner with bounded database connections and graceful shutdown. The MIT-licensed dependency is pinned to 12.38.0 and implements the queue already chosen in ADR 0004. Production SMTP wiring follows in M2.2c3b; no endpoint is exposed by this PR. ## Validation - Thirty-four real PostgreSQL integration tests pass. - Four queue tests cover transaction rollback, ciphertext-only persistence, restart delivery, transport failures and retries, opaque persisted errors, expired credentials and tampered ciphertext. - Workspace lint, types and builds pass; existing account, limiter, repository, schema, audit and fleet integration suites pass. ## Security considerations Queue and schema names are fixed. The upstream Prisma adapter executes pg-boss SQL with separately bound values inside the current transaction; request values never form SQL identifiers or query text. Only ciphertext reaches queue tables. Worker exceptions omit transport responses and validation details. Plaintext buffers are cleared after encryption/decryption. SMTP transport is an injected port, exercised separately in the next PR. ## Checklist - [x] M2.2c3a acceptance checked; SMTP and HTTP flows remain open - [x] Lint, types, builds and PostgreSQL integration tests pass - [x] Restart, rollback, tampering and secret-disclosure tests added - [x] No shell invocation or plaintext job persistence - [x] Delivery enqueue joins command/audit transactions - [x] Architecture and threat model updated
5 of 6 tasks
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 5, 2026
…#97) ## Task Review follow-up for #45 (M2.2c2). Refs #21 ## What changed - Throttling now has three axes per operation: client network, subject, and subject from one client network (`source`). - Credential proofs (login, verify, reset, MFA, token): - The hard cap of 10 per 15 min moves from the subject to subject + network. - The subject alone keeps the progressive delay, now capped at 8 s, and has no hard cap. - The subject + network axis keeps the delay up to 64 s. - Signup and email delivery keep their per-subject cap of 5 per hour on purpose, to prevent mailbox flooding. - IPv6 clients are keyed by their /64 and IPv4-mapped addresses by their IPv4, for both the network and the source axes (`clientNetwork`). - `succeeded(subject, ip)` clears the account delay and that network's account quota after a successful login. - When admitted, the decision returned is the one with the fewest remaining requests. - SPEC and THREAT_MODEL updated. ## Why Anyone could lock any known account out. About 10 failed logins every 15 minutes, from any address, kept the per-account bucket exhausted, so the real owner got 429 indefinitely. A single IPv6 /64 also gave an attacker effectively unlimited per-IP quota. ## How it was tested - Unit tests: policy per axis (including the bounded global delay) and `clientNetwork` (IPv4, mapped, compressed IPv6, zone ids, non-addresses). - Integration tests (`identity-throttle.integration.spec.ts`): - existing cases adjusted; - an attacker exhausting their quota from one network does not stop the owner from another network 8 s later; - rotating addresses inside one /64 shares one quota. - `nx run-many -t lint typecheck test -p api` in a clean worktree: all pass. Integration tests could not run locally (no Docker in the sandbox), and GitHub Actions is blocked by the account spending limit. CI must pass before merge. ## Security considerations Trade-off: a distributed guesser is no longer hard-capped per account. Each network gets at most 10 tries per 15 minutes per account and every attempt on the account is spaced by up to 8 s, which still bounds online guessing against Argon2id-hashed passwords. This follows OWASP guidance to avoid hard lockouts. ## Checklist - [x] Lint, TS tests pass locally - [x] Tests added, including the lockout scenario - [x] No new shell invocation and no new secret exposure path - [x] Audit events unchanged - [x] SPEC and THREAT_MODEL updated - [ ] CI green (blocked by billing)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Task
M2.2c2, part of #21. Depends on #44; base
feat/m2.2c1-identity-commands.What changed and why
Add PostgreSQL-backed authentication attempt reservations with independent IP and subject quotas. Atomic upserts enforce progressive credential delays across API instances; rejected retries do not extend the block. Successful login clears only its subject bucket, while IP quotas remain effective against account cycling. Expired rows are removed in bounded, non-blocking batches and persisted keys are hashes.
The port returns quota/reset/retry metadata for the HTTP layer, which follows in M2.2c4. This PR does not yet expose account commands publicly.
Validation
Security considerations
Delays reserve the next credential attempt before expensive hashing, so simultaneous requests cannot all pass before a failed-proof counter is updated. Session/login success cannot erase IP abuse history. Counters are security telemetry and carry no password, bearer token, email or IP plaintext. HTTP callers must normalize subjects and use trusted client-IP derivation.
Checklist