-
Notifications
You must be signed in to change notification settings - Fork 341
Fix jti consistency for token creation #1255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Conversation
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
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
@kevalmahajan
kevalmahajan
requested review from
crivetimihai and
madhav165
as code owners
October 15, 2025 13:29
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.
Uh oh!
There was an error while loading. Please reload this page.
🐛 Bug-fix PR
Closes #1254
📌 Summary
This PR fixes a bug where the jti (JWT ID) value in the generated JWT token does not match the jti stored in the
email_api_tokens
database table. This mismatch will cause issues with token validation, revocation, and audit logging.The fix ensures that a single jti is generated and reused both for token creation and database insertion, maintaining consistency and referential integrity.
🔁 Reproduction Steps
🐞 Root Cause
The jti - JWT ID was being generated inside the
_generate_token
function and included in the token payload, but this same ID was not used when inserting the token record into the database. Instead, the database assigned a separate, random jti value to the record. As a result, the token and its corresponding database entry ended up with different jti values, breaking token validation and tracking mechanisms.To fix this, the jti must be generated before both token creation and database insertion, ensuring the same ID is consistently used in both places.
💡 Fix Description
Refactored the token creation logic to generate the jti before both token generation and database insertion.
The same jti is now explicitly passed to both the _generate_token function and the database record creation, ensuring consistency.
🧪 Verification
make lint
make test
make coverage
📐 MCP Compliance (if relevant)
✅ Checklist
make black isort pre-commit
)