Reject access tokens issued before a per-user cutoff

Draft
HA
42m ago
+18142-0

Revoking a CLI token in the DB does not stop its 7-day JWT. This adds nullable auth.users.tokens_valid_after. sessionFromOAuthBearer rejects a token whose iat is before it. Null = no effect, other users untouched, JWKS key not rotated.

  • Check is in apps/api/src/trpc/context.ts. It reuses the user row already loaded per request: no extra query.
  • Migration 0199 is a nullable column add with no default (metadata-only). It takes a brief ACCESS EXCLUSIVE lock on auth.users; the db-migrations checklist is not yet cleared, and the migration has not been run anywhere.
  • Not covered: Workers using verifyJWT (relay, realtime) and packages/mcp/src/auth.ts have no DB access and still accept the token until expiry.
  • Tests: bun test src/trpc/isIssuedBeforeCutoff (4 pass).

Summary by cubic

Revoking a CLI token in the DB now stops its 7-day JWT instead of leaving it valid until expiry. This adds a nullable auth.users.tokens_valid_after column; sessionFromOAuthBearer rejects any bearer token whose iat predates the user's cutoff. A null cutoff leaves behavior unchanged, other users are untouched, and no JWKS keys are rotated. The check lives in apps/api/src/trpc/context.ts and reuses the user row already loaded per request, so no extra query is added.

Migration

  • Migration 0199 adds the nullable column with no default and takes a brief ACCESS EXCLUSIVE lock on auth.users; it has not been run anywhere yet.

Not covered

  • Workers using verifyJWT (relay, realtime) and packages/mcp/src/auth.ts have no DB access and still accept the token until expiry.