8000 Redirect using client data when the session has expired by graziang · Pull Request #39330 · keycloak/keycloak · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Redirect using client data when the session has expired #39330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 15, 2025

Conversation

graziang
Copy link
Contributor

Closes #36150

When the authentication session doesn't exist and it's restarted using the KC_RESTART cookie, with this PR the redirect_uri is taken from the client_data parameter of the restart endpoint (which belongs to the tab) instead of from the value inside the KC_RESTART cookie, which is shared across tabs.

I'm not sure if there are any security implications with this approach, since KC_RESTART is encrypted and not accessible from javascript, instead client_data is only Base64-encoded and accessible via javascript so the redirect_uri could potentially be injected but it still needs to be one of the allowed values.

@mposolda mposolda self-assigned this Apr 29, 2025
Copy link
Contributor
@mposolda mposolda left a comment

Choose a reason for hiding this comment

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

@graziang Thanks for the PR and sorry for late review. Added few review comments. Can you check those?

//set redirect uri from client data parameter
try {
ClientData clientData = ClientData.decodeClientDataFromParameter(clientDataString);
authSession.setRedirectUri(clientData.getRedirectUri());
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to me that this approach can have other issues as redirectUri can belong to completely different client. For example in tab1, there could be client1 and in tab2 there could be client2, which has completely different redirect urls.

There is one point that if client_data parameter is present, there should be also client_id parameter present. We can check if client_id from the parameter is the same as the client_id from the KC_RESTART cookie. If it is same:

  • We can replace redirect_uri but also other things, which are available from clientData (like state, responseMode, responseType)
  • If clientId parameter is not the same like the one from cookie, we either should not replace anything OR we should maybe skip restart from the cookie at all as it is obvious that KC_RESTART cookie was created for different browser tab than the current tab.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The check that compares the client_id in the request param with the client_id in the KC_RESTART cookie is already done here:
https://github.com/keycloak/keycloak/blob/main/services/src/main/java/org/keycloak/protocol/RestartLoginCookie.java#L155
So the behavior should not change, if the client_ids are different the restart from cookie will be skipped. Working on replacing the other claims from clientData.

@@ -727,6 +727,54 @@ public void testLoginPageRefresh() {
}
}

@Test
public void testRedirectToCorrectUrlAfterAuthSessionExpiration() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to add automated tests also for some other scenarios? Like for example the scenarios like:

  • Fake client_data is injected with the incorrect redirect_uri. In this case, we should check that redirect did not happened
  • Maybe test with multiple different clients in two browser tabs (in this case, the redirectUri either should not be rewritten or the restart from cookie should not happen at all if we do the same what I did in other comment).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm working on adding tests, I'm having some trouble testing the replacement of the client_data, because it would require replacing the parameter in the authenticate browser form inside the login page, so far, I haven't found a way to do that

Copy link
Contributor

Choose a reason for hiding this comment

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

graziang added 2 commits May 8, 2025 11:57
Closes keycloak#36150

Signed-off-by: Giuseppe Graziano <g.graziano94@gmail.com>
Closes keycloak#36150

Signed-off-by: Giuseppe Graziano <g.graziano94@gmail.com>
Copy link
Contributor
@mposolda mposolda left a comment

Choose a reason for hiding this comment

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

@graziang Thanks for the updates!

@mposolda mposolda merged commit 6007dc9 into keycloak:main May 15, 2025
76 checks passed
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.

wrong redirect after login timeout for parallel logins
2 participants
0