Skip to content

Fix integer overflow in OIDC re-auth max_age checks - #52499

Open
groie wants to merge 1 commit into
keycloak:mainfrom
groie:fix/kc-action-reauth-overflow
Open

Fix integer overflow in OIDC re-auth max_age checks#52499
groie wants to merge 1 commit into
keycloak:mainfrom
groie:fix/kc-action-reauth-overflow

Conversation

@groie

@groie groie commented Sep 7, 2026

Copy link
Copy Markdown

isAuthTimeExpired() and isReAuthRequiredForKcAction() in OIDCLoginProtocol summed authTime and maxAge as int before comparing against the current time. A very large max_age (e.g. Integer.MAX_VALUE, reachable via the client-supplied max_age request parameter, or via a required action's configured max auth age) overflows the sum to a negative number, making the comparison incorrectly report the authentication as expired and force an unwanted re-authentication. Widen the sum to long to avoid the overflow.

Closes #52491

@groie
groie requested a review from a team as a code owner September 7, 2026 17:58
Copilot AI balanced review requested due to automatic review settings September 7, 2026 17:58

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

The overflow fix is focused, covered by tests, and has no unresolved issues.

Pull request overview

Fixes integer overflow in OIDC re-authentication expiry calculations.

Changes:

  • Uses long for timestamp-plus-age calculations.
  • Adds regression and baseline tests for affected authentication paths.
File summaries
File Description
services/src/test/java/org/keycloak/protocol/oidc/OIDCLoginProtocolTest.java Tests large, normal, and absent max-age behavior.
services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocol.java Prevents overflow in re-authentication expiry comparisons.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@mposolda mposolda self-assigned this Sep 8, 2026

@mposolda mposolda 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.

@groie Thanks!

The fix is good, but can you please add proper integration test instead of the test in the services module (which introduces lots of "mock" objects, which is not ideal)? Possibly new method in the OIDCAdvancedRequestParamsTest (there are already existing tests for maxAge and IMO, it is sufficient to add the itnegration test for the max_age supplied as a parameter)

@groie

groie commented Sep 8, 2026

Copy link
Copy Markdown
Author

Thanks for the Headsup @mposolda, I wasn't quite happy with the verbosity of the test myself. I'll follow your suggestion and see where the journey takes me.

Copilot AI review requested due to automatic review settings September 8, 2026 09:01
@groie
groie force-pushed the fix/kc-action-reauth-overflow branch from 8ad2e8f to dda4a19 Compare September 8, 2026 09:01
@groie
groie requested review from a team as code owners September 8, 2026 09:01

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

Add regression coverage for the required-action max_auth_age overflow path.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Copilot AI review requested due to automatic review settings September 8, 2026 09:18
@groie
groie force-pushed the fix/kc-action-reauth-overflow branch from dda4a19 to 3d7d2d5 Compare September 8, 2026 09:18

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

The brokered OIDC passMaxAge path still has the same overflow and lacks regression coverage.

Review details

Suppressed comments (1)

services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocol.java:554

  • The same client-supplied max_age still overflows for brokered OIDC logins when passMaxAge is enabled: OIDCIdentityProvider.java:548 adds authTimeInt + maxAgeInt as int and then rejects the IdP response. Please widen that comparison as well and cover the existing KcOidcBrokerPassMaxAgeTest path so this fix applies consistently.
        if ((long) authTimeInt + maxAgeInt < Time.currentTime()) {
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@groie
groie force-pushed the fix/kc-action-reauth-overflow branch from 3d7d2d5 to cf329b0 Compare September 8, 2026 09:30
Copilot AI review requested due to automatic review settings September 8, 2026 09:30

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

The overflow fix and regression coverage are complete, with no unresolved issues.

Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

isAuthTimeExpired() and isReAuthRequiredForKcAction() in OIDCLoginProtocol, and isAuthTimeExpired() in the OIDC identity broker (OIDCIdentityProvider, used when passMaxAge is enabled) summed authTime and maxAge as int before comparing against the current time. A very large max_age (e.g. Integer.MAX_VALUE, reachable via the client-supplied max_age request parameter, via a required action's configured max auth age, or via the passMaxAge broker config) overflows the sum to a negative number, making the comparison incorrectly report the authentication as expired and force an unwanted re-authentication or reject an otherwise valid brokered login. Widen the sum to long in all three call sites to avoid the overflow.

Closes keycloak#52491

Signed-off-by: Ilkka <ilkka.harmanen@gmail.com>
Copilot AI review requested due to automatic review settings September 8, 2026 11:10
@groie
groie force-pushed the fix/kc-action-reauth-overflow branch from cf329b0 to 86e81f7 Compare September 8, 2026 11:10

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

The overflow fix is appropriately covered by regression tests, with no unresolved issues.

Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0 new
  • Review effort level: 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.

Integer overflow in OIDC re-auth max_age comparison (OIDCLoginProtocol)

3 participants