Anchor CORS Origin allowlist matching (re.fullmatch)#5303
Open
adilburaksen wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
allowed_cors(libs/handler.py) matches the requestOriginagainst each configuredwhitelisted_cors_urlsregex withre.match, which only anchors at the start of the string. On a match it reflects the origin intoAccess-Control-Allow-Origintogether withAccess-Control-Allow-Credentials: true.With the shipped example pattern
https?://(.*-dot-)?test-client-site.appspot.com,re.matchalso 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
re.fullmatchso the pattern must match the entireOrigin(anchors both ends), closing the trailing-suffix and prefix bypasses.configs/test/gae/auth.yamlto escape literal dots and document the requirement, so copied configs are safe by default.