Skip to content

Fix NPE in secure-redirect-uris-enforcer during PAR authorization requests - #54053

Open
tatsuya-kurosaka wants to merge 3 commits into
keycloak:mainfrom
tatsuya-kurosaka:issue-53191
Open

tatsuya-kurosaka wants to merge 3 commits into
keycloak:mainfrom
tatsuya-kurosaka:issue-53191

Conversation

@tatsuya-kurosaka

Copy link
Copy Markdown

Closes #53191

Summary

When secure-redirect-uris-enforcer is enabled, PAR authorization requests
may not include redirect_uri in the raw authorization request parameters
during PRE_AUTHORIZATION_REQUEST.

This causes redirect URI validation to be executed with a null value and
results in a failure before the PAR request parameters are resolved.

This change skips redirect URI validation during
PRE_AUTHORIZATION_REQUEST when redirect_uri is not present.

The redirect URI is still validated later during
AUTHORIZATION_REQUEST, where the PAR request has already been resolved
and the effective redirect URI is available.

Changes

  • Skip redirect URI validation when redirect_uri is absent during
    PRE_AUTHORIZATION_REQUEST
  • Add regression test for PAR authorization requests

Verification

Automated

  • Added integration test:
    • testSecureRedirectUrisEnforcerExecutor_parAuthorizationRequest

Manual

Verified the following scenarios with secure-redirect-uris-enforcer enabled.

Valid PAR flow

  1. Register a client with a valid redirect URI
  2. Send a PAR request containing redirect_uri
  3. Send an authorization request containing only:
    • client_id
    • request_uri
  4. Complete login

Result:

  • Authorization request succeeds
  • Authorization code is issued
  • No exception is thrown

Invalid redirect URI

  1. Register a client with a valid redirect URI
  2. Send a PAR request containing an invalid redirect URI
    (or one not permitted by the executor configuration)

Result:

  • Request is rejected
  • Redirect URI validation is still enforced

Copilot AI balanced review requested due to automatic review settings October 16, 2026 08:43
@tatsuya-kurosaka
tatsuya-kurosaka requested review from a team as code owners October 16, 2026 08:43

Copilot AI 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.

🔵 Needs a closer look

It modifies security-sensitive redirect-URI enforcement logic where an incorrect relaxation could enable open-redirect bypasses, so a human should confirm the safety reasoning before approval.

0 open findings

What changed in this PR

This PR fixes a NullPointerException in SecureRedirectUrisEnforcerExecutor that occurred during Pushed Authorization Request (PAR) authorization flows. In a PAR flow, the authorization request sent to the authorization endpoint contains only client_id and request_uri, so redirect_uri is absent from the raw parameters processed during the PRE_AUTHORIZATION_REQUEST client-policy event. The executor previously passed this null value into the URI constructor, throwing an NPE before the request could be resolved. The fix skips the early redirect-URI validation when redirect_uri is not present, relying on the later AUTHORIZATION_REQUEST event (which runs after PAR resolution) to validate the effective redirect URI.

Changes:

  • Guard the PRE_AUTHORIZATION_REQUEST redirect-URI validation with a redirectUriParam != null check.
  • Add an integration regression test covering the end-to-end PAR authorization flow.
File Description
services/​src/​main/​java/​org/​keycloak/​services/​clientpolicy/​executor/​SecureRedirectUrisEnforcerExecutor.java Adds a null check so redirect-URI validation is skipped when redirect_uri is absent during PRE_AUTHORIZATION_REQUEST, deferring enforcement to AUTHORIZATION_REQUEST.
testsuite/​integration-arquillian/​tests/​base/​src/​test/​java/​org/​keycloak/​testsuite/​client/​policies/​SecureRedirectUrisEnforcerExecutorTest.java Adds a regression test verifying a PAR authorization request with only client_id/request_uri succeeds and issues a token without an NPE.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Signed-off-by: Tatsuya Kurosaka <tatsuya.kurosaka.pf@hitachi.com>
@lhanusov

Copy link
Copy Markdown
Contributor

Thanks for the fix! This addresses #53191 while keeping validation of the resolved redirect URI in AUTHORIZATION_REQUEST. Could you also add a negative PAR test where the resolved URI violates the executor policy? That would cover the deferred validation alongside the successful flow.

@lhanusov lhanusov 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.

@tatsuya-kurosaka please check the comment.thanks

Copilot AI balanced review requested due to automatic review settings October 30, 2026 01:54
Signed-off-by: Tatsuya Kurosaka <tatsuya.kurosaka.pf@hitachi.com>

Copilot AI 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.

🟢 Approval recommended

No active review issues were identified for the PAR redirect URI validation change.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 30, 2026 01:57

Copilot AI 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.

🟡 Changes recommended

Both new PAR regression tests were added to the deprecated Arquillian suite and should be moved to the Keycloak Test Framework using its client-policy setup helpers.

1 open issue

Review effort: Balanced

Comment on lines +708 to +709
@Test
public void testSecureRedirectUrisEnforcerExecutor_parAuthorizationRequest() throws Exception {
@tatsuya-kurosaka

Copy link
Copy Markdown
Author

@lhanusov
Thanks for the review. I added a negative PAR test to cover the deferred validation. The test verifies that a redirect URI stored in the PAR is rejected during AUTHORIZATION_REQUEST when it violates the secure redirect URI policy.

@lhanusov

lhanusov commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

@tatsuya-kurosaka
The added negative PAR test addresses my earlier request. Both new tests pass with the fix and reproduce the original NPE when the null check is reverted. Resolved redirect URI enforcement remains intact. This looks ready once functional CI passes and the commits are squashed with the issue reference.

@mposolda can you please trigger the build to have CI results? feel free to re-review, thank you 👍

Copilot AI balanced review requested due to automatic review settings November 12, 2026 12:08

Copilot AI 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.

🟡 Changes recommended

When redirect_uri is omitted, the resolved destination is not validated before error redirects, allowing redirects to a registered URI forbidden by policy.

2 open issues

Review effort: Balanced

throw invalidRedirectUri("Invalid parameter: clientId");
}
if (isAuthFlowWithRedirectEnabled(client)) {
if (redirectUriParam != null && isAuthFlowWithRedirectEnabled(client)) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

secure-redirect-uris-enforcer fails with PAR requests during PRE_AUTHORIZATION_REQUEST

4 participants