Skip to content

Commit f796766

Browse files
committed
fix: reject NumericDates outside Instant range
1 parent 8920eed commit f796766

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

lib/src/main/java/com/auth0/jwt/impl/PayloadDeserializer.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
1414

1515
import java.io.IOException;
16+
import java.time.DateTimeException;
1617
import java.time.Instant;
1718
import java.util.*;
1819

@@ -88,7 +89,13 @@ Instant getInstantFromSeconds(Map<String, JsonNode> tree, String claimName) {
8889
"The claim '%s' value (%s) is out of the range representable as a NumericDate.",
8990
claimName, node.asText()));
9091
}
91-
return Instant.ofEpochSecond(node.asLong());
92+
try {
93+
return Instant.ofEpochSecond(node.asLong());
94+
} catch (DateTimeException e) {
95+
throw new JWTDecodeException(String.format(
96+
"The claim '%s' value (%s) is out of the range representable as a NumericDate.",
97+
claimName, node.asText()), e);
98+
}
9299
}
93100

94101
String getString(Map<String, JsonNode> tree, String claimName) {

lib/src/test/java/com/auth0/jwt/impl/PayloadDeserializerTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,18 @@ public void shouldThrowOutOfRangeWhenNumericDateExceedsLong() {
269269
deserializer.getInstantFromSeconds(tree, "key");
270270
}
271271

272+
@Test
273+
public void shouldThrowOutOfRangeWhenNumericDateExceedsInstantRange() {
274+
exception.expect(JWTDecodeException.class);
275+
exception.expectMessage(
276+
"The claim 'key' value (9223372036854775807) is out of the range representable as a NumericDate.");
277+
278+
Map<String, JsonNode> tree = new HashMap<>();
279+
tree.put("key", new LongNode(Long.MAX_VALUE));
280+
281+
deserializer.getInstantFromSeconds(tree, "key");
282+
}
283+
272284
@Test
273285
public void shouldGetNullStringWhenParsingNullNode() {
274286
Map<String, JsonNode> tree = new HashMap<>();
@@ -299,4 +311,4 @@ public void shouldGetStringWhenParsingTextNode() {
299311
assertThat(text, is("something here"));
300312
}
301313

302-
}
314+
}

0 commit comments

Comments
 (0)