Skip to content

reject wildcard origin with credentials in is_origin_allowed#2644

Merged
stephenberry merged 2 commits into
stephenberry:mainfrom
uwezkhan:cors-wildcard-credentials
Jun 18, 2026
Merged

reject wildcard origin with credentials in is_origin_allowed#2644
stephenberry merged 2 commits into
stephenberry:mainfrom
uwezkhan:cors-wildcard-credentials

Conversation

@uwezkhan

Copy link
Copy Markdown
Contributor

With allowed_origins {"*"} and allow_credentials true, any request Origin is echoed back with credentials:

> Origin: https://evil.example
< Access-Control-Allow-Origin: https://evil.example
< Access-Control-Allow-Credentials: true

is_origin_allowed treats "*" (or an empty origin list) as allow-all without looking at allow_credentials, and create_cors_middleware reflects the request origin once credentials are on. The combination lets any site read authenticated cross-origin responses. The cors_config docs already say "*" is invalid with credentials, so this keeps the wildcard/empty-list allow-all path but gates it on credentials being off; with credentials on it falls through to the exact allowed_origins match (the validator path is unchanged).

Before: "*" + credentials reflects any origin alongside Access-Control-Allow-Credentials: true.
After: "*" + credentials only allows origins listed explicitly (or accepted by the validator); "*" without credentials still allows all and sends Access-Control-Allow-Origin: *.

Test in tests/networking_tests/cors_test drives the middleware headers and is_origin_allowed across these cases.

uwezkhan and others added 2 commits June 18, 2026 19:19
The pre-existing cors_wildcard_with_credentials_echoes_origin test asserted
the old behavior where a wildcard origin list with credentials echoed the
request origin alongside Access-Control-Allow-Credentials. The security fix in
is_origin_allowed now rejects an unlisted origin in that configuration, so the
test is updated to verify the preflight is denied (403) with no Allow-Origin or
Allow-Credentials headers, and renamed accordingly.
@stephenberry stephenberry merged commit ab2921d into stephenberry:main Jun 18, 2026
53 checks passed
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