Skip to content
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

Add nonce to OIDC Authentication Request #7337

Closed
wants to merge 7 commits into from

Conversation

mkheck
Copy link
Contributor

@mkheck mkheck commented Sep 2, 2019

This is a PR for gh-4442: Consider adding nonce to OAuth2 Authentication Request (#4442).

I've coded the implementation & tests for creating+passing+verifying the nonce in the ID token, and all tests pass (with the exception of the one that wasn't passing in the codebase before).

I would like to open a follow-on request to push some optimizing changes out a bit further.
I'm getting everything I need within the OidcIdTokenValidator by retrieving the nonce via claims, but it would be cleaner to change from dealing with Jwt to dealing with OIdcIdTokens instead. But that would necessitate reaching into & reworking DefaultOidcIdTokenValidatorFactory (& of course tests associated, etc.) and everything that touches. And it touches quite a lot.

In short, this all works, so I believe the issue to be feature complete. But I would like to extend further changes to present a more specific solution throughout.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 2, 2019
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.

@mkheck Thanks for the PR! I left a couple of comments for you. Also, can you please rebase off master and squash commits to one and than force push. Please ensure you do fast-forward merges as we use this git process. Thanks!

@jgrandja jgrandja self-assigned this Sep 7, 2019
@jgrandja jgrandja added in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 7, 2019
@jgrandja jgrandja changed the title PR for gh-4442: Consider adding nonce to OAuth2 Authentication Request Add nonce to OAuth2 Authentication Request Sep 7, 2019
@jgrandja
Copy link
Contributor

jgrandja commented Sep 7, 2019

@mkheck I've been thinking about whether the nonce validation should happen in OidcIdTokenValidator or OidcAuthorizationCodeAuthenticationProvider. Although it seems natural that it should happen in OidcIdTokenValidator, there are some challenges with that since either nonce should be passed in via the constructor, as you have it:

public OidcIdTokenValidator(ClientRegistration clientRegistration, String nonce)

which is not ideal since we would have to create a new OidcIdTokenValidator per request since the specific nonce is request specific.

The other solution is to implement the validation check in OidcAuthorizationCodeAuthenticationProvider, which would work well since we have access to the OidcIdToken and OAuth2AuthorizationRequest. We are also doing validation checks there between the OAuth2AuthorizationRequest and OAuth2AuthorizationResponse. So I say we implement the nonce check directly in OidcAuthorizationCodeAuthenticationProvider.

Makes sense?

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 updates @mkheck! I left some further feedback. Looks like there are some test failures. You can run ./gradlew --refresh-dependencies clean check to ensure build passes before you push.

Also, can you update the commit messages to follow this format.

String nonceHash = createHash(nonce);
additionalParameters.put(IdTokenClaimNames.NONCE, nonceHash);
} catch (NoSuchAlgorithmException e) {
// MAH: TODO...but what?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the nonce hash could not be created because of JCE crypto lib missing than we should not add the nonce to attributes, effectively creating an Authentication Request without a nonce as is the current impl.

Implements nonce functionality for OpenID Connect
authentication request in OAuth2 Authorization Code flow.
This includes the following capabilities:

* Generate nonce

* Generate hash of nonce

* Add nonce to attributes and hash to additional
parameters of authentication request

* Propagate hash to authentication response

* Verify hash upon receipt of response by hashing
original nonce

* Complete all relevant tests

Fixes/implements spring-projectsgh-4442
@mkheck
Copy link
Contributor Author

mkheck commented Sep 11, 2019

Hi @jgrandja,

Good catches one and all. I've reworked per your recommendations and all build tests pass. LDAP integration tests are failing, but I suppose those are resolved by Travis?

I've also formatted the commit message per the guidelines you provided. 😃

Please let me know of any additional changes required or desired. Thanks!

@mkheck
Copy link
Contributor Author

mkheck commented Sep 11, 2019

Missed 4 unit tests in OAuth2AuthorizationRequestRedirectFilterTests, fixed & re-pushed. Please let me know if I need to repackage in some way. 😑

Still getting local failures with various LDAP tests under org.springframework.security.config.ldap, but I did not modify those. Integration tests to complete successfully in CI pipeline?

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 updates @mkheck. Please see comments inline.

Made changes requested by Joe Grandja to PR, including addition of test
when nonce isn't present in request.

Fixes spring-projectsgh-4442 and addresses changes requested to PR
Copy link
Contributor Author

@mkheck mkheck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please let me know Joe, thanks!

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 updates @mkheck. Please see my comments.

Also, can you add a test in OidcAuthorizationCodeReactiveAuthenticationManagerTests

@jgrandja jgrandja added this to the 5.2.0 milestone Sep 23, 2019
@jgrandja jgrandja changed the title Add nonce to OAuth2 Authentication Request Add nonce to OIDC Authentication Request Sep 26, 2019
@jgrandja
Copy link
Contributor

jgrandja commented Sep 26, 2019

Thanks for the PR @mkheck! This is now in master via da9f027. Please take a look at the polish commit d3b7a47 and let me know if you have any questions.
Thanks again!

@jgrandja jgrandja closed this Sep 26, 2019
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) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants