Regression of #99: '+' in state parameter is corrupted in authorization redirect responses
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 80/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
調査の方向性
server/src/main/java/org/cloudfoundry/identity/uaa/oauth/UaaAuthorizationEndpoint.java の UaaAuthorizationEndpoint.encode() から始め、次に server/src/test/java/org/cloudfoundry/identity/uaa/oauth/UaaAuthorizationEndpointTest.java にある既存のリダイレクトに関するアサーションを確認してください。この issue にはエンコーディングの変更が記載され、回帰テストケースが示されています。state 内の + が %2B として返され、テストでリダイレクト URL が検証されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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");
}
- 主要言語
- Java
- スター
- 1.6k
- フォーク
- 847
- 平均マージ
- 2日 1時間
- マージ済み PR(30日)
- 48
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
cloudfoundry/uaa のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
cloudfoundry/uaa#4189 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
cloudfoundry/uaa#4156 ·
メンテナーはふだん 1 日以内に返信
-
Support named allowed-resource policies for mTLS clients対応中かも @strehle が 24 日前に担当しました。 オープン
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
cloudfoundry/uaa#4125 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
cloudfoundry/uaa#4086 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
cloudfoundry/uaa#3735 ·
メンテナーはふだん 1 日以内に返信
cloudfoundry/uaa の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
testng-team/testng#3672 ·
メンテナーはふだん 1 日以内に返信
-
triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
eclipse-edc/IdentityHub#1296 ·
メンテナーはふだん 1 日以内に返信
-
area: ui priority: medium
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
tetsuji16/microProject#1721 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 2 日以内に返信
-
[Bug] [BanyanDB] timestamp.ParseDuration silently drops everything after "d"対応中かも @soujasK が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
apache/skywalking#14287 ·
メンテナーはふだん 1 日以内に返信