Skip to content

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

Closed

Conversation

furti
Copy link
Contributor

@furti furti commented Apr 8, 2020

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.

Copy link
Contributor

@jgrandja jgrandja left a 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");
Copy link
Contributor

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.

Copy link
Contributor

@mengelbrecht mengelbrecht Apr 17, 2020

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).

Copy link
Contributor

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)) {
Copy link
Contributor

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()
Copy link
Contributor

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");
Copy link
Contributor

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");
Copy link
Contributor

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
Copy link
Contributor

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

@jgrandja jgrandja added in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: duplicate A duplicate of another issue type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 17, 2020
@jgrandja jgrandja added this to the 5.4.0.M1 milestone Apr 17, 2020
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
@furti furti force-pushed the gh-8321-issuer-validation branch from b9d029e to f15e84b Compare April 19, 2020 04:25
@furti
Copy link
Contributor Author

furti commented Apr 19, 2020

@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).
I ignored the "issuer" -> "iss" comments, as @mengelbrecht pointed out, the claim is called "issuer" in the metadata.

@jgrandja
Copy link
Contributor

Thanks for the updates @furti. This is now in master!

@jgrandja jgrandja closed this Apr 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Open ID Connect ID Token Issuer not validated
4 participants