-
Notifications
You must be signed in to change notification settings - Fork 6k
Validate ID Token Issuer #8357
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
Validate ID Token Issuer #8357
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @furti. Please see my comments.
@@ -143,6 +146,13 @@ public void setClock(Clock clock) { | |||
this.clock = clock; | |||
} | |||
|
|||
private boolean issuerMatchesMetadata(Jwt idToken) { | |||
String metadataIssuer = (String) clientRegistration.getProviderDetails().getConfigurationMetadata() | |||
.get("issuer"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issuer claim is iss
. You can use JwtClaimNames.ISS
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure? AFAIK the claim is called issuer
in the provider metadata and iss
in the id token (https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, my mistake. Thanks for correcting me @mengelbrecht !
@@ -68,7 +69,9 @@ public OAuth2TokenValidatorResult validate(Jwt idToken) { | |||
|
|||
// 2. The Issuer Identifier for the OpenID Provider (which is typically obtained during Discovery) | |||
// MUST exactly match the value of the iss (issuer) Claim. | |||
// TODO Depends on gh-4413 | |||
if (!issuerMatchesMetadata(idToken)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move the validation check here and remove the method.
@@ -143,6 +146,13 @@ public void setClock(Clock clock) { | |||
this.clock = clock; | |||
} | |||
|
|||
private boolean issuerMatchesMetadata(Jwt idToken) { | |||
String metadataIssuer = (String) clientRegistration.getProviderDetails().getConfigurationMetadata() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prefix this.
for private members -> this.clientRegistration
* the validation must fail | ||
*/ | ||
Map<String, Object> configurationMetadata = new HashMap<>(); | ||
configurationMetadata.put("issuer", "https://issuer.somethingelse.com"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use JwtClaimNames.ISS
* the validation must fail | ||
*/ | ||
Map<String, Object> configurationMetadata = new HashMap<>(); | ||
configurationMetadata.put("issuer", "https://issuer.example.com"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use JwtClaimNames.ISS
public void validateWhenMetadataIssuerMatchThenNoErrors() { | ||
/* | ||
* When the issuer is set in the provider metadata, and it does not match the issuer in the ID Token, | ||
* the validation must fail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validation must fail -> validation will pass
When the issuer is set in the provider metadata, we validate the iss field of the ID Token against it. The OpenID Connect Specification says this must always be validated. But this would be a breaking change for applications configured other than with ClientRegistrations.fromOidcIssuerLocation(issuer). This will be done later with spring-projects#8326 fixes spring-projectsgh-8321
b9d029e
to
f15e84b
Compare
@jgrandja I implemented your changes and pushed the commit again. I moved the check inline, added the "this." prefix and fixed the wrong javadoc comment in the Test (copy paste error). |
Thanks for the updates @furti. This is now in master! |
When the issuer is set in the provider metadata, we validate the iss
field of the ID Token against it.
The OpenID Connect Specification says this must always be validated.
But this would be a breaking change for applications configured other
than with ClientRegistrations.fromOidcIssuerLocation(issuer). This will
be done later with #8326
fixes gh-8321
Running gradlew
I tried to run
./gradlew build
but 3 Tests failed in classes I did not even touch. But the tests for the class I changed passed, so I think the changes should be fine.If you want me to give the build another try, please let me know.
CLA
I signed the CLA.