Skip to content

[M2.2c2-fix] Stop unauthenticated account lockout and key IPv6 by /64 - #97

Merged
samuelmbabhazi merged 1 commit into
mainfrom
fix/m2.2-throttle-lockout
Nov 5, 2026
Merged

samuelmbabhazi merged 1 commit into
mainfrom
fix/m2.2-throttle-lockout

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

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

  • Lint, TS tests pass locally
  • Tests added, including the lockout scenario
  • No new shell invocation and no new secret exposure path
  • Audit events unchanged
  • SPEC and THREAT_MODEL updated
  • CI green (blocked by billing)

@samuelmbabhazi
samuelmbabhazi force-pushed the fix/m2.2-throttle-lockout branch from bed32ad to 9e3b132 Compare November 5, 2026 13:54
@samuelmbabhazi
samuelmbabhazi merged commit 341410c into main Nov 5, 2026
2 of 11 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the fix/m2.2-throttle-lockout branch November 5, 2026 13:54
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)
@samuelmbabhazi samuelmbabhazi mentioned this pull request Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant