Skip to content
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

Re-authenticate users if the OIDC session cookie can not be read #46822

Conversation

sberyozkin
Copy link
Member

Fixes #46765.

The internal session cookie format changed in 3.18, which, given it is not part of the API, should not have caused any issues. However, in advanced OIDC applications, what happens, as explained by @sschellh, is that there could be a large number of currently logged in users possibly in different regions, which have not had time to logout before the new Quarkus release is deployed. thus keeping the existing session cookies.

For example, a user logged in the morning, the session is active for 8 hours, new Quarkus is deployed at lunch time, and the user can not access the application after lunch.

In such cases, if the internal session format changes, currently, Quarkus, after failing to parse the cookie content, stops users in their tracks with 401 which is not a good user experience.

Instead, Quarkus should remove the session cookie it can not parse and request re-authentication - the user may not even notice if the OIDC provider's own session cookies still valid.

This is what this simple PR does - deletes the session cookie (this is already done on main and tested) but instead of terminating the flow with 401, it forces the re-authentication with 302.

// Make this error message visible in the dev mode
return Uni.createFrom().failure(new AuthenticationFailedException(error));
} catch (NumberFormatException ex) {
final String error = "Access token expires_in property in the session cookie must be a number";
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice if we had the value that was found, for debugging purposes

Suggested change
final String error = "Access token expires_in property in the session cookie must be a number";
final String error = "Access token expires_in property in the session cookie must be a number, found %s";

Copy link
Member Author

@sberyozkin sberyozkin Mar 14, 2025

Choose a reason for hiding this comment

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

@gastaldi Sure, took me a little while to experiment with getting to that value from different branches, so I wrapped the actual parsing call in a function to make it easier, hope it looks better

Copy link
Contributor

@gastaldi gastaldi left a comment

Choose a reason for hiding this comment

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

Approved, but I wonder if we can improve that error message with some useful data

This comment has been minimized.

@sberyozkin sberyozkin force-pushed the reauth_when_session_cookie_can_not_be_read branch from d5bc3a5 to 3b248a5 Compare March 14, 2025 16:11
Copy link

quarkus-bot bot commented Mar 14, 2025

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit 3b248a5.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.

@sberyozkin sberyozkin merged commit 3cc4d38 into quarkusio:main Mar 14, 2025
27 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.22 - main milestone Mar 14, 2025
@sberyozkin sberyozkin deleted the reauth_when_session_cookie_can_not_be_read branch March 14, 2025 16:53
@gsmet gsmet modified the milestones: 3.22 - main, 3.21.0 Mar 18, 2025
@gsmet gsmet modified the milestones: 3.21.0, 3.19.4 Mar 18, 2025
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.

OIDC session cookie format changed in 3.18 causing it to be incompatible to 3.17.x
3 participants