Skip to content

Restrict redirect URI loopback exceptions to IP literals - #54527

Merged
mposolda merged 1 commit into
keycloak:mainfrom
lhanusov:fix/54413-literal-loopback-redirects
Nov 16, 2026
Merged

mposolda merged 1 commit into
keycloak:mainfrom
lhanusov:fix/54413-literal-loopback-redirects

Conversation

@lhanusov

@lhanusov lhanusov commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Closes #54413
Co-authored by: Codex noreply@openai.com

Copilot AI balanced review requested due to automatic review settings November 2, 2026 10:07
@lhanusov
lhanusov requested review from a team as code owners November 2, 2026 10:07

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

Missing or invalid response_type values can bypass redirect-URI policy validation, allowing error redirects to previously registered forbidden hostnames.

3 open issues
What changed in this PR

This PR addresses #54413 by restricting redirect-policy loopback exceptions to IP literals, preventing DNS-resolved hostnames from bypassing the permitted-domain allowlist.

Changes:

  • Requires literal IPv4 or IPv6 addresses for loopback exceptions.
  • Adds error-redirect suppression for redirect URI policy rejections.
  • Adds regression coverage, deterministic hostname fixtures, and documentation.
File Description
testsuite/​integration-arquillian/​tests/​base/​src/​test/​java/​org/​keycloak/​testsuite/​client/​policies/​SecureRedirectUrisLoopbackTest.java Adds registration, update, and authorization regression tests.
testsuite/​integration-arquillian/​tests/​base/​src/​test/​java/​org/​keycloak/​testsuite/​client/​policies/​LoopbackAddressResolver.java Verifies hostname fixtures in the server JVM.
testsuite/​integration-arquillian/​README.md Documents regression-test setup and execution.
services/​src/​test/​java/​org/​keycloak/​services/​clientpolicy/​executor/​RedirectLoopbackRegressionTest.java Tests literal classification, allowlists, and OAuth compliance.
services/​src/​main/​java/​org/​keycloak/​services/​clientpolicy/​executor/​SecureRedirectUrisEnforcerExecutorFactory.java Clarifies literal-only behavior in configuration help.
services/​src/​main/​java/​org/​keycloak/​services/​clientpolicy/​executor/​SecureRedirectUrisEnforcerExecutor.java Restricts loopback classification and disables redirects for rejected URIs.
services/​src/​main/​java/​org/​keycloak/​protocol/​oidc/​endpoints/​AuthorizationEndpoint.java Handles policy errors that prohibit redirects with an error page.
server-spi/​src/​main/​java/​org/​keycloak/​services/​clientpolicy/​ClientPolicyException.java Adds an error-redirect permission flag.
docs/​documentation/​server_admin/​topics/​clients/​client-policies.adoc Explains validation behavior and upgrade considerations.
.github/​actions/​update-hosts/​hosts Adds IPv4 and IPv6 loopback hostname fixtures.

Review effort: Balanced

@lhanusov
lhanusov force-pushed the fix/54413-literal-loopback-redirects branch from 72ec6d6 to 82a71e6 Compare November 2, 2026 10:37
Copilot AI balanced review requested due to automatic review settings November 2, 2026 10:37

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

Malformed authorization requests can trigger error redirects before redirect-URI policy validation, allowing redirects to previously registered forbidden hosts.

3 open issues

Review effort: Balanced

@lhanusov
lhanusov force-pushed the fix/54413-literal-loopback-redirects branch from 82a71e6 to 3d1c3b4 Compare November 2, 2026 10:48
Copilot AI balanced review requested due to automatic review settings November 2, 2026 10:48

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

Malformed authorization requests can still reach an error-redirect path before redirect-policy validation, leaving an open redirect to a stored, disallowed hostname.

3 open issues

Review effort: Balanced

@lhanusov
lhanusov force-pushed the fix/54413-literal-loopback-redirects branch from 3d1c3b4 to 4acdaa0 Compare November 2, 2026 10:56
Copilot AI balanced review requested due to automatic review settings November 2, 2026 10:56

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

With a client-protocol condition, requests missing response_type or using an invalid scope can still redirect to forbidden stored URIs before redirect URI policy validation runs.

4 open issues

Review effort: Balanced

@lhanusov
lhanusov force-pushed the fix/54413-literal-loopback-redirects branch from 4acdaa0 to e600eb9 Compare November 2, 2026 11:07
Copilot AI balanced review requested due to automatic review settings November 2, 2026 11:07

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

Earlier error-redirect paths bypass the new policy guard, leaving previously registered, now-disallowed loopback hosts usable as open redirects.

5 open issues

Review effort: Balanced

@lhanusov
lhanusov force-pushed the fix/54413-literal-loopback-redirects branch from e600eb9 to 685fdea Compare November 2, 2026 12:54
Copilot AI balanced review requested due to automatic review settings November 2, 2026 12:54

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

Redirect URI policy enforcement occurs after redirect-capable validation, allowing malformed authorization requests to redirect to previously stored disallowed hosts.

5 open issues

Review effort: Balanced

@lhanusov
lhanusov force-pushed the fix/54413-literal-loopback-redirects branch from 685fdea to 0df16ba Compare November 2, 2026 13:02
Copilot AI balanced review requested due to automatic review settings November 2, 2026 13:02
@lhanusov
lhanusov requested a balanced review from Copilot November 5, 2026 10:05
@lhanusov
lhanusov force-pushed the fix/54413-literal-loopback-redirects branch from c3a05e1 to c86a715 Compare November 5, 2026 10:07

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

Security-sensitive changes to policy evaluation, executor ordering, and PAR/request-object/CIMD error handling require maintainer runtime validation for compatibility because project tests could not run in the review environment.

4 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 5, 2026 10:09

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

The cross-cutting authorization-policy and error-redirect changes require maintainer-run integration validation across PAR, request-object, and CIMD flows, including custom policy compatibility, because integration execution is unavailable here.

4 open issues

Review effort: Balanced

@jimmychakkalakal jimmychakkalakal self-assigned this Nov 5, 2026

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

@lhanusov Thanks for the PR.

This fix properly prevents the DNS loopback bypass.

Rechecking redirect URIs at the OIDC authorization endpoint protects both new and existing clients. It safely covers direct, PAR, and request-object flows.

I also checked the token, refresh, logout, device, and service-account endpoints and confirmed they are safe

Looks good to Me! I approve the changes from myside

@lhanusov

lhanusov commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@mposolda this PR is ready for merge, is it necessary to re-run the build, feel free to re-review again, thank you 👍

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

@lhanusov @jimmychakkalakal Thanks for the PR and review!

I've added inline comments to make classes like DefaultClientPolicyManager and ClientPolicyException to be kept as more generic framework classes without any concrete logic related to concrete executors, redirect uri etc. Hopefully it is possible to keep it like that?

Also a question: Does it worth to document this again in the upgrading guide? I am not 100% sure whether someone rely on the current behavior? Or do you rather consider that current behavior is buggy and does not need to notify people about it at all?

doPolicyOperation(
(ClientPolicyConditionProvider condition) -> condition.applyPolicy(context),
(ClientPolicyExecutorProvider executor) -> executor.executeOnEvent(context),
(ClientPolicyExecutorProvider executor) -> {

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.

Can we avoid having those changes in DefaultClientPolicyManager? The DefaultClientPolicyManager is more a framework class, which ideally should not need to ask instanceof and have any code logic specific to "redirect uri" or concrete contexts and executors inside itself.

The SecureRedirectUrisEnforcerExecutor is the only executor implementing the interface AuthorizationRequestRedirectUriValidator . So considering that, it might be OK to have this inside SecureRedirectUrisEnforcerExecutor.executeOnEvent:

    @Override
    public void executeOnEvent(ClientPolicyContext context) throws ClientPolicyException {
        if (context instanceof AuthorizationRequestRedirectUriContext redirectUriContext) {
            this.validateRedirectUri(redirectUriContext);
        } else {
            .. the code as is now ...
       }

Per my understanding, when this is done, it will have same effect as the code in this PR without a need of introducing interface AuthorizationRequestRedirectUriValidator and without those changes in DefaultClientPolicyManager ?

private String error = OAuthErrorException.INVALID_REQUEST;
private String errorDetail ="NA";
private Status errorStatus = Response.Status.BAD_REQUEST;
private boolean errorRedirectAllowed = true;

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.

Instead of errorRedirectAllowed, is it possible to have something more "generic" like private Map<String, Object> details = new HashMap<>();

And then perhaps introduce something to the Constants like ERROR_REDIRECT_ALLOWED and then in the AuthorizationEndpoint something like if exception.containsKey(Constants.ERROR_REDIRECT_ALLOWED) && exception.get(Constants.ERROR_REDIRECT_ALLOWED)) instead of if (exception.isRedirectAllowed()) .

My point is similar like other comment for DefaultClientPolicyManager : It would be good to keep ClientPolicyException as a generic framework class, which would not have any stuff specific to "redirect uri" or "authorization endpoint" or concrete executors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@mposolda Thanks Marek, I agree with keeping the framework classes generic. I propose moving dispatch into the executor and replacing the exception flag with generic details. I’ll also make RejectRequestExecutor skip the early validation event to preserve OAuth error redirects for allowed callbacks. An upgrade note makes sense because existing registrations can be affected.

@mposolda mposolda self-assigned this Nov 11, 2026
@lhanusov
lhanusov force-pushed the fix/54413-literal-loopback-redirects branch from c86a715 to e84276c Compare November 13, 2026 09:11
Copilot AI balanced review requested due to automatic review settings November 13, 2026 09:11

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

The flow-disabled guard bypasses redirect-policy validation, allowing unauthorized_client errors to redirect to registered callbacks whose hostnames are forbidden by the allowlist.

1 open issue
4 resolved since last review

Review effort: Balanced

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

@lhanusov Thanks for the updates! I am just not sure about copilot warning... Could you please check it?

@lhanusov
lhanusov force-pushed the fix/54413-literal-loopback-redirects branch from e84276c to 6910f8b Compare November 13, 2026 11:32
Copilot AI balanced review requested due to automatic review settings November 13, 2026 11:32
@lhanusov
lhanusov force-pushed the fix/54413-literal-loopback-redirects branch from 6910f8b to ae1c789 Compare November 13, 2026 11:33

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

The new OIDC policy-dispatch event changes security-sensitive error routing, warranting maintainer review of custom extension compatibility and integration behavior across authorization flows.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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

@lhanusov Thanks! Rebasing (hopefully that helps with "SAST" failure).

Signed-off-by: Lukas Hanusovsky <lhanusov@redhat.com>
@mposolda
mposolda force-pushed the fix/54413-literal-loopback-redirects branch from ae1c789 to baaceb9 Compare November 16, 2026 10:56
Copilot AI balanced review requested due to automatic review settings November 16, 2026 10:56

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 block the change restricting redirect URI loopback exceptions to literal IP addresses.

No open issues 🎉

Review effort: Balanced

@mposolda
mposolda merged commit 8a55a44 into keycloak:main Nov 16, 2026
100 of 170 checks passed
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.

[CVE-2026-118425] Redirect URI Domain Allowlist Bypass

4 participants