fix: reject NumericDates outside Instant range - #790
Conversation
|
Hi @ANSHUL-REAL, Thanks for tracking this down — the fix correctly closes the gap from #782, and the repro in the issue was really helpful. One small gap in test coverage: Separately, and non-blocking for this PR: Would it be worth consolidating the range check into a single explicit check against if (!node.canConvertToLong()
|| node.asLong() < Instant.MIN.getEpochSecond()
|| node.asLong() > Instant.MAX.getEpochSecond()) {
throw new JWTDecodeException(String.format(
"The claim '%s' value (%s) is out of the range representable as a NumericDate.",
claimName, node.asText()));
}
return Instant.ofEpochSecond(node.asLong());This keeps the exact same exception types and messages (so no behaviour change for callers), removes the try/catch, and ties the bound directly to |
f5078ea to
8ec08a9
Compare
|
Verified locally in both directions (Long.MAX_VALUE and Long.MIN_VALUE); both are now covered and passing. The Instant.MIN/Instant.MAX approach reads a lot cleaner than the try/catch too. Thanks for making these changes! @ANSHUL-REAL
|
Fixes #782
Registered NumericDate claims that fit in a
longbut fall outsidejava.time.Instant's epoch-second range are now rejected through the library's existingJWTDecodeExceptionboundary.The range check uses
Instant.MINandInstant.MAXdirectly and covers both overflow and underflow with regression tests forLong.MAX_VALUEandLong.MIN_VALUE.Validation:
./gradlew :java-jwt:test --tests com.auth0.jwt.impl.PayloadDeserializerTest -x :java-jwt:compileModuleInfoJava./gradlew :java-jwt:test -x :java-jwt:compileModuleInfoJava