Repository navigation
fix(jwtsvid): return null from getIssuedAt when the iat claim is absent - #480
Merged
Merged
Conversation
The 'iat' claim is optional in a JWT-SVID, and JwtSvid.parseInsecure and JwtSvid.parseAndValidate accept tokens without it. In that case the issuedAt field is null, and JwtSvid.getIssuedAt() threw a NullPointerException while making its defensive copy. Any caller that read the issued-at time of such a token crashed. getIssuedAt() now returns null when the token has no 'iat' claim, and otherwise still returns a defensive copy, matching getExpiry(). The method gains Javadoc describing the null return. CachedJwtSource.isTokenPastHalfLifetime previously avoided the NPE by reading the raw "iat" entry from the claims map. It now uses getIssuedAt() directly. Its behavior is unchanged: SVIDs without 'iat' are still treated as needing a refresh. Tests cover a token without 'iat' (getIssuedAt returns null) and a token with 'iat' (the value is returned and the internal state cannot be modified through the returned Date). Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
maxlambrecht
force-pushed
the
fix/jwt-svid-missing-iat
branch
from
October 29, 2026 15:37
ca4e3b1 to
d1ba2e9
Compare
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.
What
Make
JwtSvid.getIssuedAt()returnnullwhen the JWT-SVID has noiatclaim instead of throwing aNullPointerException. Wheniatis present it still returns a defensive copy, as before. The method now has Javadoc that describes thenullreturn.CachedJwtSource.isTokenPastHalfLifetimenow callsgetIssuedAt()instead of reading the raw"iat"entry fromgetClaims(), which #430 added to avoid this NPE. Its behavior is unchanged: SVIDs withoutiatare still refreshed.Fixes #477
Why
iatis optional in a JWT-SVID, andparseInsecure/parseAndValidateaccept tokens without it. The public getter, however, dereferenced the field unconditionally, so any caller reading the issued-at time of such a token crashed.How tested
JwtSvidParseInsecureTest: a token withoutiatreturnsnull, and a token withiatreturns the value as a copy that cannot change the SVID. The first test fails with an NPE without this change../gradlew :java-spiffe-core:build(includes the full core test suite, includingCachedJwtSourceTest, and the binary compatibility check) on JDK 17.