Regression of #99: '+' in state parameter is corrupted in authorization redirect responses
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 80/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- authentication, backend
Research direction
Start with UaaAuthorizationEndpoint.encode() in server/src/main/java/org/cloudfoundry/identity/uaa/oauth/UaaAuthorizationEndpoint.java, then review the existing redirect assertions in server/src/test/java/org/cloudfoundry/identity/uaa/oauth/UaaAuthorizationEndpointTest.java. The issue describes the encoding change and provides a regression test case. Done when a + in state is returned as %2B and the test verifies the redirect URL.
Written by the indexing model from the issue text.
Description
What version of UAA are you running?
Reproducible on current develop — the relevant code in
UaaAuthorizationEndpoint.encode() uses UriUtils.encodeQueryParam, which does not percent-encode +.
How are you deploying the UAA?
- locally only using gradlew (also observed in a production deployment)
What did you do?
Started an authorization code flow where the client-generated state contains a
properly percent-encoded + (e.g. standard Base64 output):
GET /oauth/authorize?client_id=login&response_type=code&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&state=a%2Bb
What did you expect to see?
The redirect back to the client should return the state with the + still
percent-encoded, so that form-urlencoded decoding restores the original value:
Location: https://example.com/callback?code=...&state=a%2Bb
RFC 6749 (Section 4.1.2 / Appendix B) requires authorization response parameters
to be serialized using the application/x-www-form-urlencoded format, in which a
literal + represents a space and a plus sign must be encoded as %2B.
What did you see instead?
Location: https://example.com/callback?code=...&state=a+b
Note the asymmetry: = is encoded (%3D) but + is not. The client's
form-urlencoded decoding (browsers, servlet containers, standard OAuth client
libraries) turns + into a space, so the client receives "a b" and state
validation fails, breaking the login flow.
Root cause: UaaAuthorizationEndpoint.encode() delegates to Spring's
UriUtils.encodeQueryParam, which implements lenient RFC 3986 query encoding.
+ is a sub-delim that is legal in a query string, so it is left as-is — but
it is ambiguous under the form-urlencoded rules mandated by RFC 6749.
This is a regression of #99 (fixed in 2014 via
spring-projects/spring-security-oauth#152, which used strict URI-variable
encoding). The bug returned when AuthorizationEndpoint was vendored into
UaaAuthorizationEndpoint and the redirect building switched to
UriUtils.encodeQueryParam. The existing test assertion
contains("access_token=TOKEN_VALUE+%3D") in UaaAuthorizationEndpointTest
pins the incorrect half-encoded behavior.
It rarely surfaces in practice because most clients generate state as
base64url/hex/UUID (no +), but any client using standard Base64 state is
broken.
Fix:
In class server/src/main/java/org/cloudfoundry/identity/uaa/oauth/UaaAuthorizationEndpoint.java
Update the method as
private String encode(String value) {
// RFC 3986 allows a literal '+' in a query, but RFC 6749 redirect params
// are form-urlencoded where '+' means space - so encode '+' as '%2B'
// (https://github.com/cloudfoundry/uaa/issues/99)
return value == null ? null : UriUtils.encodeQueryParam(value, "UTF-8").replace("+", "%2B");
}
Test case
server/src/test/java/org/cloudfoundry/identity/uaa/oauth/UaaAuthorizationEndpointTest.java
@Test
void approvePercentEncodesPlusSignInState() {
AuthorizationRequest authorizationRequest = getAuthorizationRequest(
"foo", "http://anywhere.com", "+Jse6b2trAEcoPElv+ftGQ==", "read", Collections.singleton("code"));
model.put(UaaAuthorizationEndpoint.AUTHORIZATION_REQUEST, authorizationRequest);
model.put(UaaAuthorizationEndpoint.ORIGINAL_AUTHORIZATION_REQUEST, uaaAuthorizationEndpoint.unmodifiableMap(authorizationRequest));
Map<String, String> approvalParameters = new HashMap<>();
approvalParameters.put("user_oauth_approval", "true");
when(authorizationCodeServices.createAuthorizationCode(any(OAuth2Authentication.class))).thenReturn("code");
View view = uaaAuthorizationEndpoint.approveOrDeny(approvalParameters, model, sessionStatus, principal);
assertThat(view).isInstanceOf(RedirectView.class);
assertThat(((RedirectView) view).getUrl())
.contains("state=%2BJse6b2trAEcoPElv%2BftGQ%3D%3D");
}
- Dominant language
- Java
- Stars
- 1.6k
- Forks
- 847
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 48
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cloudfoundry/uaa
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
cloudfoundry/uaa#4189 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
cloudfoundry/uaa#4156 ·
Maintainers usually reply within 1 day
-
Support named allowed-resource policies for mTLS clientsPossibly taken @strehle claimed this 24 days ago. Open
Difficulty 5/5 Over a week Newbie friendliness 35/100
cloudfoundry/uaa#4125 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
cloudfoundry/uaa#4086 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
cloudfoundry/uaa#3735 ·
Maintainers usually reply within 1 day
All issues in cloudfoundry/uaa
Similar issues
-
triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
eclipse-edc/IdentityHub#1296 ·
Maintainers usually reply within 1 day
-
area: ui priority: medium
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
tetsuji16/microProject#1721 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 2 days
-
The engine's "loaded, but had errors" message leaves out which library and line each error is inOpen
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
cqframework/clinical_quality_language#1980 ·
Maintainers usually reply within 3 days
-
windows-sys 0.101.0Open
Difficulty 2/5 1-3 hours Newbie friendliness 61/100