Skip to content

feat(cors): Add wildcard port matching for CORS allowOrigins#8708

Open
GajanSoorian wants to merge 1 commit intoenvoyproxy:mainfrom
GajanSoorian:main
Open

feat(cors): Add wildcard port matching for CORS allowOrigins#8708
GajanSoorian wants to merge 1 commit intoenvoyproxy:mainfrom
GajanSoorian:main

Conversation

@GajanSoorian
Copy link
Copy Markdown

What type of PR is this?

feat(cors)

What this PR does:

Re-adds wildcard port matching (*) for CORS allowOrigins, reverting the removal in commit 81dce3e (upstream PR #2453).

The wildcard2regex runtime function already handles port wildcards correctly; This PR relaxes the kubebuilder CRD validation regex to accept * in the port position.

Why we need it:

The current SecurityPolicy CRD validation rejects wildcard ports, requiring every port to be enumerated explicitly. This creates friction in several scenarios:

  1. Local development with arbitrary ports: Tools like webpack dev servers run on several ports chosen by the developers. Arbitrary client applications can also use multiple ports. Explicitly listing these ports is no manageable.

  2. Using a general wildcard is not suitable in development environments that require stricter controls to prevent unwanted CORS access.

  3. Parallel agent workflows: Multiple AI coding agents working in separate worktrees each need their own dev server on a unique port. Hardcoding ports prevents this.

Wildcard port matching (e.g., https://host.com:*) allows a single origin entry to cover all ports for a given host, eliminating the need to enumerate and maintain an ever-growing list of port numbers or compromise on security by using the general wildcard option.

What Changed

  • api/v1alpha1/cors_types.go: Relaxed the kubebuilder validation regex on Origin from (:\d{1,5})? to (:(\*|\d{1,5}))?
  • Regenerated CRD manifests via make manifests
  • Added wildcard port test cases to internal/gatewayapi/securitypolicy_test.go
  • Updated CEL validation test expectations in test/cel-validation/securitypolicy_test.go

Test plan

  • make manifests regenerates CRDs with the new regex
  • go test ./internal/gatewayapi/... -run Test_wildcard2regex passes with new port wildcard cases
  • CEL validation tests pass: go test ./test/cel-validation/... -run TestSecurityPolicyTarget
  • Origins like https://example.com:* are accepted by the CRD
  • Origins like https://examplecom:5173 still work (no regression)

Which issue(s) this PR fixes:
N.A

@GajanSoorian GajanSoorian requested a review from a team as a code owner April 10, 2026 02:33
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 10, 2026

Deploy Preview for cerulean-figolla-1f9435 canceled.

Name Link
🔨 Latest commit 7ff604d
🔍 Latest deploy log https://app.netlify.com/projects/cerulean-figolla-1f9435/deploys/69e5a68f4184c00008dbd297

@arkodg
Copy link
Copy Markdown
Contributor

arkodg commented Apr 12, 2026

cc @zhaohuabing

@zhaohuabing
Copy link
Copy Markdown
Member

@codex

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 71d94a932b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@GajanSoorian
Copy link
Copy Markdown
Author

Thanks @zhaohuabing , I've addressed this comment

@arkodg arkodg added this to the v1.8.0-rc.1 Release milestone Apr 19, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.29%. Comparing base (40b3dbf) to head (e2e05d7).
⚠️ Report is 31 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8708      +/-   ##
==========================================
- Coverage   74.34%   74.29%   -0.05%     
==========================================
  Files         244      245       +1     
  Lines       38868    38801      -67     
==========================================
- Hits        28896    28829      -67     
+ Misses       7970     7968       -2     
- Partials     2002     2004       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: Gajan Suryan <gajansuryan@gmail.com>
@zhaohuabing
Copy link
Copy Markdown
Member

zhaohuabing commented Apr 20, 2026

The request is legitimate, but I’m not sure wildcard port matching is the right API here since it’s not a common pattern of how wildcard is used to match hosts. Maybe we should introduce an additional regex-based matcher in the CORS API, which would be clearer and more future-proof.

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.

3 participants