Skip to content

Reject authorization codes on OAuth state mismatch - #1364

Closed
drewrukin wants to merge 1 commit into
apache:masterfrom
drewrukin:fix/swagger-oauth-state-validation
Closed

Reject authorization codes on OAuth state mismatch#1364
drewrukin wants to merge 1 commit into
apache:masterfrom
drewrukin:fix/swagger-oauth-state-validation

Conversation

@drewrukin

@drewrukin drewrukin commented Aug 29, 2026

Copy link
Copy Markdown

Problem

Swagger UI detects a state mismatch in the authorization-code callback but
only logs a warning. It still saves the returned code, deletes the original
state, and starts the token exchange.

This can attach a response from another or older OAuth request to the current
authorization flow, leading to login CSRF or authorization under the wrong
account, tenant, or OAuth configuration.

Fix

Validate the returned state before either authorization-code callback path.
This includes the normal path that stores a new code and the path where the
authorization object already contains a code.

On a mismatch, report an authorization error, close the redirect window, and
return immediately. Do not update the authorization object, delete the saved
state, invoke the callback, or start token exchange.

Valid authorization-code responses continue through the existing callback.
Implicit-flow responses keep their current behavior and still pass the state
validation result to the caller.

Result

After this change, an authorization response cannot cross from one OAuth
request into another. The original request state remains available after a
rejected response, and downstream code never receives or exchanges a code
that failed the state check.

Tests cover all supported authorization-code flow names, matching and
mismatched states, an existing authorization code, and the implicit flow.

Verification

mvn -pl gateway-openapi-ui -am -Dtest=OAuth2RedirectScriptTest -Dsurefire.failIfNoSpecifiedTests=false test

The authorization-code callback warned on a state mismatch but still\naccepted the returned code. Reject mismatched authorization-code\nresponses, preserve the original state binding, and add a regression\ntest covering both authorization-code and implicit flows.
@drewrukin drewrukin closed this Aug 29, 2026
@drewrukin
drewrukin deleted the fix/swagger-oauth-state-validation branch August 29, 2026 05:26
@drewrukin drewrukin changed the title Reject mismatched OAuth state in Swagger redirect callback Reject authorization codes on OAuth state mismatch Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant