Files
GandClaude Opus 5 c6d688d79b fix(admin): patient rows carried every patient's password hash (#41)
GET /api/admin/patients and /api/admin/patients/[id] returned the Drizzle row
verbatim — `db.query.users.findMany(...)` with no `columns:` projection — so
every response carried each patient's bcrypt digest, plus failedLoginAttempts
and lockedUntil.

Confirmed live on prod before fixing: 2/2 rows in the list response and both
detail responses carried a `$2b$12$…` hash.

This is a worse shape than the FleetCrown /api/me case that prompted the sweep.
There the digest was the caller's own. Here an admin console shipped OTHER
people's credential material to a browser, in a clinic app, where those people
are patients. A digest is not a password, but it is the input to an offline
attack that costs the attacker nothing, and it moves the secret from a place
nothing can read it to a place everything can.

lib/db/user-view.ts is now the single answer to what may leave the server:
an ALLOW-list whose halves are exhaustive over the schema, so a new users
column fails the test until it is classified exposed or withheld. A deny-list
can only name what existed when it was written.

failedLoginAttempts and lockedUntil stay exposed deliberately — not secrets,
and an admin helping someone locked out needs to see them.

Negative-tested in both directions, because a gate that cannot fail is not a
gate: dropping `role` from the list fails with "users.role is in NEITHER list";
re-exposing `password` fails with "in BOTH lists" plus the projection and
serialization assertions.

Verified: tsc clean, eslint clean, 1100/1100 tests (8 new).

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-16 10:49:18 +00:00
..