Skip to content

feat(cors): enhance origin validation for wildcard subdomains and add tests - #70

Open
jaymesC wants to merge 1 commit into
mainfrom
wildcard-subdomain
Open

feat(cors): enhance origin validation for wildcard subdomains and add tests#70
jaymesC wants to merge 1 commit into
mainfrom
wildcard-subdomain

Conversation

@jaymesC

@jaymesC jaymesC commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

What

CORS *.example.com wildcard origins now match on a real subdomain label
boundary
instead of a bare string suffix.

Why

isOriginAllowed matched *.example.com with strings.HasSuffix(origin, "example.com"), so an attacker-controlled https://evilexample.com (or
https://example.com.evil.com) also matched. With AllowCredentials, that's a
cross-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 longer
affect matching. Exact-match entries are unchanged.

  • https://acme.example.com, https://a.b.example.com, https://example.com
  • https://evilexample.com, https://example.com.evil.com

Tests

New extensions/security/cors_test.go covers the allow/reject cases (lookalikes,
nested subdomains, apex, ports, malformed) plus exact-match-without-wildcard. Green.

@vercel

vercel Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
forge Ready Ready Preview Aug 29, 2026 6:28pm

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

Conventional Commits Validation

PR Title: valid
Commits: all 1 follow conventional format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant