Repository navigation
[M2.2c1] Add audited account and session flows - #44
Merged
Merged
Conversation
6 tasks done
samuelmbabhazi
force-pushed
the
feat/m2.2b3-identity-store
branch
3 times, most recently
from
November 5, 2026 12:13
2a98306 to
6432448
Compare
samuelmbabhazi
changed the base branch from
feat/m2.2b3-identity-store
to
main
November 5, 2026 12:13
samuelmbabhazi
force-pushed
the
feat/m2.2c1-identity-commands
branch
from
November 5, 2026 12:14
8384abf to
426973c
Compare
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 5, 2026
## 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 - Workspace lint, types and TypeScript tests pass. - Thirty PostgreSQL integration tests pass, including five limiter tests for concurrent workers, exact delay/window boundaries, 100 distinct-account attempts from one IP, email quotas and scope isolation. - SQL remains parameterized; database failures become opaque availability errors. ## 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 - [x] M2.2c2 acceptance checked; HTTP integration remains open - [x] Lint, types and tests pass - [x] Real concurrency and quota-boundary tests added - [x] No shell invocation or plaintext secret persistence - [x] Telemetry only; account commands remain audited - [x] SPEC and threat model updated
5 of 6 tasks
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 5, 2026
…#101) ## Task Review follow-up for #44 (M2.2c1). Refs #21 ## What changed **API** - `POST /auth/verify` takes `{ token, password }` (`VerifyEmailDto`). Verification checks the password against the stored hash, with Argon2id work outside any lock or transaction. Under the user lock it then rechecks that the hash did not change in the meantime, before consuming the link and activating the account. - A wrong password does not consume the verification link. - Password reset (request and confirm) accepts pending accounts as well as active ones. A reset on a pending account activates it (`identity.email_verified` then `identity.password_reset`), invalidates outstanding verification links, and advances the security version as before. - `openapi.json` and the api-client regenerated. **Web** - The verification page asks for "Password you chose when signing up" (`autocomplete=current-password`) and links to password reset for people who did not create the account or forgot the password. **Docs and tests** - SPEC 8.1 and a new THREAT_MODEL row (S4) describe the defence. - New integration test for the full attack: an attacker registers the owner's address with their own password. The owner cannot activate that password with the link, claims the account through reset, and afterwards the attacker's password and verification link are both rejected. - New integration test: a wrong password does not consume the link. - Existing unit, integration and browser flows now send the password with the code. ## Why Account pre-hijacking: 1. An attacker registers `[email protected]` with their own password. The account stays pending and the verification link goes to the victim. 2. A later signup by the victim was silently ignored, and reset refused pending accounts. 3. The victim clicked the link, which activated the attacker's password. 4. The attacker could then log in, enroll MFA and create API tokens. Enrolling MFA would lock the owner out even after a reset. ## How it was tested - `nx run-many -t lint typecheck test build -p web api` in a clean worktree: 12 tasks pass. - `pnpm gen:openapi` and `pnpm gen:api-client`: the committed output is the regenerated output. - Integration and browser 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 - Contract change on `POST /auth/verify`: the password is now required. Only the bundled web UI calls this endpoint, and it is updated in this PR. - The verify endpoint keeps its `verify` attempt limit (per network and account after #97). No new enumeration signal: every failure returns the same 401. ## Checklist - [x] Lint, typecheck, tests and build pass locally - [x] Malicious-scenario integration test added - [x] No new shell invocation and no new secret exposure path - [x] Audit events emitted for the new activation path - [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.2c1, part of #21. Depends on #43; base
feat/m2.2b3-identity-store.What changed and why
Add account and session commands behind application ports. Signup preserves existing credentials, verification/reset credentials are single-use, login rotates the presented session, and password reset invalidates all older sessions and reset links. Password proof is checked again against the user's security version under a row lock to prevent a concurrent reset from authorizing a stale login.
Every command mutation publishes an identity event in the same database transaction. Session authentication verifies account status, security version, idle/absolute expiry and a session-bound CSRF hash using a timing-safe comparison. SMTP delivery, request limits, public HTTP endpoints and MFA are intentionally separate remaining plan items; these commands are not exposed over HTTP in this PR.
Validation
Security considerations
Credential values remain wrapped until hashing, storage or the mail port. Password hashing and mail delivery occur outside database transactions. A mail delivery failure leaves an unverified account eligible for the explicit resend flow; it grants no session. Request throttling and production delivery must land before exposing the commands publicly. No new shell invocation or agent action is introduced.
Checklist