8000 Add commit-time max_auth_age check for application-initiated actions by msdaly200 · Pull Request #54551 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Add commit-time max_auth_age check for application-initiated actions - #54551

Draft
msdaly200 wants to merge 1 commit into
keycloak:mainfrom
msdaly200:53168
Draft

msdaly200 wants to merge 1 commit into
keycloak:mainfrom
msdaly200:53168

Conversation

@msdaly200
Copy link
Copy Markdown
Contributor

Closes #53168

Fix: enforce max_auth_age at AIA commit time, not only at entry

For AIAs configured with max_auth_age, the freshness check was only enforced when the action page was opened. A user could open the confirmation page while their authentication was fresh, wait until max_auth_age elapsed, and then submit — the action would complete without re-authentication.

Changes
AuthenticationProcessor.authenticationComplete() - writes the current time to an AUTH_TIME auth session note when an authentication flow completes. This records when the user last authenticated within the current auth session, independently of the original login time on the user session.

AuthenticatorUtil.isReAuthRequiredForKcAction() - new shared method that checks max_auth_age against the auth session note (falling back to the user session note if absent). Used by both the existing entry-time check in OIDCLoginProtocol.requireReauthentication() and the new commit-time check below.

LoginActionsService.processRequireAction() - calls isReAuthRequiredForKcAction immediately before provider.processAction(). If re-auth is required, the flow is reset and the user is redirected to the login page without executing the action. This applies to all AIAs processed through this handler, not only delete_credential.

Tests
Unit tests in AuthenticatorUtilTest cover all branches of the new method.
Integration tests in AppInitiatedActionMaxAuthAgeTest cover the commit-time gate end-to-end.
Existing Arquillian tests in AppInitiatedActionResetPasswordTest and AppInitiatedActionUpdateEmailTest continue to cover the entry-time behaviour unchanged.

@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.actions.TermsAndConditionsTest#termsAccepted

Keycloak CI - Forms IT (chrome)

java.lang.RuntimeException: Could not create statement
	at org.jboss.arquillian.junit.Arquillian.methodBlock(Arquillian.java:307)
	at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:160)
	at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:344)
	at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:48)
...

Report flaky test

@msdaly200
msdaly200 force-pushed the 53168 branch 7 times, most recently from e8a917e to 2459a10 Compare November 6, 2026 09:58
@msdaly200
msdaly200 requested a balanced review from Copilot November 6, 2026 11:33
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.

🟡 Changes recommended

Critical authentication-freshness gaps grant brokered sessions extra validity and allow POSTs without session_code to change email through expired UPDATE_EMAIL actions.

3 open issues
What changed in this PR

This PR addresses #53168 by checking authentication freshness when application-initiated actions are submitted, rather than only when their pages are opened.

Changes:

  • Shares max_auth_age validation between entry-time and commit-time checks.
  • Records authentication timestamps and checks freshness before persisting identity-provider links, with exceptions for completion callbacks and admin credential offers.
  • Adds unit and integration coverage for expiry, re-authentication, and unaffected flows.
File Description
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​oid4vc/​OID4VCAdminActionTest.java Tests the admin credential-offer exemption.
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​oid4vc/​OID4VCActionTest.java Tests expired credential-offer submissions.
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​broker/​oidc/​KcOidcBrokerIdpLinkActionMaxAuthAgeTest.java Tests link persistence across fresh and expired broker round trips.
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​actions/​AppInitiatedActionMaxAuthAgeTest.java Covers commit-time expiry, recovery, and configuration behavior.
test-framework/​ui/​src/​main/​java/​org/​keycloak/​testframework/​ui/​page/​IdpLinkActionPage.java Adds an identity-provider link confirmation page helper.
services/​src/​test/​java/​org/​keycloak/​protocol/​oidc/​OIDCLoginProtocolReauthenticationTest.java Tests protocol re-authentication decisions.
services/​src/​test/​java/​org/​keycloak/​authentication/​AuthenticatorUtilTest.java Tests shared freshness-check logic.
services/​src/​main/​java/​org/​keycloak/​services/​resources/​LoginActionsService.java Gates action submissions and redirects expired flows to authentication.
services/​src/​main/​java/​org/​keycloak/​services/​resources/​IdentityBrokerService.java Records broker authentication time and checks freshness before linking.
services/​src/​main/​java/​org/​keycloak/​protocol/​oidc/​OIDCLoginProtocol.java Delegates action freshness checks to the shared utility.
services/​src/​main/​java/​org/​keycloak/​authentication/​AuthenticatorUtil.java Adds shared action freshness validation.
services/​src/​main/​java/​org/​keycloak/​authentication/​AuthenticationProcessor.java Records authentication time for non-SSO flows.

Review effort: Balanced

…loses keycloak#53168

Signed-off-by: Marie Daly <marie.daly1@ibm.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.

delete_credential AIA validates max_auth_age only at action entry, not at commit

2 participants

0