Repository navigation
fix(auth): require an authorization code on the confidential OIDC callback #35679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -613,6 +613,11 @@ public void handleCallback(HttpServletRequest req, HttpServletResponse resp) { | |
| // Build Credentials | ||
| OidcCredentials credentials = buildCredentials(successResponse); | ||
|
|
||
| // The identity below must come from the ID token the back-channel exchange returns, and that | ||
| // exchange only runs when the callback carries an authorization code. Reject a callback that | ||
| // brings only a front-channel token: it never passed through the provider's token endpoint. | ||
| requireAuthorizationCode(pendingSession, credentials); | ||
|
gitar-bot[bot] marked this conversation as resolved.
|
||
|
|
||
| // Validations | ||
| validateAndSendTokenRequest(pendingSession, credentials, computedCallbackUrl); | ||
|
|
||
|
|
@@ -914,6 +919,32 @@ static Map<String, String> buildLoginParams(OidcConfiguration configuration) { | |
| return new HashMap<>(authParams); | ||
| } | ||
|
|
||
| private void requireAuthorizationCode(UserSession session, OidcCredentials credentials) { | ||
| if (expectsAuthorizationCode() && credentials.getCode() == null) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When Keep the authorization-code requirement for this handler, or verify front-channel tokens before trusting their claims. How this was verified: The exempt callback copies the supplied token into credentials, skips the code exchange, and passes its unchecked claims through user lookup to session activation. Knowledge Base Used: Platform security and governance |
||
| LOG.warn( | ||
| "Rejecting OIDC callback without an authorization code for session {}", | ||
| SessionService.truncateId(session.getId())); | ||
| throw new IllegalArgumentException("Authorization code is required"); | ||
| } | ||
| } | ||
|
|
||
| private boolean expectsAuthorizationCode() { | ||
| // The default and documented confidential mode is the authorization-code flow. Per OIDC, any | ||
| // response_type that includes "code" (plain or hybrid) returns an authorization code, so the | ||
| // callback must carry one. A response_type configured for pure implicit delivery is not a code | ||
| // flow and keeps its existing handling. | ||
| String responseType = client.getConfiguration().getResponseType(); | ||
| if (nullOrEmpty(responseType)) { | ||
| return true; | ||
| } | ||
| for (String part : responseType.trim().split("\\s+")) { | ||
| if ("code".equalsIgnoreCase(part)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private void validateAndSendTokenRequest( | ||
| UserSession session, OidcCredentials oidcCredentials, String computedCallbackUrl) | ||
| throws URISyntaxException { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.