Migrate the OAuth provider: rotation with reuse detection, auth_time in seconds #91
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
queue
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
romaine-life/auth!91
Loading…
Reference in a new issue
No description provided.
Delete branch "oauth-provider-migration"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Stage 3 of the Chess Tactics authentication audit, in this repository because two of its findings
are here rather than there.
Why
Two normative defects in the deprecated
oidcProviderplugin, confirmed still present in its ownlatest release (1.6.27) and therefore never going to be fixed in it:
left the previous refresh token valid until its own expiry, so replaying one produced no conflict
and rotation bought nothing (RFC 9700 §4.14.2). It also re-stamped the expiry on every refresh,
so an active chain never expired at all.
auth_timewas emitted in milliseconds where OIDC Core §2 requires seconds, so a relyingparty checking authentication freshness saw a time in the far future and passed unconditionally.
What this is
Not a rename. Three structural differences:
trustedClientsoption;src/oauth-clients.tsdeclares the four andreconciles them into
oauth_clientat boot, awaited beforeserve(). A confidential clientwith no secret in the environment throws rather than registering as one anybody could
impersonate.
customIdTokenClaimsandcustomUserInfoClaimsboth feedplatformClaims. This is the dangerous one: losingroleorgroupsraises no error, it justdemotes every Grafana user to Viewer and stops Argo CD matching any RBAC rule.
endpoints.
drizzle/0002is expand/contract — the two colliding legacy tables are renamed aside, neverdropped, so a rollback finds its data intact.
Verification
npm run test:oauthboots the provider over PGlite (Postgres as WASM) and drives the real HTTPsurface with real
Requestobjects. Eight tests: the schema applies; reconciliation is idempotentand preserves row ids; a real login carries
role/groups/appsin both the id_token anduserinfo;
auth_timeis seconds, asserted by wall-clock skew; a rotated refresh token isrefused and replaying it revokes the family, checked in the database; a confidential client
cannot redeem without its secret; a code is single-use; a bad PKCE verifier is refused; and the
shipped SQL produces exactly the columns the drizzle models map to.
Writing them found two real defects that no typecheck would have caught: the camelCase/snake_case
table mismatch between Better Auth's generator and this repo's drizzle models, and a client secret
written raw where the plugin expected a hash.
Whole suite: 167 passing,
tsc --noEmitclean.Before rolling out
OIDC_CHESS_TACTICS_CLIENT_SECRETin Key Vault, mounted here and in Chess Tactics.drizzle/0002before rolling the image.meaningless to the new plugin.
configured in those systems.
drizzle/0003drops the*_legacytables once confirmed — not before.Pairs with romaine-life/chess-tactics#920, and note the ordering constraint in
docs/oauth-provider-migration.md: fixing rotation without raising the refresh lifetime wouldshorten Chess Tactics sessions, because today's bug is the only reason an active chain outlives
seven days. Both changes are in this branch for that reason.