Skip to content

fix(cors): mirror Origin header when credentials are allowed (#679)#696

Open
jackthepunished wants to merge 1 commit into
poyrazK:mainfrom
jackthepunished:fix/cors-wildcard-credentials-679
Open

fix(cors): mirror Origin header when credentials are allowed (#679)#696
jackthepunished wants to merge 1 commit into
poyrazK:mainfrom
jackthepunished:fix/cors-wildcard-credentials-679

Conversation

@jackthepunished

@jackthepunished jackthepunished commented May 25, 2026

Copy link
Copy Markdown
Contributor

Browsers reject responses that combine wildcard Origin with credentials. The CORS middleware now echoes the request Origin (with Vary header) when present and only sends credentials in that case; falls back to wildcard without credentials when there is no Origin (Fixes #679).

…#679)

Browsers reject `Access-Control-Allow-Origin: *` combined with
`Access-Control-Allow-Credentials: true`. The CORS middleware now echoes the
request Origin (with `Vary: Origin`) when present and only sends the
credentials header in that case; falls back to `*` without credentials when
there is no Origin.
Copilot AI review requested due to automatic review settings May 25, 2026 03:08
@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@jackthepunished, we couldn't start this review because you've used your available PR reviews for now.

Your plan includes 1 review of capacity. Refill in 59 minutes and 11 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2657c38a-72c5-4a5a-97f5-f2a323218586

📥 Commits

Reviewing files that changed from the base of the PR and between e0f151b and 658997a.

📒 Files selected for processing (1)
  • pkg/httputil/middleware.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the development CORS middleware to support credentialed requests by avoiding the invalid Access-Control-Allow-Origin: * + Access-Control-Allow-Credentials: true combination.

Changes:

  • Mirror the request Origin when present and enable credentials; otherwise fall back to wildcard origin.
  • Add explanatory comment documenting the browser constraint and the chosen behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +82 to +89
origin := c.GetHeader("Origin")
if origin != "" {
c.Header("Access-Control-Allow-Origin", origin)
c.Header("Vary", "Origin")
c.Header("Access-Control-Allow-Credentials", "true")
} else {
c.Header("Access-Control-Allow-Origin", "*")
}
origin := c.GetHeader("Origin")
if origin != "" {
c.Header("Access-Control-Allow-Origin", origin)
c.Header("Vary", "Origin")
Comment on lines 74 to 80
// CORS enables permissive CORS headers for development.
//
// Browsers reject responses that combine `Access-Control-Allow-Origin: *`
// with `Access-Control-Allow-Credentials: true`. When the request supplies
// an `Origin` header we mirror it back (with `Vary: Origin`) and allow
// credentials; otherwise we fall back to the wildcard with no credentials.
func CORS() gin.HandlerFunc {
@github-actions github-actions Bot added bug Something isn't working size/xs labels May 25, 2026
@poyrazK poyrazK closed this Jun 13, 2026
@poyrazK poyrazK reopened this Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size/xs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CRITICAL: CORS allows wildcard origin with credentials - browser rejects

3 participants