Skip to content

Commit 9d4d10d

Browse files
author
Ning Kang
committed
Fixed OAuth2Util crash with IllegalArgumentException when extracting expiration time from arbitrary Bearer token that looks like jwt.
1 parent 3469cf3 commit 9d4d10d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

core/src/main/java/org/apache/iceberg/rest/auth/OAuth2Util.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ static Long expiresAtMillis(String token) {
441441
JsonNode node;
442442
try {
443443
node = JsonUtil.mapper().readTree(Base64.getUrlDecoder().decode(parts.get(1)));
444-
} catch (IOException e) {
444+
} catch (IOException | IllegalArgumentException e) {
445445
return null;
446446
}
447447

core/src/test/java/org/apache/iceberg/rest/auth/TestOAuth2Util.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public void testOAuthScopeTokenValidation() {
7373
public void testExpiresAt() {
7474
assertThat(OAuth2Util.expiresAtMillis(null)).isNull();
7575
assertThat(OAuth2Util.expiresAtMillis("not a token")).isNull();
76+
assertThat(
77+
OAuth2Util.expiresAtMillis(
78+
"a.b.c token looks like jwt but not jwt and too short per section"))
79+
.isNull();
7680

7781
// expires at epoch second = 1
7882
String token =

0 commit comments

Comments
 (0)