---
name: "cors-origin-preflight-hardening"
description: "Configure secure Cross-Origin Resource Sharing (CORS) without wildcards or leaks."
metadata:
  author: "MDN Web Docs"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "configure cors allowlist"
  - "fix cors preflight error"
  - "prevent insecure cors wildcard"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# CORS Access-Control Hardening & Preflight Checks

Configures production CORS policies: exact origin matching, validating Origin headers against dynamic allowlists, handling OPTIONS preflights, and preventing Access-Control-Allow-Origin: * with credentials.

## When to Invoke
Invoke this skill whenever you need to:
- configure cors allowlist
- fix cors preflight error
- prevent insecure cors wildcard

## Execution SOP & Rules
1. Match incoming Origin headers against an explicit array of allowed domain strings.
2. Never return Access-Control-Allow-Origin: * when Access-Control-Allow-Credentials is true.
3. Include Vary: Origin in responses when dynamically reflecting allowed origins.
4. Limit Access-Control-Allow-Headers and Access-Control-Allow-Methods strictly to required values.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
