-
Notifications
You must be signed in to change notification settings - Fork 6k
ID Token validation should support clock skew #5839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@zcwang3 You've tested 3 different scenarios with 2 passing and 1 failing so this suggests a possible environment issue. I took a look at the debug screenshot you provided and it looks like you have a clock sync issue between the computer you're testing on and Google's clock. 2018-09-13T08:55:26.893Z - Now (Testing machine clock) As you can see, the clock on your testing machine is not in sync with Google's clock. Looks like the testing machine clock is approx. 36 secs behind Google's clock. Can you adjust the clock on the testing machine and re-test? Please also see this comment for more info. There is no current way for a user to configure We can look at adding this support in a future release. And I also feel that a more detailed exception message for ID Token validation failures is needed. |
@jgrandja Thanks for you checking. Please notice: in the same test machine, Microsoft ID token verification is pass and Google ID token verification is failure because of maxIssuedAt check issue. After I have sync clock on my testing machine with ntp command, the same issue still exists. So i think clock out of sync issue should exist in Google and I can do nothing for that. So, I need increate grace time of maxIssuedAt check to avoid potential production issue caused by clock out of sync in OpenID provider (like Microsoft / Google / etc...) |
Can you please provide another sceenshot from the test machine for Microsoft and Google. I'd like to see what the |
Hi @jgrandja here is the attached screen shots for Microsoft / Google id token verification Google ID token verification: Google clock is about 40s faster than our server BTW: private void validateIdToken(OidcIdToken idToken, ClientRegistration clientRegistration) {
|
Hi @jgrandja Do we have any conclusion/plan for this issue? |
@zcwang3 Apologies for the delayed response. We were quite busy leading up to the 5.1 release and SpringOne last week. I do have a plan on how to provide a configurable clock skew value for Would you be interested in submitting a PR for this? I could guide you through the process and detail the plan/idea I have for this change. |
@jgrandja Sorry for late response because of holiday leave. I can have a try to fix this issue. |
@zcwang3 No worries. I'll try to get to it soon as well. If you get to it before me please let me know. Thanks. |
@jgrandja In the meantime should we rename this to be something like...OidcAuthorizationCodeAuthenticationProvider should support clock skew? |
@rwinch Yes, thanks for pointing that out. I renamed it to be more specific to ID Token validation. |
@jgrandja clock skew is just one of the many factors due to which this check would fail (e.g. network latency). I'd recommend to name this client config as Additionally, clock skew is applicable not just to
|
@gburboz Thanks for the feedback. I'll consider your points when I get to this issue. |
Hi @jgrandja i have the same issue. when do you think you will resolve it. |
@yannick-fernand This is scheduled for 5.2.0.M1 as indicated in the ticket. However, given that M1 is scheduled for Jan 15, it might not make it until M2. I'm trying to catch up with things since the break. I'll do my best. |
@zcwang3 @gburboz @yannick-fernand Clock skew can now be configured via |
@zcwang3 @gburboz @yannick-fernand #6379 has been resolved which allows the user to configure the clock skew (per provider) in a straight forward way. The following example demonstrates a custom clock skew setting for @Configuration
public class OAuth2LoginConfig {
@Bean
public JwtDecoderFactory<ClientRegistration> idTokenDecoderFactory() {
OidcIdTokenDecoderFactory idTokenDecoderFactory = new OidcIdTokenDecoderFactory();
idTokenDecoderFactory.setJwtValidatorFactory(clientRegistration -> {
OidcIdTokenValidator idTokenValidator = new OidcIdTokenValidator(clientRegistration);
if (clientRegistration.getRegistrationId().equals("google")) {
idTokenValidator.setClockSkew(Duration.ofSeconds(30));
} else if (clientRegistration.getRegistrationId().equals("okta")) {
idTokenValidator.setClockSkew(Duration.ofSeconds(45));
}
return idTokenValidator;
});
return idTokenDecoderFactory;
}
} NOTE: Please be aware that |
Hello @jgrandja, how can this new method be used?: idTokenDecoderFactory() |
Summary
I am using spring security 5.0.7 with spring boot 2.0.4.RELEASE for login with Google and Login with Microsoft feature.
I meet the same issue of OidcAuthorizationCodeAuthenticationProvider maxIssuedAt which is closed without any enhancement
Actual Behavior
Today, when i login with Google account in one of my testing machine, I meet the issue with follow error message:
c.c.w.g.c.SecurityConfiguration$2 - Authentication request failed: org.springframework.security.oauth2.core.OAuth2AuthenticationException: [invalid_id_token]
it does not output the detail reason why id token is invalid: like aud is null or audience is not same with client id or idToken is expired etc.
After debug, I find that the failure reason is because of issuedAt.isAfter(maxIssuedAt) check failure, you can see detail error reason in the following screen shots:

Expected Behavior
Login with Microsoft and Google account should be successful in all different machines with some grace time
Please notice
Login with Microsoft account with ID token is successful in the same machine.
Login with Google account with ID token is failure because of issuedAt.isAfter(maxIssuedAt) check failure
Login with Microsoft and Google account with ID token are both successful in other testing machines
Since we can not control the issuedAt value which generated by Microsoft or Google and issuedAt generated by Microsoft and Google is obviously different in my testing machine.
Enhance request 1: add detail error reason in exception when id_tioken validate failure
Enhance request 2: default 30 second in the check of issuedAt.isAfter(maxIssuedAt) becomes configurable
Suggestion to fix with existing spring security version : And for current spring security version without previous enhance support, how can I do to change the value of 30 to 300s, do we have some extension point for it without change sourcecode in jar?
Configuration
no special configuration, the issue is just related with id token check logic in OidcAuthorizationCodeAuthenticationProvider
Version
org.springframework.boot spring-boot-starter-parent 2.0.4.RELEASESample
no special configuration, the issue is just related with id token check logic in OidcAuthorizationCodeAuthenticationProvider
The text was updated successfully, but these errors were encountered: