Client: accept server epoch-second expires_at, normalize to ISO#227
Merged
Conversation
The server sends the OIDC `expires_at` as a Unix epoch-second (the JWT `exp`), matching its bootstrap/refresh identity endpoints. The client now normalizes that wire form to an ISO string on the way in, keeping storage and the refresh-freshness check ISO-based. An ISO string is still accepted for older mocks/servers, and an epoch-as-a-string stays rejected so an unparseable expiry can't loop the refresh forever.
platypii
commented
Jul 1, 2026
| if (!Number.isFinite(v) || v <= 0) { | ||
| throw new Error(`identity response field '${field}' is not a valid timestamp`) | ||
| } | ||
| return new Date(v * 1000).toISOString() |
Contributor
Author
There was a problem hiding this comment.
Low severity, non-blocking. The number branch guards Number.isFinite(v) && v > 0 but not the magnitude, so a large-but-finite positive value (a server mistakenly sending exp in ms or µs) slips through. Two out-of-contract outcomes:
v > ~8.64e12(e.g. microsecondexp):new Date(v * 1000).toISOString()throws an uncontrolledRangeError: Invalid time value, defeating this function's stated purpose of failing loudly with a descriptive error — it escapes as an unclassified error on the refresh hot path.v ≈ 1.7e12(millisecondexp): produces a valid year-56461 date, soisFreshtreats the token as fresh forever and it never refreshes — silently.
Both require an out-of-spec server, so this is not blocking. If you want to harden it, validate the constructed date and/or bound the epoch to a sane range, e.g.:
if (typeof v === 'number') {
const ms = v * 1000
const d = new Date(ms)
if (!Number.isFinite(v) || v <= 0 || Number.isNaN(d.getTime())) {
throw new Error(`identity response field '${field}' is not a valid timestamp`)
}
return d.toISOString()
}
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
Align the OIDC client with the OAuth wire form the server actually sends. The server emits
expires_atas a Unix epoch-second (the JWTexp), matching its bootstrap/refresh identity endpoints. The client now normalizes that to an ISO string on the way in, so session storage and the refresh-freshness check (isFresh) stay ISO-based.expiryTimestampaccepts a finite positive JSON number (epoch-second) and converts to ISO; still accepts an ISO string for older mocks/servers.Testing
npm test(1775 passing)🤖 Generated with Claude Code