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 3 commits into
keycloak:mainfrom
huyenvu2101:fix-55375-consent-required-action-bypass
Open

huyenvu2101 wants to merge 3 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

…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-Aut
10BC8
hored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: huyenvu2101 <vhuyen2101@gmail.com>
@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

Add a test that submits a valid session code of another required action
to the consent endpoint, use getCleanup() instead of try/finally, and
send the consent request with URLUtils.sendPOSTRequestWithWebDriver.

Closes keycloak#55375

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: huyenvu2101 <vhuyen2101@gmail.com>
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

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>
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

3 participants

0