fix: reject expired IMS tokens by comparing expiry in milliseconds - #265
Merged
Merged
Conversation
IMS JWT `created_at` and `expires_in` fields are in milliseconds, but `now` was computed in seconds — making `expires` always ~1000x larger than `now`, so expired tokens were never rejected. Fix: use `Date.now()` (ms) for `now` to match the IMS field scale. Also update the jose mock and offline validation token fixture to use ms-scale timestamps, matching real IMS behavior. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Tokens with < 60s remaining cause DA_AUTH.put() to throw a 400 (Cloudflare KV requires expiration >= 60s in the future). The unhandled error propagated through getUsers → getDaCtx → 500 response. Fix: wrap the KV PUT in setUser() with a try-catch so near-expiry tokens still authenticate the user for the current request; they just won't be cached, which is the right behaviour for an almost-expired token anyway. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
bosschaert
reviewed
Apr 29, 2026
bosschaert
approved these changes
Apr 29, 2026
Collaborator
|
🎉 This PR is included in version 1.6.2 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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.
Issue
Regular
500observed with message:Summary
created_atandexpires_infields are in milliseconds, butnowwas computed in seconds (Math.floor(Date.now() / 1000)), making the comparisonexpires < nowalways false — expired tokens were never rejectedDate.now()fornowso both sides of the comparison are in millisecondsTest plan
auth.test.js: token issued 2h ago valid for 1h → must resolve asanonymous; confirmed the test fails before the fix and passes afteranonymous if expiredtest continues to passOffline Token Validationtests continue to passnpm run lint && npm test— 0 failures🤖 Generated with Claude Code