Repository navigation
Conversation
|
Pinging @jonkoops as you have triaged the original issue and asked for community help. |
|
Yes, I'll make some time to get this reviewed. Thanks for the detailed information @t-tani, that helps us a lot. |
|
Looks like some tests failed, so I did a quick rebase to make sure we're not just flaking out here. Let's see what the CI does. |
|
Looks like the failures are consistent, @t-tani could you take a look and see why they are failing? |
Signed-off-by: t-tani <31282248+t-tani@users.noreply.github.com>
|
I apologize, but after investigating the test results, I discovered that the proposed fix was not effective. The KC_RESTART cookie has the http-only attribute, which means it cannot be accessed via JavaScript. As a result, the validation was not working as intended. With the current implementation, I couldn't think of any solution other than addressing the issue of |
|
I will close this pull request. If we come up with any good ideas to fix the issue, I'll reopen this pull request. |
|
If the |
|
After testing, I've determined that using KC_RESTART does not resolve this issue. Test procedure:
Failed tests:
Root cause: Conclusion: |
Issue
Closes #33071
Unexpected requests to
/realms/{realm_name}/login-actions/restartare causing RESTART_AUTHENTICATION_ERROR. This error overrides the OIDC client state (particularly affecting Cloudflare Zero Trust service) and can trigger CODE_TO_TOKEN_ERROR, resulting in unexpected unauthenticated errors.Note: The occurrence of CODE_TO_TOKEN_ERROR is inconsistent and depends on the timing of the request to
/realms/{realm_name}/login-actions/restart.Root Cause
The
checkCookiesAndSetTimerfunction inthemes/src/main/resources/theme/base/login/resources/js/authChecker.jsis not properly unloaded or cleared in the browser, leading to unexpected execution. This issue has been reproduced on iOS Safari and Google Chrome.Comparison of network logs between environments where the problem does not occur (PC) and where it does (mobile) reveals an unexpected
/realms/teamv/login-actions/restartrequest being sent.Tested Environment
Test Cases
The following test cases were conducted using Passkey authentication on the default theme UI, with requests analyzed through a local proxy.
Test Case 1: Success (No error)
Environment:
Normal authentication flow:
/realms/{realm_name}/protocol/openid-connect/auth(200 OK)checkCookiesAndSetTimer/realms/{realm_name}/login-actions/authenticate(input use 8000 rname) (200 OK)checkCookiesAndSetTimer/realms/{realm_name}/login-actions/authenticate(input credentials) (302 Found)/cdn-cgi/access/callback(302 Found)/cdn-cgi/access/authorized(302 Found)Test Case 2: Failure (RESTART_AUTHENTICATION_ERROR)
Environment:
Flow with RESTART_AUTHENTICATION_ERROR:
/realms/{realm_name}/protocol/openid-connect/auth(200 OK)checkCookiesAndSetTimer/realms/{realm_name}/login-actions/authenticate(input username) (200 OK)checkCookiesAndSetTimer/realms/{realm_name}/login-actions/authenticate(input credentials) (302 Found)/cdn-cgi/access/callback(302 Found)/cdn-cgi/access/authorized(302 Found)/realms/{realm_name}/login-actions/restart-> RESTART_AUTHENTICATION_ERRORWeb inspector analysis suggests that the timer unload code is not executed at the expected timing on iOS browsers:
It appears the root cause was the
beforeunloadevent not functioning correctly in iOS browsers. While the documentation at https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event states that it's supported, in practice, it wasn't working as expected.As a result, the restart request is invoked by the checkCookiesAndSetTimer function, even though the KC_RESTART cookie has already been cleared by valid authentication. This function/timer event is expected to be cleared after a valid authentication but does not in the case of access from iOS browsers.
Proposed Solution
Add validation before redirect to prevent unintended restart requests, as there should be no case where
login-actions/restartis called without the KC_RESTART cookie being set.Post-Fix Testing
Confirmed that the RESTART_AUTHENTICATION_ERROR no longer reproduces on iOS browsers after the fix.
Relevant Code for
login-actions/restartpublic static AuthenticationSessionModel restartSession: RestartLoginCookie.java#L142