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

Fix verification_uri in device authorization response when context path exists #1729

Closed
wants to merge 4 commits into from

Conversation

sfeigl
Copy link

@sfeigl sfeigl commented Sep 27, 2024

This fixes

#1714: Invalid verification_uri in device authorization response when context path exists

Before this change the reported verification URI was built by completely replacing the path of the incoming device authorization request. If the application is not running under the root path (/) this lead to an incorrect verification URI. After the change the verification URI is built relative to the context path of the application.

Additionally it clears the query part of the URI. The current code passes the query parameters used to do the device authorization query to the verification URI. IMHO that is not expected / intended behaviour.

According to https://datatracker.ietf.org/doc/html/rfc8628#section-3.1

"Parameters sent without a value MUST be treated as if they were omitted from the request. The authorization server MUST ignore unrecognized request parameters. Request and response parameters MUST NOT be included more than once."

Passing through is not "ignoring"

The pull request should be mergeable in main and 1.3.x

Did some quick tests with:

  • application in Apache Tomcat with non-empty application root / context path (/foo/)
  • application in Payara with empty application root / context path (/)
  • sample demo-authorization-server with / and /foo context path

Seems to look ok for me

Fixes gh-1714

Selene Feigl added 2 commits September 25, 2024 12:56
The query part of the request URI was copied to the verification URI - which is - in my opinion - not the expected behaviour.

According to https://datatracker.ietf.org/doc/html/rfc8628#section-3.1

"Parameters sent without a value MUST be treated as if they were omitted from the request.  The authorization server MUST ignore unrecognized request parameters.  Request and response parameters MUST NOT be included more than once."

Passing through the request parameters is - IMHO - a different behaviour than ignoring them.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 27, 2024
@jgrandja jgrandja self-assigned this Oct 1, 2024
@jgrandja jgrandja added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 1, 2024
@jgrandja jgrandja added this to the 1.3.3 milestone Oct 1, 2024
Copy link
Collaborator

@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 @sfeigl !

Please see the review comment.

Also, can you please add a test in OAuth2DeviceAuthorizationEndpointFilterTests.

Thank you.

// Generate the fully-qualified verification URI
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder
.fromHttpUrl(UrlUtils.buildFullRequestUrl(request))
.replacePath(this.verificationUri);
.replacePath(UrlPathHelper.defaultInstance.getContextPath(request))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of using UrlPathHelper, please create an internal method resolveVerificationUri(), that looks like:

then it can be used UriComponentsBuilder.fromUriString(resolveVerificationUri(request)). This will provide consistency between the 3x implementations (OAuth2AuthorizationEndpointFilter is implemented the same).

Copy link
Author

Choose a reason for hiding this comment

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

I created - as requested - an internal method and added a test.

I used doFilterWhenDeviceAuthorizationRequestThenDeviceAuthorizationResponse as a base for my test. I am not sure whether the method name fits the project conventions for test method names and I am unsure about keeping all assertions of doFilterWhenDeviceAuthorizationRequestThenDeviceAuthorizationResponse or just using a reduced set of assertions.

@jgrandja jgrandja changed the title Make verification_uri relative to context path of application Fix verification_uri in device authorization response when context path exists Oct 4, 2024
jgrandja added a commit that referenced this pull request Oct 4, 2024
@jgrandja
Copy link
Collaborator

jgrandja commented Oct 4, 2024

Thanks for the updates @sfeigl ! FYI, I added some minor polish to the test. This is now merged.

@jgrandja jgrandja closed this Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Invalid verification_uri in device authorization response when context path exists
3 participants