feat(protect): cors_reflected match type for CORS-misconfiguration detection - #110
Merged
Merged
Conversation
|
Well-structured CORS misconfiguration detection feature with comprehensive tests. 🎯 Quality: 100% Elite · 📦 Size: Small 📈 This month: Your 50th PR — above team average · Averaging Excellent |
Contributor
Author
|
/review |
daniloradovic
approved these changes
Aug 12, 2026
…tection Add a `cors_reflected` response-phase primitive (dispatched like cross_origin/off_origin): true (→ block) when a response allows credentials AND either uses `Access-Control-Allow-Origin: *` or reflects the caller's own Origin — the combination that lets any malicious site read the authenticated response. A fixed allowlisted origin, or reflection without credentials, is not flagged. Uses the request Origin threaded into the response phase (#106). Third origin-comparison primitive after cross_origin (CSRF) and off_origin (open-redirect). Not a default; authored + route-scoped via `when`. +6 tests; 632 pass; typecheck clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
patchstackdave
force-pushed
the
feat/cors-reflection-detection
branch
from
August 12, 2026 11:33
36d27b0 to
a1d4f98
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The third origin-comparison capability unlocked by threading the request into the response phase (#106), after
cross_origin(CSRF) andoff_origin(open-redirect, #109). CORS misconfiguration — a response that reflects the caller's Origin and allows credentials — lets any site read the authenticated response; a common, high-impact bug in AI-built APIs.What
New
cors_reflectedresponse-phase match type (dispatched likecross_origin, needs the whole resolver):action: block) whenAccess-Control-Allow-Credentials: trueAND theAccess-Control-Allow-Origineither is*or echoes the requestOrigin(so every origin is allowed).{ "phase": "response", "category": "cors", "action": "block", "when": { "path": "/api/*" }, "rule_v2": [{ "match": { "type": "cors_reflected" } }] }Blocking withholds the response, preventing the cross-origin read. Not a default — authored and route-scoped. (A future header-mutation action — strip
ACAC/ pinACAO— would be a gentler mitigation than a full block; noted for later.)Tests
tests/protect/cors-reflection.test.ts— 6: reflected-origin + credentials blocked, wildcard + credentials blocked, fixed allowlist allowed, reflection-without-credentials allowed, no-CORS-headers allowed,whenroute scope. 632 pass; typecheck clean.🤖 Generated with Claude Code