Repository navigation
Auth: give every JWT a unique jti - #18
Merged
Merged
Conversation
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Auth.createsigns{ sub, email }withiat/exp, both at one-second precision. Two tokens for the same user within the same second are therefore identical, and the secondpersonal_access_tokensinsert fails on the uniquetokencolumn, so the login returns a 500.Seen in Arkyc CI:
admin-users.test.tsregisters 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.tssigns two tokens for the same payload back to back and asserts they differ. It fails without the fix. Auth suite: 21 passed.