Skip to content

Prevent double-escaping of authorize URL parameters #7881

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
wants to merge 2 commits into from
Closed

Prevent double-escaping of authorize URL parameters #7881

wants to merge 2 commits into from

Conversation

manuelbl
Copy link
Contributor

If the authorization URL in the OAuth2 provider configuration contained query parameters with percent escaped characters, these characters were escaped a second time – damaging the URL. This commit fixes it.

It is relevant to support the OIDC claims parameter (see https://openid.net/specs/openid-connect-core-1_0.html#ClaimsParameter).

Fixes gh-7871

Implementation notes

As UriComponentsBuilder cannot fully decode query parameters (no implementation for undoing the percent escaping), the approach is to assemble already escaped components. Before adding query parameters to the authorization URL, they must therefore be properly escaped.

The method for percent escaping uses separate UriComponentsBuilder instances. That's not straight-forward but the only way to access the method HierarchicalUriComponents.encodeUriComponent. It ensures that the minimal necessary escaping according to RFC 3986 is applied.

An alternative would be to use java.net.URLEncoder.encode. Contrary to its name, this method applies HTML form encoding, which is similar but far more aggressive, i.e. it escapes additional characters such as /, : etc.

If the authorization URL in the OAuth2 provider configuration contained query parameters with escaped characters, these characters were escaped a second time. This commit fixes it.

It is relevant to support the OIDC claims parameter (see https://openid.net/specs/openid-connect-core-1_0.html#ClaimsParameter).

Fixes gh-7871
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 30, 2020
@manuelbl manuelbl requested a review from jzheaux January 30, 2020 20:23
@jgrandja jgrandja added in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 5, 2020
@jgrandja jgrandja added this to the 5.3.x milestone Feb 5, 2020
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.

Thank you for reporting this @manuelbl and for this PR! Please see my comments.

If the authorization URL in the OAuth2 provider configuration contained query parameters with escaped characters, these characters were escaped a second time. This commit fixes it.

It is relevant to support the OIDC claims parameter (see https://openid.net/specs/openid-connect-core-1_0.html#ClaimsParameter).

Fixes gh-7871
@manuelbl manuelbl requested a review from jgrandja February 6, 2020 21:42
@jgrandja jgrandja modified the milestones: 5.3.x, 5.3.0 Feb 8, 2020
@jgrandja jgrandja self-assigned this Feb 8, 2020
@jgrandja
Copy link
Contributor

jgrandja commented Feb 8, 2020

Thanks again for providing this fix @manuelbl ! This is now in master and backported to 5.2.x.

@jgrandja jgrandja closed this Feb 8, 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) type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Query parameters in authorization-url are double-encoded
3 participants