Skip to content

[#714] Match the full OAuth 2.0 redirect URI during authorization and code exchange - #1268

Open
vharseko wants to merge 3 commits into
OpenIdentityPlatform:masterfrom
vharseko:fix/714-oauth2-redirect-uri-query
Open

vharseko wants to merge 3 commits into
OpenIdentityPlatform:masterfrom
vharseko:fix/714-oauth2-redirect-uri-query

Conversation

@vharseko

@vharseko vharseko commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Fixes #714

OpenAM removed the query from the requested redirect URI before comparing it with the registered URI. A client that registered and sent the same callback with a fixed query could therefore get redirect_uri_mismatch. At code exchange, OpenAM removed the query from the URI associated with the authorization code, causing invalid_grant when the client repeated the original URI.

Both checks now compare the complete URI, including the query. Native applications can still use the supported loopback port forms. Clients that previously appended parameters to a registered callback must register the full URI for fixed parameters or associate per-request context with OAuth state. The upgrade guide covers this change.

OpenAM preserves every explicitly registered callback spelling during authorization, including differences in host case and percent-escape hex case. If both spellings are registered, either can be requested and the client must specify which one to use. The same rule applies to callbacks derived from CDSSO agent roots.

For pairwise OIDC clients without a sector_identifier_uri, OpenAM again adds each redirect URI to an initially empty set when choosing the host for the subject identifier. This preserves the sub used by relying parties to identify existing users when registered callbacks contain different spellings of the same host.

Verification

  • All 1,017 tests in openam-oauth2 passed on JDK 11 at 31be36b51f. Regression tests cover both registered spellings, rejection of an unregistered spelling, omission of an ambiguous redirect URI, and callbacks resolved from CDSSO agent roots.
  • The new pairwise regression test also passed on JDK 21. With 13 registered spellings representing 12 distinct URI values, the client receives the same sub as on a502c7a8ac, and the validator accepts both registered spellings of the callback.
  • On the initial commit (a502c7a8ac), two Playwright tests passed against a local OpenAM 16.1.4 container with the two updated classes. The first checked that idp_id=1 survived the redirect and exchanged the code for an access token. The second used that token at the UserInfo endpoint.

@vharseko vharseko added bug javascript Pull requests that update Javascript code oauth2 OAuth2 / OpenID Connect documentation Documentation, README, or javadoc tests Test suite: coverage, fixtures, or test infrastructure java Pull requests that update java code labels Dec 1, 2026
@vharseko
vharseko requested a review from maximthomas December 1, 2026 12:21

@maximthomas maximthomas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

praise: The Playwright case checks that the fixed query survives the authorization redirect and that the same URI works in the code exchange.


issue (blocking): Preserve every explicitly registered callback spelling for exact matching.

RedirectUriValidator.java:70–72

A client can register both https://APP.example.org/callback and https://app.example.org/callback. The profile stores both strings, but the read path converts them to a HashSet<URI>, where Java considers the two spellings equal. The base validator accepted both through URI.equals. The new string comparison sees only the retained spelling and rejects the other with redirect_uri_mismatch. Preserve the registered strings for exact comparison and parse them for loopback port matching. Registration write path · Registration read path · Base validator

Closure criterion — each exact spelling is accepted when both are registered, including fixed queries that differ only in percent-escape hex case. With only one spelling registered, reject an alternate spelling for a non-loopback callback. Keep the existing supported loopback port forms.

maximthomas

This comment was marked as off-topic.

@maximthomas
maximthomas self-requested a review December 1, 2026 13:05

@maximthomas maximthomas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

see the comment below

@vharseko

vharseko commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

@maximthomas, 008d1fb addresses the registered callback spelling issue. The validator and resolver now receive one URI per distinct registered string. This preserves host case and percent-escape hex case for exact matching and retains the existing loopback port rules.

Regression tests exercise both examples from your review. With both spellings registered, either succeeds. With only one registered, the alternate is rejected. Omitting redirect_uri when both are registered also fails. All 1,016 tests in openam-oauth2 passed.

@vharseko
vharseko requested a review from maximthomas December 1, 2026 13:39

@maximthomas maximthomas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

praise: The new tests pass numbered identity attributes through the real client registration and validator, covering both host case and percent-escape hex case.


issue (blocking): Preserve existing pairwise sub values when building the redirect URI set.

OpenAMClientRegistration.java:148–154

For a pairwise client without sector_identifier_uri, getSubValue() can hash the host spelling of the first URI in the set. The previous getter filled a default HashSet incrementally, while the new getter sizes the set from the number of strings before URI.equals deduplicates them. An unchanged profile with 13 registered spellings, 12 distinct URI values and mixed case on the same hostname switched from app.example.org to APP.example.org on JDK 11 and 21, giving the same user a different sub in ID tokens and UserInfo and breaking the relying party’s existing account association. Keep the incremental set construction on the legacy getter used by pairwise subject generation and keep the spelling-preserving collection for validation and resolution. Previous getter · Subject calculation · OIDC claim stability

Closure criterion — the same stored redirect URIs, user and salt produce the same non-null sub as on a502c7a8ac for the mixed-case fixture, with both registered spellings still accepted by the validator.

@vharseko

vharseko commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

@maximthomas, 31be36b restores incremental insertion into the redirect URI set used by getSubValue(). Validation and resolution still use the collection that preserves each registered spelling.

The regression test uses a pairwise client without a sector_identifier_uri, with 13 registered spellings representing 12 distinct URI values. It failed on 008d1fb. With the fix, the same user and salt produce the exact sub issued on a502c7a, and the validator accepts both host spellings. All 1,017 tests in openam-oauth2 passed on JDK 11. The new test also passed on JDK 21.

@vharseko
vharseko requested a review from maximthomas December 1, 2026 14:43

@maximthomas maximthomas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

praise: The regression test pins the previously issued pairwise subject and checks that the same registration accepts both explicit callback spellings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug documentation Documentation, README, or javadoc java Pull requests that update java code javascript Pull requests that update Javascript code oauth2 OAuth2 / OpenID Connect tests Test suite: coverage, fixtures, or test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

About OAuth2.0 Redirection URIs "?" mark

2 participants