Skip to content

Anchor CORS Origin allowlist matching (re.fullmatch)#5303

Open
adilburaksen wants to merge 1 commit into
google:masterfrom
adilburaksen:fix-cors-origin-fullmatch
Open

Anchor CORS Origin allowlist matching (re.fullmatch)#5303
adilburaksen wants to merge 1 commit into
google:masterfrom
adilburaksen:fix-cors-origin-fullmatch

Conversation

@adilburaksen
Copy link
Copy Markdown

Problem

allowed_cors (libs/handler.py) matches the request Origin against each configured whitelisted_cors_urls regex with re.match, which only anchors at the start of the string. On a match it reflects the origin into Access-Control-Allow-Origin together with Access-Control-Allow-Credentials: true.

With the shipped example pattern https?://(.*-dot-)?test-client-site.appspot.com, re.match also matches malicious origins such as:

  • https://test-client-site.appspot.com.evil.com (trailing suffix)
  • https://anything.evil.com-dot-test-client-site.appspot.com (the .* prefix)
  • https://test-client-siteXappspot.com (unescaped .)

A page on such an origin can then make credentialed cross-origin requests to the CORS-enabled endpoint and read the victim's authorized crash/testcase data.

Fix

  • Use re.fullmatch so the pattern must match the entire Origin (anchors both ends), closing the trailing-suffix and prefix bypasses.
  • Update the example regexes in configs/test/gae/auth.yaml to escape literal dots and document the requirement, so copied configs are safe by default.

@adilburaksen adilburaksen requested a review from a team as a code owner June 1, 2026 10:26
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