validating-cors-policies
Validate CORS policies for security issues and misconfigurations. Use when reviewing cross-origin resource sharing. Trigger with 'validate CORS', 'check CORS policy', or 'review cross-origin'.
- License 许可
- MIT
- 最近更新
- 2026-03-20
- Stars
- ★ 4
- Forks
- 0
01 前言 Front Matter
- name
- validating-cors-policies
- author
- Jeremy Longshore <jeremy@intentsolutions.io>
- license
- MIT
- version
- 1.0.0
- description
- Validate CORS policies for security issues and misconfigurations. Use when reviewing cross-origin resource sharing. Trigger with 'validate CORS', 'check CORS policy', or 'review cross-origin'.
- allowed-tools
- Read, WebFetch, WebSearch, Grep
- compatible-with
- claude-code, codex, openclaw
02 资源文件 5
- 资产文件assets/README.md197 B
- 参考文档references/README.md65 B
- 脚本scripts/generate_test_cases.py16.9 KB
- 脚本scripts/README.md470 B
- 脚本scripts/validate_cors.py12.3 KB
03 SKILL.md 正文
Validating CORS Policies
Overview
Validate Cross-Origin Resource Sharing configurations in web applications and APIs for security misconfigurations that enable unauthorized cross-origin access. This skill analyzes CORS headers, middleware configurations, and server response behavior to detect wildcard origins, reflected origins, credential leakage, and overly permissive header/method exposure.
Prerequisites
- Access to the target codebase and configuration files in
${CLAUDE_SKILL_DIR}/ - For live endpoint testing: WebFetch tool available and target URLs accessible
- Familiarity with the web framework in use (Express, Django, Flask, Spring, ASP.NET, etc.)
- Reference:
${CLAUDE_SKILL_DIR}/references/README.mdfor CORS specification details, common vulnerability patterns, and example policies
Instructions
- Locate all CORS configuration points by scanning for
Access-Control-Allow-Origin,cors()middleware,@CrossOriginannotations, CORS policy builders, and server config directives (nginxadd_header, ApacheHeader set) using Grep. - Check for wildcard origin (
Access-Control-Allow-Origin: *) -- flag as severity high when combined withAccess-Control-Allow-Credentials: true, which browsers reject but indicates a misunderstanding of the security model. - Detect origin reflection patterns where the server echoes back the
Originrequest header without validation -- search for code that reads theOriginheader and sets it directly in the response. Flag as CWE-942 (Permissive Cross-domain Policy), severity critical. - Validate the origin allowlist: check that allowed origins use exact string matching rather than substring or regex patterns vulnerable to bypass (e.g.,
example.com.evil.commatching a check forexample.com). - Assess
Access-Control-Allow-Methods-- flag if dangerous methods (PUT,DELETE,PATCH) are exposed without necessity. Verify that preflight (OPTIONS) responses include appropriate method restrictions. - Evaluate
Access-Control-Allow-Headers-- flag wildcard header allowance or exposure of sensitive headers likeAuthorization,Cookie, or custom auth headers to broader origins than necessary. - Check
Access-Control-Expose-Headersfor leakage of internal headers (e.g.,X-Request-Id,X-Internal-Trace) to cross-origin consumers. - Verify
Access-Control-Max-Ageis set to a reasonable value (600-86400 seconds) to balance security with performance -- missing or excessively long max-age values deserve a low-severity note. - For live endpoints, issue preflight requests via WebFetch with various
Originvalues (legitimate, malicious, null) and analyze the response headers to confirm server behavior matches the codebase configuration. - Compile findings with severity ratings, map to OWASP Testing Guide OTG-CLIENT-007, and provide remediation with correct CORS middleware configuration examples.
Output
- CORS configuration inventory: Table of all CORS-enabled endpoints, their allowed origins, methods, headers, and credentials settings
- Findings report: Each finding includes severity, affected endpoint/file, CWE reference (CWE-942, CWE-346), observed behavior, and remediation code
- Preflight test results: For live endpoints, a table of Origin values tested and the corresponding server responses
- Remediation examples: Framework-specific CORS configuration snippets (Express
cors(), Djangodjango-cors-headers, Spring@CrossOrigin, nginx headers)
Error Handling
| Error | Cause | Solution |
|---|---|---|
| No CORS configuration found | CORS handled at infrastructure layer (CDN, API gateway) | Check CDN/gateway configs (Cloudflare, AWS API Gateway, nginx) for CORS header injection |
| WebFetch blocked or timed out | Target endpoint unreachable or rate-limited | Verify URL accessibility; fall back to static codebase analysis of CORS middleware configuration |
| Inconsistent CORS behavior across endpoints | Multiple CORS configurations at different layers | Map each layer (application, reverse proxy, CDN) and document the effective policy per endpoint |
| Origin reflection false positive | Dynamic origin validation with a secure allowlist | Verify the allowlist logic uses exact matching; mark as informational if the implementation is secure |
| Preflight not triggering | Request classified as "simple request" by the browser | Note that simple GET/POST requests bypass preflight; test with custom headers to force preflight |
Examples
Express.js CORS Middleware Audit
Scan ${CLAUDE_SKILL_DIR}/src/app.js and ${CLAUDE_SKILL_DIR}/src/middleware/ for cors()
configuration. Flag origin: true (reflects any origin) as CWE-942, severity
critical. Recommend replacing with an explicit allowlist:
origin: ['https://app.example.com', 'https://admin.example.com'].
Nginx CORS Header Review
Grep ${CLAUDE_SKILL_DIR}/nginx/ for add_header Access-Control-Allow-Origin. Flag any
$http_origin variable usage that reflects the origin without validation. Verify
that Access-Control-Allow-Credentials is only set for origins in the allowlist
using an if block or map directive.
API Gateway CORS Configuration
Review ${CLAUDE_SKILL_DIR}/infra/api-gateway.yaml or equivalent IaC definitions for
CORS settings. Flag wildcard * in allowed origins when credentials are enabled.
Verify that Access-Control-Allow-Methods is scoped to only the HTTP methods
each endpoint actually supports.
Resources
04 同仓库更多 Skills
azure-apim-architecture
Analyzes and explains Azure API Management architecture decisions for enterprise API marketplace implementations using VNet Internal mode, Front Door, hybrid authentication, and multi-environment strategies. Use when discussing APIM component selection, network topology, cost optimization, or comparing alternatives like workspaces vs instances, VNet Internal vs External mode, or Front Door vs Application Gateway.
apiops-deployment
Guides deployment of Azure API Management infrastructure using Infrastructure as Code (Bicep/Terraform), CI/CD pipelines (GitHub Actions/Azure DevOps), and APIOps workflows. Use when deploying APIM, creating pipelines, or implementing dev→test→prod promotion strategies.
apim-policy-authoring
Creates production-ready Azure API Management policy XML for authentication (OAuth 2.0, JWT validation, subscription keys), rate limiting, CORS configuration, error handling, and API transformations. Use when implementing API security, access control, or request/response processing logic.
api-security-review
Reviews Azure API Management configurations for security vulnerabilities, OWASP API Security Top 10 compliance, VNet Internal mode validation, Private Link verification, and Azure Security Benchmark alignment. Use when performing security audits, pre-deployment validation, or compliance reviews.
jira-cli
Interact with Jira from the command line to create, list, view, edit, and transition issues, manage sprints and epics, and perform common Jira workflows. Use when the user asks about Jira tasks, tickets, issues, sprints, or needs to manage project work items.
calculator
Performs arbitrary-precision arithmetic calculations including addition, subtraction, multiplication, division, and exponents. Use when the user asks to calculate, compute, or evaluate math expressions, or when precise decimal arithmetic is needed to avoid floating-point errors.