Repository navigation
Restrict redirect URI loopback exceptions to IP literals - #54527
Conversation
There was a problem hiding this comment.
🟡 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
72ec6d6 to
82a71e6
Compare
82a71e6 to
3d1c3b4
Compare
3d1c3b4 to
4acdaa0
Compare
4acdaa0 to
e600eb9
Compare
e600eb9 to
685fdea
Compare
685fdea to
0df16ba
Compare
c3a05e1 to
c86a715
Compare
There was a problem hiding this comment.
🔵 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
There was a problem hiding this comment.
🔵 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
left a comment
There was a problem hiding this comment.
@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
|
@mposolda this PR is ready for merge, is it necessary to re-run the build, feel free to re-review again, thank you 👍 |
mposolda
left a comment
There was a problem hiding this comment.
@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) -> { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
c86a715 to
e84276c
Compare
There was a problem hiding this comment.
🟡 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
e84276c to
6910f8b
Compare
6910f8b to
ae1c789
Compare
There was a problem hiding this comment.
🔵 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
Signed-off-by: Lukas Hanusovsky <lhanusov@redhat.com>
ae1c789 to
baaceb9
Compare


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