8000 Do not complete login from a consent request without a valid session code by huyenvu2101 · Pull Request #55398 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Do not complete login from a consent request without a valid session code - #55398

Open
huyenvu2101 wants to merge 2 commits into
keycloak:mainfrom
huyenvu2101:fix-55375-consent-required-action-bypass
Open

huyenvu2101 wants to merge 2 commits into
keycloak:mainfrom
huyenvu2101:fix-55375-consent-required-action-bypass

Conversation

@huyenvu2101
Copy link
Copy Markdown
Contributor

Closes #55375

The consent form posts the session code as code, but since 5ea4ef9 the consent endpoint reads session_code, so every consent submission was treated as a page refresh and the required-action check never ran.

Decisions and assumptions:

  • Fixed on the server (read code, fall back to session_code) rather than in login-oauth-grant.ftl, so custom themes copied from the base template keep working.
  • A consent request without a valid code now continues with the pending action (required action or consent screen) instead of granting consent, matching how processRequireAction handles refreshes.
  • verifyRequiredAction is 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

@huyenvu2101
huyenvu2101 marked this pull request as ready for review November 20, 2026 08:34
@huyenvu2101
huyenvu2101 requested review from a team as code owners November 20, 2026 08:34
Copilot AI balanced review requested due to automatic review settings November 20, 2026 08:34
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 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 code parameter, with session_code as 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 gaoyikeshuer left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @huyenvu2101 , thanks for this PR, I agree with the fix, just have some comments in your test file.

events.clear();
}
}

@gaoyikeshuer gaoyikeshuer Nov 25, 2026 •
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could we not use try/finally. the rest of this class uses getCleanup()

Comment on lines +441 to +452
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();");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this part a bit awkward, maybe is there any better way to shorten it

Copilot AI balanced review requested due to automatic review settings November 25, 2026 15:39
@huyenvu2101
Copy link
Copy Markdown
Contributor Author

Thanks for the review @gaoyikeshuer, I just updated the PR please take a look again

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the consent-request validation change.

No open issues 🎉

Review effort: Balanced

@gaoyikeshuer
Copy link
Copy Markdown
Contributor

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>
@huyenvu2101
huyenvu2101 force-pushed the fix-55375-consent-required-action-bypass branch from a7a36ce to 9ea3e86 Compare November 26, 2026 12:43
@mabartos mabartos left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@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 code param to session_code in the login-oauth-grant.ftl
  • Accept code fallback 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>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 15:12
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues blocking approval.

No open issues 🎉

Review effort: Balanced

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.

[CVE-2026-133221] Pending required actions (e.g. CONFIGURE_TOTP) bypassed by a POST to login-actions/consent without session_code

4 participants

0