check-cors-security
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "check-cors-security" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-8c04381de1b6673a2cef02e51d82d598b41bb3c1b7716b39c73c45844c8b92bb. Verify the upstream source and version against https://github.com/dykyi-roman/awesome-claude-code before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Tooling and guidance for auditing CORS configuration security, aimed at detecting wildcard origins, wildcard-with-credentials, reflected dynamic origins, missing preflight handling, and overly permissive policies.
Introduction source: third_party · dykyi-roman · 0.0.1 Reference
SkillPi interpretation
- Tasks
- Audits CORS configuration security. Detects wildcard origins, credentials with wildcards, dynamic origin reflection, missing preflight handling, and overly permissive policies.
- Inputs and outputs
- ```markdown
- Testing
- Not tested
Browse files
Frontmatter
name: check-cors-security
description: Audits CORS configuration security. Detects wildcard origins, credentials with wildcards, dynamic origin reflection, missing preflight handling, and overly permissive policies.CORS Security Audit (A05:2021)
Analyze PHP code for CORS misconfiguration vulnerabilities.
Detection Patterns
1. Wildcard Origin
// CRITICAL: Allows any website to make requests
header('Access-Control-Allow-Origin: *');
// In framework config:
'allowed_origins' => ['*'], // Any origin!
2. Credentials with Wildcard
// CRITICAL: Browser ignores this (spec violation), but shows misconfiguration intent
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Credentials: true');
// Cannot use * with credentials — forces dynamic origin reflection
3. Dynamic Origin Reflection (Dangerous)
// CRITICAL: Reflects any Origin header — equivalent to wildcard with credentials
class CorsMiddleware
{
public function handle(Request $request, Response $response): Response
{
$origin = $request->headers->get('Origin');
$response->headers->set('Access-Control-Allow-Origin', $origin); // Reflects ANY origin!
$response->headers->set('Access-Control-Allow-Credentials', 'true');
return $response;
}
}
// CORRECT: Whitelist of allowed origins
class CorsMiddleware
{
private const array ALLOWED_ORIGINS = [
'https://app.example.com',
'https://admin.example.com',
];
public function handle(Request $request, Response $response): Response
{
$origin = $request->headers->get('Origin');
if (in_array($origin, self::ALLOWED_ORIGINS, true)) {
$response->headers->set('Access-Control-Allow-Origin', $origin);
$response->headers->set('Access-Control-Allow-Credentials', 'true');
$response->headers->set('Vary', 'Origin');
}
return $response;
}
}
4. Missing Vary: Origin Header
// VULNERABLE: Without Vary, CDN/proxy may cache wrong CORS headers
$response->headers->set('Access-Control-Allow-Origin', $dynamicOrigin);
// Missing: $response->headers->set('Vary', 'Origin');
// CDN caches response for origin A, serves to origin B
5. Overly Permissive Methods/Headers
// VULNERABLE: Allows all methods including DELETE, PATCH
header('Access-Control-Allow-Methods: *');
header('Access-Control-Allow-Headers: *');
// CORRECT: Minimal required methods
$response->headers->set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
$response->headers->set('Access-Control-Allow-Headers', 'Content-Type, Authorization');
6. Missing Preflight Handling
// VULNERABLE: OPTIONS request not handled — browser blocks request
class ApiController
{
public function handle(Request $request): Response
{
// No OPTIONS handling — preflight fails
return $this->processRequest($request);
}
}
// CORRECT: Handle preflight
if ($request->getMethod() === 'OPTIONS') {
$response = new Response('', 204);
$response->headers->set('Access-Control-Allow-Origin', $allowedOrigin);
$response->headers->set('Access-Control-Allow-Methods', 'GET, POST');
$response->headers->set('Access-Control-Max-Age', '86400');
return $response;
}
7. Regex Origin Matching (Bypass Risk)
// VULNERABLE: Regex can be bypassed
$origin = $request->headers->get('Origin');
if (preg_match('/example\.com$/', $origin)) {
// Matches: evil-example.com, phishing-example.com
$response->headers->set('Access-Control-Allow-Origin', $origin);
}
// CORRECT: Exact match or proper regex
if (preg_match('/^https:\/\/([a-z]+\.)?example\.com$/', $origin)) {
$response->headers->set('Access-Control-Allow-Origin', $origin);
}
Grep Patterns
# CORS headers
Grep: "Access-Control-Allow-Origin|Access-Control-Allow-Credentials" --glob "**/*.php"
Grep: "Access-Control-Allow-Methods|Access-Control-Allow-Headers" --glob "**/*.php"
# Wildcard origin
Grep: "Allow-Origin.*\*|allowed_origins.*\*" --glob "**/*.php" --glob "**/*.yaml"
# Dynamic origin reflection
Grep: "Origin.*header|getHeader.*Origin" --glob "**/*.php"
# CORS framework config
Grep: "cors|CORS" --glob "**/*.yaml" --glob "**/*.yml" --glob "**/*.php"
# Missing Vary header
Grep: "Allow-Origin" --glob "**/*.php"
Grep: "Vary.*Origin" --glob "**/*.php"
# Preflight handling
Grep: "OPTIONS|preflight" --glob "**/*.php"
Severity Classification
| Pattern | Severity |
|---|---|
| Dynamic origin reflection + credentials | 🔴 Critical |
| Wildcard origin on authenticated API | 🔴 Critical |
| Weak regex origin matching | 🟠 Major |
| Missing Vary: Origin | 🟠 Major |
| Wildcard methods/headers | 🟡 Minor |
| Missing preflight handling | 🟡 Minor |
Output Format
### CORS Security: [Description]
**Severity:** 🔴/🟠/🟡
**Location:** `file.php:line`
**CWE:** CWE-942 (Overly Permissive CORS Policy)
**OWASP:** A05:2021 — Security Misconfiguration
**Issue:**
[Description of the CORS misconfiguration]
**Attack Scenario:**
[How attacker exploits this from malicious origin]
**Current Configuration:**
Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: true
**Fix:**
```php
// Secure CORS configuration
Current listing version
0.0.1
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Areas to improve
-
缺少 When to Use 章节 Reported severity: Minor
文档未明确说明适用场景和使用时机,如开发阶段、代码审查或 CI/CD 集成。
Recommendation: 建议添加 'When to Use' 章节,说明该 Skill 适用于 PHP 项目安全审计、API 开发阶段或自动化安全扫描场景。
Highlights
- 提供 CORS 安全审计功能,覆盖 OWASP A05:2021 安全风险
- 检测多种高危配置模式,包括动态来源反射、通配符凭据等
- 适用于 PHP 项目安全开发和代码审查
Highlights
- 触发词精准完整,覆盖 CORS 安全审计核心功能
- description 清晰列出检测项,边界明确,不易误触
Areas to improve
-
文档较长,建议分节优化 Reported severity: Minor
文档内容详尽但篇幅较长,可能影响快速查阅体验。
Recommendation: 建议将检测模式、Grep 模式等拆分为独立子章节或文件,提升可读性。
Highlights
- 结构清晰,Phase/步骤分明,包含端到端示例
- frontmatter 完整,输出格式规范,便于集成
Areas to improve
-
缺少误报处理与确认机制说明 Reported severity: Minor
未说明如何处理 Grep 匹配的误报,以及不可逆操作(如自动修复)的确认机制。
Recommendation: 建议补充误报过滤策略,并说明在自动修复前应进行人工确认。
Highlights
- 工具来源明确,参数正确,覆盖主要异常场景
- 提供具体 Grep 命令,便于实际执行和集成
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
-
Accounts, secrets or authorization
Use a dedicated least-privilege account. Keep secrets out of public content and command logs; verify the receiving service and tenant.
Mentioned in main document · lines 3, 22, 27, 28, 34
Domains or addresses referenced in the document
These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.
- admin.example.com
- app.example.com
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.