Skip to content

Auth: give every JWT a unique jti - #18

Merged
3m1n3nc3 merged 1 commit into
mainfrom
fix/auth-unique-jwt
Oct 21, 2026
Merged

3m1n3nc3 merged 1 commit into
mainfrom
fix/auth-unique-jwt

Conversation

@3m1n3nc3

Copy link
Copy Markdown
Member

Summary

Auth.create signs { sub, email } with iat/exp, both at one-second precision. Two tokens for the same user within the same second are therefore identical, and the second personal_access_tokens insert fails on the unique token column, so the login returns a 500.

Seen in Arkyc CI: admin-users.test.ts registers a user and logs in within the same second and fails intermittently. The same happens in production on a double-submitted login.

Each JWT now carries a random jti (randomUUID()).

Tests

New packages/auth/tests/jwt.test.ts signs two tokens for the same payload back to back and asserts they differ. It fails without the fix. Auth suite: 21 passed.

The token payload was only sub and email plus iat/exp, which have
one-second precision, so two logins by the same user within a second
produced identical tokens. The second insert then collided on the unique
personal_access_tokens.token column and the login failed with a 500
(e.g. a double-submitted login, or a test that registers and logs in at
once). Each token now carries a random jti.
@3m1n3nc3
3m1n3nc3 merged commit 8f4222e into main Oct 21, 2026
3 checks passed
@codecov

codecov Bot commented Oct 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant