feat(cors): enhance origin validation for wildcard subdomains and add tests - #70
Open
jaymesC wants to merge 1 commit into
Open
feat(cors): enhance origin validation for wildcard subdomains and add tests#70jaymesC wants to merge 1 commit into
jaymesC wants to merge 1 commit into
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Conventional Commits ValidationPR Title: valid |
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.
What
CORS
*.example.comwildcard origins now match on a real subdomain labelboundary instead of a bare string suffix.
Why
isOriginAllowedmatched*.example.comwithstrings.HasSuffix(origin, "example.com"), so an attacker-controlledhttps://evilexample.com(orhttps://example.com.evil.com) also matched. WithAllowCredentials, that's across-origin read vector — the response is reflected back to the malicious origin.
How
Parse the origin, take its host, and allow only when the host equals the base
domain or ends with
"." + domain(a genuine subdomain). Scheme/port no longeraffect matching. Exact-match entries are unchanged.
https://acme.example.com,https://a.b.example.com,https://example.comhttps://evilexample.com,https://example.com.evil.comTests
New
extensions/security/cors_test.gocovers the allow/reject cases (lookalikes,nested subdomains, apex, ports, malformed) plus exact-match-without-wildcard. Green.