Repository navigation
Do not complete login from a consent request without a valid session code - #55398
huyenvu2101 wants to merge 2 commits 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
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" |
…code The consent form submits 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. Read the code from the field the form sends, and 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>
a7a36ce to
9ea3e86
Compare
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?
…tionsService.java Co-authored-by: Martin Bartoš <mabartos@redhat.com> Signed-off-by: Vũ Thị Huyền <vhuyen2101@gmail.com>
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