Skip to content

[OAuth] Prefer authorization error on redirect_uri#48553

Open
tdiesler wants to merge 1 commit intokeycloak:mainfrom
tdiesler:ghi48542
Open

[OAuth] Prefer authorization error on redirect_uri#48553
tdiesler wants to merge 1 commit intokeycloak:mainfrom
tdiesler:ghi48542

Conversation

@tdiesler
Copy link
Copy Markdown
Contributor

@tdiesler tdiesler commented Apr 28, 2026

closes #48542

This PR tries to be as unintrusive as possible. While processing an authorization request there are potential errors coming from

  1. checks in client policies
  2. various request parsers (e.g. url query, request object, request_uri)
  3. checks on request_uri, response_type, response_mode

most of these errors map to an unchecked ErrorPageException, which then displays an html error page.

When the request passes the above, errors tend to be reported back to the caller via redirect_uri already.

This PR proposes to first catch these ErrorPageExceptions and then (when configured to do so) make a "best effort" to use the redirect_uri path - otherwise, the error is returned to the caller as json object.

Without the authorization.preferErrorOnRedirect attribute on the realm, this PR changes nothing. As a result, no test cases needed to be touched. That was in fact the hard bit: change nothing, unless the headless error path is wanted.

Automated conformance tests are headless - they prefer errors to be delivered on the redirect_uri when possible.

If this approach gets accepted, we would likely want to expose that switch on the admin UI, which is not (yet) part of this PR.

This PR is at the bottom of all other HAIP conformance work.

@tdiesler tdiesler changed the title [OAuth] Avoid error page when redirect to client is possible/configured [OAuth] Avoid error page when redirect to client is possible Apr 28, 2026
Copy link
Copy Markdown

@keycloak-github-bot keycloak-github-bot Bot left a comment

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.adapter.servlet.SAMLLoginResponseHandlingTest#testAttributes

Keycloak CI - Adapter IT Strict Cookies

org.openqa.selenium.JavascriptException: 
TypeError: can't access property "outerHTML", document.documentElement is null
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.17.0-1011-azure', java.version: '21.0.11'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
...

Report flaky test

@tdiesler tdiesler force-pushed the ghi48542 branch 9 times, most recently from 2c3c43a to 6927d2a Compare April 29, 2026 03:33
@tdiesler tdiesler changed the title [OAuth] Avoid error page when redirect to client is possible [OAuth] Avoid error page in headless environments Apr 29, 2026
@tdiesler tdiesler force-pushed the ghi48542 branch 3 times, most recently from 64cf932 to b2ea215 Compare April 29, 2026 05:33
Copy link
Copy Markdown

@keycloak-github-bot keycloak-github-bot Bot left a comment

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.model.user.UserModelTest#testAddRemoveUser

Keycloak CI - Store Model Tests

org.opentest4j.MultipleFailuresError: 
Multiple Failures (2 failures)
	java.lang.NullPointerException: Cannot invoke "org.keycloak.models.KeycloakSessionFactory.create()" because "factory" is null
	java.lang.NullPointerException: Null keys are not supported!
	Suppressed: java.lang.NullPointerException: Cannot invoke "org.keycloak.models.KeycloakSessionFactory.create()" because "factory" is null
...

Report flaky test

@tdiesler tdiesler force-pushed the ghi48542 branch 10 times, most recently from 4853bfb to 1a960a5 Compare May 4, 2026 09:12
@tdiesler tdiesler marked this pull request as draft May 4, 2026 09:32
@tdiesler tdiesler force-pushed the ghi48542 branch 2 times, most recently from 3d081eb to 0d1663e Compare May 4, 2026 11:53
Copy link
Copy Markdown

@keycloak-github-bot keycloak-github-bot Bot left a comment

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.forms.BruteForceTest#testNoFailureResetForPermanentLockout

Keycloak CI - Base IT (5)

org.opentest4j.AssertionFailedError: Expected error event ==> expected: <true> but was: <false>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
...

Report flaky test

event.detail(Details.CLIENT_POLICY_ERROR, cpe.getError());
event.detail(Details.CLIENT_POLICY_ERROR_DETAIL, cpe.getErrorDetail());
event.error(cpe.getError());
throw new ErrorPageException(session, authenticationSession, cpe.getErrorStatus(), cpe.getErrorDetail());
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.

cpe.getError() gets lost here, so a client policy raising a different OAuth error code than invalid_request will always be overridden by invalid_request now?

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.

Yes, this is how the translation from ClientPolicyException => ErrorPageException works. Perhaps the html error page does not show the error property from the CPE. This code path has not changed.

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.

This has been fixed - the error code coming from ErrorPageException and AuthorizationCheckException are now passed on correctly.

@tdiesler tdiesler force-pushed the ghi48542 branch 5 times, most recently from 508875f to b40195a Compare May 7, 2026 08:39
Signed-off-by: Thomas Diesler <tdiesler@proton.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OAuth] Prefer authorization error on redirect_uri

2 participants