Skip to content

Commit 4589194

Browse files
vishalvrv9jgrandja
authored andcommitted
OidcIdTokenValidator ensures clockSkew is positive number
Fixes gh-6443
1 parent 462b2ec commit 4589194

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/oidc/authentication/OidcIdTokenValidator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public OAuth2TokenValidatorResult validate(Jwt idToken) {
132132
*/
133133
public final void setClockSkew(Duration clockSkew) {
134134
Assert.notNull(clockSkew, "clockSkew cannot be null");
135+
Assert.isTrue(clockSkew.getSeconds() >= 0, "clockSkew must be >= 0");
135136
this.clockSkew = clockSkew;
136137
}
137138

oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/oidc/authentication/OidcIdTokenValidatorTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.Map;
3434

3535
import static org.assertj.core.api.Assertions.assertThat;
36+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
3637

3738
/**
3839
* @author Rob Winch
@@ -60,6 +61,21 @@ public void validateWhenValidThenNoErrors() {
6061
assertThat(this.validateIdToken()).isEmpty();
6162
}
6263

64+
65+
@Test
66+
public void setClockSkewWhenNullThenThrowIllegalArgumentException() {
67+
OidcIdTokenValidator idTokenValidator = new OidcIdTokenValidator(this.registration.build());
68+
assertThatThrownBy(() -> idTokenValidator.setClockSkew(null))
69+
.isInstanceOf(IllegalArgumentException.class);
70+
}
71+
72+
@Test
73+
public void setClockSkewWhenNegativeSecondsThenThrowIllegalArgumentException() {
74+
OidcIdTokenValidator idTokenValidator = new OidcIdTokenValidator(this.registration.build());
75+
assertThatThrownBy(() -> idTokenValidator.setClockSkew(Duration.ofSeconds(-1)))
76+
.isInstanceOf(IllegalArgumentException.class);
77+
}
78+
6379
@Test
6480
public void validateWhenIssuerNullThenHasErrors() {
6581
this.claims.remove(IdTokenClaimNames.ISS);

0 commit comments

Comments
 (0)