CORS
Configure Cross-Origin Resource Sharing correctly to avoid security issues and debugging pain.
от clawic★ 23 звезды на GitHub
Установить CORS в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Preflight Triggers
- Any header except: Accept, Accept-Language, Content-Language, Content-Type (with restrictions)
- Content-Type other than: application/x-www-form-urlencoded, multipart/form-data, text/plain
- Methods: PUT, DELETE, PATCH, or any custom method
- ReadableStream in request body
- Event listeners on XMLHttpRequest.upload
- One trigger = preflight; simple requests skip OPTIONS entirely
Credentials Mode
Access-Control-Allow-Origin: *incompatible with credentials—must specify exact originAccess-Control-Allow-Credentials: truerequired for cookies/auth headers- Fetch:
credentials: 'include'; XHR:withCredentials = true - Without credentials mode, cookies not sent even to same origin for cross-origin requests
Wildcard Limitations
*doesn't match subdomains—*.example.comis invalid, not a pattern- Can't use
*with credentials—specify origin dynamically from request Access-Control-Allow-Headers: *works in most browsers but not all—list explicitly for compatibilityAccess-Control-Expose-Headers: *same issue—list headers you need to expose
Origin Validation
- Check Origin header against allowlist—don't reflect blindly (security risk)
- Regex matching pitfall:
example.commatchesevilexample.com—anchor the pattern nullorigin: sandboxed iframes, file:// URLs—usually reject, never allow as trusted- Missing Origin header: same-origin or non-browser client—handle explicitly
Vary Header (Critical)
- Always include
Vary: Originwhen response depends on origin—even if you allow only one - Without Vary: CDN/proxy caches response for one origin, serves to others—breaks CORS
- Add
Vary: Access-Control-Request-Headers, Access-Control-Request-Methodfor preflight caching correctness
Exposed Headers
- By default, JS can only read: Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, Pragma
- Custom headers invisible to JS unless listed in
Access-Control-Expose-Headers X-Request-ID,X-RateLimit-*, etc. need explicit exposure—common oversight
Preflight Caching
Access-Control-Max-Age: 86400caches preflight for 24h—reduces OPTIONS traffic significantly- Chrome caps at 2 hours; Firefox at 24 hours—values above are silently reduced
- Cached per origin + URL + request characteristics—not globally
- Set to 0 or omit during development—caching hides config changes
Debugging
- CORS error in browser = request reached server and came back—check server logs
- Preflight failure: server must return 2xx with CORS headers on OPTIONS—404/500 = failure
- Opaque response in fetch:
mode: 'no-cors'succeeds but response is empty—usually not what you want - Network tab shows CORS errors; Console shows which header is missing
Common Server Mistakes
- Only setting CORS headers on main handler, not OPTIONS—preflight fails
- Setting headers after error response—CORS headers missing on 4xx/5xx breaks error handling
- Proxy stripping headers—verify headers reach client, not just that server sets them
Access-Control-Allow-Origin: "*", "https://example.com"—must be single value, not list
Security
- Don't reflect Origin header blindly—validate against allowlist first
- Private Network Access: Chrome requires
Access-Control-Allow-Private-Network: truefor localhost access from public web - CORS doesn't prevent request from being sent—just blocks response reading; server still processes it
- Sensitive endpoints: don't rely on CORS alone; use authentication + CSRF tokens
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- _meta.json
FAQ
Что делает скилл CORS?
Configure Cross-Origin Resource Sharing correctly to avoid security issues and debugging pain.
Как установить скилл CORS?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл CORS запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…