🛡️ Sentinel: Fix missing Vary: Origin in CORS middleware#218
🛡️ Sentinel: Fix missing Vary: Origin in CORS middleware#218EffortlessSteven wants to merge 2 commits intomainfrom
Conversation
This change adds the `Vary: Origin` header to responses where `Access-Control-Allow-Origin` is dynamically set (based on the request Origin). This prevents cache poisoning where a response authorized for one origin might be cached and served to a different origin, causing CORS failures. The fix is applied to both `app-http` and `http-middleware` crates. Uses `append` instead of `insert` to preserve existing `Vary` headers (e.g. from compression middleware). Verification: - Added reproduction test `crates/app-http/tests/security_cors_vary.rs` - Verified regressions with existing security tests.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
This PR mitigates a CORS-related cache poisoning risk by ensuring responses that dynamically reflect the request Origin include Vary: Origin, preventing intermediate caches from serving mismatched Access-Control-Allow-Origin headers across origins.
Changes:
- Append
Vary: Originon regular CORS responses whenAccess-Control-Allow-Originis set from the request origin. - Append
Vary: Originon CORS preflight (OPTIONS) responses whenAccess-Control-Allow-Originis set. - Add integration tests asserting
VaryincludesOriginfor both GET and OPTIONS requests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/http-middleware/src/cors.rs | Appends Vary: Origin when reflecting allowed origins for both normal and preflight responses. |
| crates/app-http/src/middleware/cors.rs | Mirrors the same Vary: Origin behavior in app-http’s CORS middleware implementation. |
| crates/app-http/tests/security_cors_vary.rs | Adds integration coverage to confirm Vary includes Origin for GET and OPTIONS. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This change adds the `Vary: Origin` header to responses where `Access-Control-Allow-Origin` is dynamically set (based on the request Origin). This prevents cache poisoning where a response authorized for one origin might be cached and served to a different origin, causing CORS failures. The fix is applied to both `app-http` and `http-middleware` crates. Uses `append` instead of `insert` to preserve existing `Vary` headers (e.g. from compression middleware). Verification: - Added reproduction test `crates/app-http/tests/security_cors_vary.rs` - Verified regressions with existing security tests.
Test Results283 tests 245 ✅ 11m 24s ⏱️ Results for commit 2b94163. |
🛡️ Sentinel: [CRITICAL/HIGH] Fix CORS cache poisoning vulnerability
🚨 Severity: HIGH
💡 Vulnerability: Missing
Vary: Originheader in CORS responses. WhenAccess-Control-Allow-Originreflects the request Origin (e.g. for wildcard or multi-origin configurations), intermediate caches may cache the response. WithoutVary: Origin, a cached response forOrigin: A(containingAccess-Control-Allow-Origin: A) might be served to a client withOrigin: B, causing a CORS error for client B.🎯 Impact: Valid cross-origin requests may fail due to incorrect cached headers, or potentially (in rare configs) incorrect access.
🔧 Fix: Added
Vary: Originheader wheneverAccess-Control-Allow-Originis set dynamically. Usedappendto avoid overwriting otherVarydirectives.✅ Verification: New integration test
crates/app-http/tests/security_cors_vary.rsconfirms the header is present for both GET and OPTIONS requests.PR created automatically by Jules for task 17752059851552910074 started by @EffortlessSteven