mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 15:23:29 +00:00
Two findings from the v1.4.34.3 security audit, both with the same
shape — every authenticated surface a user owns should rotate when a
credential-rotation path fires, and unfamiliar discovery sub-paths
must not inherit "no auth" status by default.
destroyAllSessions:
Previously only ran `prisma.session.deleteMany`, leaving every
long-lived `ApiToken` row (Bearer credentials issued via
/settings/api-tokens) and every native-client `RefreshToken`
intact. A stolen iOS Bearer kept working after the user rotated
their password or after an admin reset; only the browser cookie
flipped. Wraps the cleanup in a $transaction that flips
`apiToken.revoked = true` and `refreshToken.revokedAt = now()` in
the same atomic block so the audit trail survives. Both lookups at
`src/lib/auth/api-token.ts` and `src/lib/auth/refresh-token.ts`
already filter on these columns; no second code path needed.
Same destroyAllSessions call already runs from:
- POST /api/auth/password (user-initiated change)
- POST /api/admin/users/[id]/reset-password (admin reset)
- DELETE /api/settings/account (account deletion)
All three paths now wipe every transport in one shot.
Well-known proxy bypass:
`src/proxy.ts` PUBLIC_PATHS carried "/.well-known/" with a prefix
match — a future route at `/.well-known/foo` would inherit "no
auth" status silently. Tighten to an exact-match Set
(WELL_KNOWN_PUBLIC_PATHS) seeded with the one path we actually
serve (`apple-app-site-association`). New routes must be added
explicitly.
Also drops the stale `/api/auth/codex/callback` PUBLIC_PATHS
entry — that route doesn't exist in the codebase (the Codex
OAuth flow uses `/api/auth/codex/{device-poll,device-start,
disconnect}` instead).
Tests:
- New destroyAllSessions assertion in src/lib/auth/__tests__/
session.test.ts pins the three updateMany/deleteMany call
shapes inside a single $transaction.
- Existing proxy well-known + privacy + onboarding redirect
suites stay green.