Skip to content

Reject authorization codes on OAuth state mismatch - #1365

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

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

Conversation

@drewrukin

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 Swagger UI OAuth redirect callback only reported a warning when an authorization-code response returned a mismatched state. It then stored the returned code and started token exchange.

Reject mismatched responses before invoking the callback, preserve the original state, and add regression coverage for every supported authorization-code flow name and the existing implicit-flow behavior.
@drewrukin

Copy link
Copy Markdown
Author

The two Actions workflows for the current head are waiting for maintainer approval and have not created any jobs:

Could a maintainer approve these workflows?

The failed Publish Test Results run linked from the earlier PR belongs to closed PR #1364 and commit 4e3f422. Its parent workflow produced no jobs or artifacts, so the publisher failed while opening the absent Event File artifact. The current PR head is 99a19a8.

@moresandeep

Copy link
Copy Markdown
Contributor

@drewrukin i just approved it.

@github-actions

Copy link
Copy Markdown

Test Results

 3 files   3 suites   8s ⏱️
53 tests 53 ✅ 0 💤 0 ❌
64 runs  64 ✅ 0 💤 0 ❌

Results for commit 99a19a8.

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.

2 participants