-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
🔒 security: Enforce case-sensitive null origin validation in CORS #3995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🔒 security: Enforce case-sensitive null origin validation in CORS #3995
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Comment |
Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## add-cors-origin-validation-and-tests #3995 +/- ##
========================================================================
+ Coverage 90.99% 91.57% +0.58%
========================================================================
Files 119 119
Lines 10861 10271 -590
========================================================================
- Hits 9883 9406 -477
+ Misses 619 546 -73
+ Partials 359 319 -40
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
c6986fe
into
add-cors-origin-validation-and-tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR addresses a security vulnerability in the CORS middleware where null origin validation was case-insensitive, potentially allowing malicious requests with non-standard "NULL" or "Null" variants. The fix enforces case-sensitive validation to only accept the spec-compliant lowercase "null".
Key Changes:
- Changed null origin check from lowercased
originHeaderto case-sensitiveoriginHeaderRaw - Added comprehensive test coverage for uppercase and mixed-case null variants to ensure rejection
- Improved test structure with
ExpectAllowedfield for clearer intent
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| middleware/cors/cors.go | Fixed null origin validation to use case-sensitive comparison with originHeaderRaw instead of lowercased originHeader |
| middleware/cors/cors_test.go | Added test cases for "NULL", "Null", and wildcard "*" origins, plus ExpectAllowed field for clearer test assertions |
The implementation is correct and well-tested. The security fix properly addresses the vulnerability by ensuring only the lowercase literal "null" is accepted as a valid null origin, which aligns with the CORS specification and legitimate browser behavior. No issues were identified in this pull request.
Description
The CORS middleware was performing case-insensitive null origin validation, accepting "NULL" and "Null" variants when only the lowercase literal "null" is valid per CORS specification. This creates a potential security issue as legitimate browsers always send lowercase "null".
Changes introduced
originHeaderRaw == "null"instead of lowercasedoriginHeaderExpectAllowedfield and renamed test case from "NullOriginAllowed" to "NullOriginLowercase"Type of change
Checklist
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.