Skip to content

honor allowed_origins_validator over the default wildcard in is_origin_allowed - #3119

Open
uwezkhan wants to merge 1 commit into
stephenberry:mainfrom
uwezkhan:cors-validator-wildcard
Open

uwezkhan wants to merge 1 commit into
stephenberry:mainfrom
uwezkhan:cors-validator-wildcard

Conversation

@uwezkhan

Copy link
Copy Markdown
Contributor

cors_config::allowed_origins defaults to {"*"}, and is_origin_allowed grants every origin when that list holds "*" and credentials are off, before the validator's answer is used. A config that only sets allowed_origins_validator, such as create_cors_middleware({.allowed_origins_validator = ...}), therefore allows origins the validator rejects, and since a validator is set the middleware echoes them back:

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

The wildcard and empty-list grant now applies only when no validator is set. With a validator, an origin is allowed if the validator accepts it or it is listed exactly in allowed_origins. The check stays in is_origin_allowed so enable_cors(config) and direct middleware users get the same answer. #2644 covered "*" with credentials on and left the validator path as is; this is the credentials-off side.

  • Before: validator set, allowed_origins left at default: every origin allowed and reflected.
  • After: only origins the validator accepts (or exact entries) are allowed; a rejected origin gets no Access-Control-Allow-Origin.
  • Tradeoff: a config that lists "*" and also sets a validator no longer allows all origins. That combination was contradictory, and clearing the validator restores allow-all.

Two tests in tests/networking_tests/cors_test/cors_test.cpp fail on main (3 asserts) and pass with the change; the rest of cors_test is unchanged and green, also under ASan+UBSan.

This branch has not been deployed

No deployments
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