Invalidate existing sessions on password change/reset (B-34)
Neither self-service password change nor the admin reset invalidated already-issued JWTs — a 24h-lifetime token stayed valid regardless, so a stolen token (or an attacker who already had the old password) kept working past a password change meant to lock them out. The admin reset exists precisely for the "account compromised" case and didn't evict the attacker at all. Add User.token_version (migration 943dbd74d983), embedded in every JWT as a "tv" claim and checked against the DB on every request in get_current_user/get_optional_user; a mismatch reads as session_expired. Both change-password and the admin reset bump it. change-password hands back a freshly minted token so the caller's own session keeps working instead of being logged out by its own request; the admin reset does not, since that session isn't the one making the call. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
16802cafb6
commit
739fc9fed2
12 files changed
+159
-36
No files matched your search
@@ -1,11 +1,11 @@
|
||||
# Known bugs
|
||||
|
||||
A second full-codebase audit on 2026-07-27 found **25 further issues** (4 critical, 6 high,
|
||||
7 medium, 8 low), listed below as B-33 … B-49. B-25 through B-33 are fixed (see "Previously
|
||||
fixed" below) — no Critical-severity finding remains open; the other 16 are High/Medium/Low.
|
||||
7 medium, 8 low), listed below as B-33 … B-49. B-25 through B-34 are fixed (see "Previously
|
||||
fixed" below) — no Critical-severity finding remains open; the other 15 are High/Medium/Low.
|
||||
The 139-test suite was green at the time of the audit, so none of these were caught by existing
|
||||
coverage — every fix lands with a regression test (the nine fixes so far brought the suite
|
||||
from 139 to 192).
|
||||
coverage — every fix lands with a regression test (the ten fixes so far brought the suite
|
||||
from 139 to 194).
|
||||
|
||||
The recurring pattern across the open findings is worth stating once: the code is rigorous
|
||||
about the failure modes that have actually been hit, and silent about the ones that have not.
|
||||
@@ -18,21 +18,6 @@ single-process assumptions, no user-facing history, etc.), see "Known gaps / TOD
|
||||
|
||||
---
|
||||
|
||||
## High
|
||||
|
||||
### B-34 — Password change and admin reset do not invalidate existing sessions
|
||||
|
||||
Neither `/users/me/change-password` nor `/admin/users/{id}/reset-password` invalidates
|
||||
already-issued JWTs (24h default lifetime, no revocation, no `token_version` on the user). The
|
||||
admin reset exists precisely for the "account compromised" case and **does not evict the
|
||||
attacker**.
|
||||
|
||||
**Proposed fix.** Add a `token_version` (or `password_changed_at`) column on `User`, embed it
|
||||
in the JWT claims, and reject any token whose value is stale in
|
||||
`auth/dependencies.py:get_current_user`. Bump it on both endpoints.
|
||||
|
||||
---
|
||||
|
||||
## Medium
|
||||
|
||||
### B-35 — Every API timestamp is naive, so the frontend renders it in the wrong timezone
|
||||
@@ -212,9 +197,10 @@ already does.
|
||||
- **B-31** — resubscribing on reconnect ran serially before anything else started, freezing the chain tip (and so an in-flight draw) for the whole sweep
|
||||
- **B-32** — an RBF bump's fee delta could fall below BIP125's relay-mandated minimum, so the node rejected it and the same tick retried identically forever; also had no ceiling on how high the fee rate could climb
|
||||
- **B-33** — `POST /auth/login` had no rate limiting on a custodial wallet, so a patient distributed attack could brute-force a password against an enumerable username list; fixed with per-username *and* per-IP exponential backoff (`app/auth/rate_limit.py`), registration throttled per-IP too (also bounds B-31's attacker-controlled user count)
|
||||
- **B-34** — neither self-service password change nor the admin reset invalidated already-issued JWTs, so a stolen token (or an attacker's own session) survived a password change meant to lock it out; fixed with a `User.token_version` column embedded in every JWT (`"tv"` claim) and checked on every request in `get_current_user`/`get_optional_user`, bumped on both endpoints — change-password hands back a fresh token so the caller's own session keeps working, the admin reset does not
|
||||
|
||||
See git history for the fix-by-fix breakdown (commits `f13f685`, `50a43ae`, `933760e`, and the
|
||||
B-28/B-29/B-30/B-31/B-32/B-33 fixes). Suite grew from 139 to 192 tests over the nine.
|
||||
B-28/B-29/B-30/B-31/B-32/B-33/B-34 fixes). Suite grew from 139 to 194 tests over the ten.
|
||||
|
||||
A full-codebase audit on 2026-07-26 (commit `d4e0974`) found 24 bugs across every Python
|
||||
module under `app/`, both static frontends, and the Docker/Caddy deployment — 5 critical,
|
||||
|
||||
Reference in new issue
Block a user