fix: Identity providers should not be hidden from login page when the user goes back from the reset credentials page - #48814
Conversation
0d11bb6 to
abaabbc
Compare
|
Is it possible that the failing test ( If it's not flaky, can you help me reproduce the failure? Apart from that I fixed all failing tests. |
|
After opening this PR, I worked on another PR that initially failed CI because I added tests to the old test framework instead of the new one. The tests in this PR were originally rebased from my ~2-year-old unfinished PR. Given that, do you think I should rewrite these newly added tests using the new test framework instead? I’d rather not migrate the existing tests that I only had to touch because the flow changed slightly, since that would make it harder to follow their lifecycle/history. What do you think, @mabartos? I'm happy to do that if it would help. |
|
@vilmosnagy Thanks for the PR! The old testsuite is deprecated, and we should not add another tests there if possible. Please try to find a relevant test in the new testsuite, and add the additional test cases. If there's none, it'd be good to create a new one there with the same/similar name, and the rest of the test cases will be migrated afterwards. I'll review the core fix logic introduced in this PR later. |
e33dc33 to
14a22aa
Compare
@mabartos I migrated all the newly added tests to the new test framework. We should squash all the commits at the end for simplicity, but I tried to be as detailed as possible in this phase. I didn't find a one-to-one mapping between the old test suite and the new test framework's files, so I created a The commits are currently in this order:
|
|
Should I do anything more here @mabartos ? Should I regurarly rebase this branch? |
|
@vilmosnagy Sorry, didn't have time to look at it yet. Could you please rebase once again? Seems these CI failures cannot be resolved by retries. |
14a22aa to
6c6946b
Compare
|
let me try. as far as I remember they passed before my last change - and my last change only migrated the new tests to the new testframework. |
|
@mabartos I think the failing test |
6c6946b to
d6548c9
Compare
d6548c9 to
ef96355
Compare
|
@mabartos I rebased this PR, and my understanding about the tests:
Could you please take a look? Thanks. |
Signed-off-by: Vilmos Nagy <me@vnagy.eu>
…work. Signed-off-by: Vilmos Nagy <me@vnagy.eu>
Signed-off-by: Vilmos Nagy <me@vnagy.eu>
…ehaviour Signed-off-by: Vilmos Nagy <me@vnagy.eu> # Conflicts: # testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/forms/RegisterTest.java
- Clear the RESET_CREDENTIAL_USER_CHOSEN auth note after clearing the user, so subsequent login page renders do not redundantly clear again (feedback from @mposolda in keycloak#33254) - Add ResetPasswordTest::resetPasswordEmailLinkWorksAfterNavigatingBackToLoginPage to verify that the password reset email link still works after the user navigates back to the login page, covering the scenario raised in the review discussion of keycloak#33254 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Vilmos Nagy <me@vnagy.eu>
They were already rewritten to the new test framework with the same name. Signed-off-by: Vilmos Nagy <me@vnagy.eu>
ef96355 to
4d3286c
Compare
There was a problem hiding this comment.
LGTM, thanks!
@rmartinc Do you want to review this small PR as well that avoids some sort of user enumeration? Thanks!
Case:
If the login page changes (for instance, if one or more identity providers become hidden), this indicates that the tested username exists in the realm (and only linked the visible identity providers to their account).
rmartinc
left a comment
There was a problem hiding this comment.
Thanks @vilmosnagy and @mabartos! LGTM!
… user goes back from the reset credentials page (keycloak#48814) * keycloak#33204 add the failing test Signed-off-by: Vilmos Nagy <me@vnagy.eu> * keycloak#33204 Migrated tests from the old testsuite to the new framework. Signed-off-by: Vilmos Nagy <me@vnagy.eu> * keycloak#33204 possible fix (?) Signed-off-by: Vilmos Nagy <me@vnagy.eu> * keycloak#33204 refactor the previous tests to work with the changed behaviour Signed-off-by: Vilmos Nagy <me@vnagy.eu> # Conflicts: # testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/forms/RegisterTest.java * keycloak#33204 add test and address review feedback from keycloak#33254 - Clear the RESET_CREDENTIAL_USER_CHOSEN auth note after clearing the user, so subsequent login page renders do not redundantly clear again (feedback from @mposolda in keycloak#33254) - Add ResetPasswordTest::resetPasswordEmailLinkWorksAfterNavigatingBackToLoginPage to verify that the password reset email link still works after the user navigates back to the login page, covering the scenario raised in the review discussion of keycloak#33254 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Vilmos Nagy <me@vnagy.eu> * Remove the tests added for this PR from the old testsuite. They were already rewritten to the new test framework with the same name. Signed-off-by: Vilmos Nagy <me@vnagy.eu> --------- Signed-off-by: Vilmos Nagy <me@vnagy.eu> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Reopens #33254, closes #33204.
First of all, sorry for disappearing — a newborn arrived ~1.5 years ago and I never found the time to get back to this. Big thanks to @mposolda for keeping the previous PR open as long as he did.
I rebased the commits from #33254 and verified that the tests from last year still fail against the current
mainbranch, so the issue is still present and the fix is still needed. I also tried to address the review discussion from last year. Specifically:RESET_CREDENTIAL_USER_CHOSENauth note after callingcontext.clearUser(), so that subsequent renders of the login page within the same auth session don't needlessly clear the user again.ResetPasswordTest::resetPasswordEmailLinkWorksAfterNavigatingBackToLoginPageto cover the scenario @mposolda raised: the user initiates a password reset, navigates back to the login page (which now clears the user from the auth session), and then clicks the email link. The test verifies the reset flow still completes successfully — it seems that a user who navigates back and then clicks the email link can still change their password and get logged in, which appears fine from a security standpoint. This test was roughly half AI-generated and half hand-reworked, using the tests I wrote for the previous PR as reference — all other code in this PR is hand-written from last year.What the fix does
When a user submits a username on the "Forgot Password?" page, Keycloak sets that user on the authentication session. If the user then navigates back to the login page without completing the reset flow, Keycloak was showing only the identity providers linked to that specific user's account — leaking which social providers they had connected, which is a user enumeration vulnerability per the OWASP Forgot Password Cheat Sheet.
The fix detects the
RESET_CREDENTIAL_USER_CHOSENauth note inUsernamePasswordFormand clears the user from context before rendering the login page, so all configured IDPs are shown regardless of which user was identified during the reset flow.