Repository navigation
Do not complete login from a consent request without a valid session code - #55398
huyenvu2101 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
This authentication-boundary change requires maintainer security review and end-to-end validation of consent and pending required-action flows, which could not be executed in this environment.
No open issues 🎉
What changed in this PR
This PR addresses #55375 by preventing consent requests without a valid session code from bypassing pending required actions and completing login.
Changes:
- Reads the consent form’s
codeparameter, withsession_codeas a compatibility fallback. - Resumes pending actions rather than granting consent when the request is not a validated action submission.
- Adds regression tests for missing and invalid codes, including clients with and without required consent.
| File | Description |
|---|---|
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/oauth/OAuthGrantTest.java |
Adds required-action bypass regression tests and cleanup. |
services/src/main/java/org/keycloak/services/resources/LoginActionsService.java |
Corrects consent code lookup and guards consent processing. |
Review effort: Balanced
gaoyikeshuer
left a comment
There was a problem hiding this comment.
Hi @huyenvu2101 , thanks for this PR, I agree with the fix, just have some comments in your test file.
| events.clear(); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
could we add one more test for a valid session code taken from a different required action?
| Assertions.assertTrue(user.toRepresentation().getRequiredActions().contains(UserModel.RequiredAction.UPDATE_PASSWORD.name())); | ||
| Assertions.assertTrue(user.getUserSessions().isEmpty()); | ||
| Assertions.assertTrue(user.getConsents().isEmpty()); | ||
| } finally { |
There was a problem hiding this comment.
could we not use try/finally. the rest of this class uses getCleanup()
| StringBuilder script = new StringBuilder("var form = document.createElement('form');") | ||
| .append("document.body.appendChild(form);") | ||
| .append("form.method = 'POST';") | ||
| .append("form.action = arguments[0];"); | ||
| if (sessionCode != null) { | ||
| script.append("var input = document.createElement('input');") | ||
| .append("input.type = 'hidden';") | ||
| .append("input.name = 'code';") | ||
| .append("input.value = arguments[1];") | ||
| .append("form.appendChild(input);"); | ||
| } | ||
| script.append("form.submit();"); |
There was a problem hiding this comment.
this part a bit awkward, maybe is there any better way to shorten it
|
Thanks for the review @gaoyikeshuer, I just updated the PR please take a look again |
|
Hi @huyenvu2101 , could you squash those commits into one as well? with the format git commit -m "your commit message" -m "Closes #55375" |
a7a36ce to
9ea3e86
Compare
mabartos
left a comment
There was a problem hiding this comment.
@huyenvu2101 Thanks! Nice work!
I think the session_code is a correct way of naming, and also consisent with other templates.
I think you should:
- Change the
codeparam tosession_codein thelogin-oauth-grant.ftl - Accept
codefallback on the server
Proceed also with suggestions from @gaoyikeshuer
WDYT?
3c2546c to
98afc55
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The tests lack assertions that missing-code submissions preserve a usable password-update page and regression coverage proving consent cannot be granted or a session created without a valid code.
2 open issues
Review effort: Balanced
| if (!checks.isActionRequest()) { | ||
| // Request without a session code is not a consent submission, the action matching the consent screen | ||
| // was not verified. Continue with whatever is pending instead of granting the consent. | ||
| return AuthenticationManager.nextActionAfterAuthentication(session, authSession, clientConnection, request, session.getContext().getUri(), event); |
…code The consent form submitted the session code as "code", but the consent endpoint read "session_code", so every consent submission was handled as a page refresh and skipped the check that the consent screen is the current required action. A POST to login-actions/consent therefore completed the login while other required actions were still pending. Submit the session code as "session_code" in the consent form, like the other templates, and still accept "code" from custom themes based on the previous template. Continue with the pending action instead of granting consent when a request comes without a valid session code. Closes keycloak#55375 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TXuEjESUj73Z9jWF5m8TTg Signed-off-by: huyenvu2101 <vhuyen2101@gmail.com>
98afc55 to
6f9825d
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
The security-sensitive login transition requires live integration validation of missing or invalid codes, pending required actions, and legacy-theme consent submissions, but only static review was possible.
1 resolved since last review
Review effort: Balanced
Closes #55375
The consent form posts the session code as
code, but since 5ea4ef9 the consent endpoint readssession_code, so every consent submission was treated as a page refresh and the required-action check never ran.Decisions and assumptions:
code, fall back tosession_code) rather than inlogin-oauth-grant.ftl, so custom themes copied from the base template keep working.processRequireActionhandles refreshes.verifyRequiredActionis left unchanged, as GET refreshes of other required-action pages rely on its current behavior.The fix and tests were written with the help of an AI agent (Claude Code).
🤖 Generated with Claude Code