Claude skill CORS credentialed requests security — SA-SKL-CORS5
MCP skills that expose HTTP APIs for browser-side Claude integrations face a subtler class of CORS vulnerability when credentialed requests are involved. SA-SKL-CORS5 covers four patterns: wildcard origin paired with credentials, preflight response cache poisoning, credentialed access to unrestricted internal endpoints, and the null-origin sandbox bypass — all exploitable from a cross-origin page even when basic CORS is configured.
Why credentialed CORS is a distinct attack surface
Standard CORS restricts which origins can read responses from cross-origin requests. Adding credentials — cookies, HTTP Basic Auth, or TLS client certificates — to that picture creates stricter requirements that many developers implement incorrectly. The spec forbids Access-Control-Allow-Credentials: true combined with Access-Control-Allow-Origin: *, but frameworks that build CORS headers by string concatenation rather than spec-compliant logic can produce contradictory headers that some user agents accept. Beyond header misconfiguration, credentialed CORS unlocks attacks that are impossible with simple requests: preflight poisoning, null-origin escalation, and direct access to internal services that assume non-browser clients cannot carry session cookies.
MCP skills that expose audit endpoints, dashboard APIs, or admin interfaces over HTTP must treat credentialed cross-origin requests as a first-class threat model — especially since Claude Desktop and browser-based integrations increasingly make cross-origin requests on behalf of authenticated users.
SA-SKL-CORS5 in scope: CORS5-001 (wildcard origin with credentials), CORS5-002 (preflight cache poisoning), CORS5-003 (credentialed request to internal admin endpoint), CORS5-004 (Origin: null allowlist bypass). Each pattern includes SkillAudit detection rules and correct fixes.
CORS5-001 — Access-Control-Allow-Credentials: true with wildcard origin
The CORS specification explicitly prohibits pairing Access-Control-Allow-Credentials: true with Access-Control-Allow-Origin: *. Compliant browsers reject this combination — when credentials are requested with fetch(url, { credentials: 'include' }), the browser requires an exact origin in the ACAO header, not a wildcard. However, some Express middleware versions and hand-rolled CORS handlers set both headers when misconfigured. Non-browser HTTP clients (curl, server-side fetch, MCP tool call orchestrators) ignore CORS entirely and can send credentialed requests regardless — this matters when the credential is an API key transmitted in a cookie, since server-side tool calls can reach the endpoint without any CORS restriction. The fix is to maintain an explicit allowlist of origins and reflect only allowlisted origins back in the ACAO header when Access-Control-Allow-Credentials: true is required.
// VULNERABLE — credentials enabled with wildcard origin
import express from 'express';
const app = express();
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
// Credentials + wildcard: browsers reject this, but some frameworks
// accept it and non-browser clients ignore CORS entirely
res.setHeader('Access-Control-Allow-Credentials', 'true');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
if (req.method === 'OPTIONS') return res.sendStatus(204);
next();
});
app.get('/api/audit-results', authenticate, (req, res) => {
res.json({ results: getAuditResults(req.user) });
});
// FIXED — reflect origin only from explicit allowlist when credentials required
const ALLOWED_ORIGINS = new Set([
'https://app.skillaudit.dev',
'https://dashboard.skillaudit.dev',
]);
app.use((req, res, next) => {
const origin = req.headers.origin;
if (origin && ALLOWED_ORIGINS.has(origin)) {
// Reflect exact origin from allowlist — required for credentialed CORS
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
res.setHeader('Vary', 'Origin'); // Prevent cache poisoning across origins
}
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
if (req.method === 'OPTIONS') return res.sendStatus(204);
next();
});
app.get('/api/audit-results', authenticate, (req, res) => {
res.json({ results: getAuditResults(req.user) });
});
Access-Control-Allow-Credentials: true combined with Access-Control-Allow-Origin: * is spec-violating; browsers reject it but non-browser clients (including server-side MCP orchestrators) ignore CORS and send credentialed requests unrestricted; fix by reflecting only allowlisted origins and adding a Vary: Origin header. Detection: SkillAudit flags response handlers that set both Access-Control-Allow-Credentials: true and Access-Control-Allow-Origin: * simultaneously, or CORS middleware configured with credentials: true and origin: '*'.CORS5-002 — Preflight cache poisoning via crafted OPTIONS response
Browsers cache preflight responses for the duration specified in Access-Control-Max-Age. If a skill's CORS handler reflects arbitrary origins without an allowlist (a common permissive development shortcut), an attacker who controls a subdomain can send a crafted OPTIONS request and cache a permissive preflight response for the victim origin. Subsequent credentialed requests from legitimate pages skip the OPTIONS round-trip and use the cached permission — granting cross-origin read access to the attacker's page for the cache TTL. The attack is amplified when Access-Control-Max-Age is set to hours or days. The fix is the same allowlist-based origin reflection as CORS5-001, combined with a Vary: Origin header to ensure each origin's preflight is cached independently and an Access-Control-Max-Age value no longer than 300 seconds for sensitive endpoints.
// VULNERABLE — reflects any origin, long preflight cache TTL
app.options('/api/*', (req, res) => {
const origin = req.headers.origin || '*';
// Reflects ANY origin — attacker can seed a permissive cache entry
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, DELETE, PUT');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-API-Key');
// 24-hour preflight cache — a poisoned entry persists all day
res.setHeader('Access-Control-Max-Age', '86400');
res.sendStatus(204);
});
// FIXED — allowlist-based origin, short cache TTL, Vary header
app.options('/api/*', (req, res) => {
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'); // Cache per-origin, not globally
}
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, DELETE, PUT');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-API-Key');
// 5-minute preflight TTL — limits blast radius of any misconfiguration
res.setHeader('Access-Control-Max-Age', '300');
res.sendStatus(204);
});
Access-Control-Max-Age duration; fix by using allowlist origin reflection, adding Vary: Origin, and capping Access-Control-Max-Age at 300 seconds. Detection: SkillAudit flags OPTIONS handlers that set Access-Control-Allow-Origin to the value of req.headers.origin without checking against a hardcoded allowlist.CORS5-003 — Credentialed cross-origin request to internal admin endpoint
MCP skills that expose both a public skill API and an internal admin API on the same server sometimes omit CORS restrictions from admin routes, reasoning that admin endpoints are "not public." A browser-based attacker on any origin can send a credentialed request with fetch('/api/admin/users', { credentials: 'include' }). If the server returns admin data without validating the Origin header on admin routes, the attacker's page can read the response — authenticated by the victim's session cookie. The fix requires that admin routes either refuse all cross-origin requests (by checking Origin against an empty allowlist or enforcing same-origin), or add explicit authentication beyond session cookies (such as a CSRF token or API key that cannot be sent by an attacker's cross-origin page).
// VULNERABLE — public API has CORS, admin API has none but shares session auth
app.use('/api/skill', corsMiddleware); // CORS configured for skill routes
// Admin route: no CORS config, relies on session cookie
// A browser-side attacker can still reach this with credentials: 'include'
app.get('/api/admin/users', requireAdminSession, (req, res) => {
res.json({ users: getAllUsers() });
});
// Attacker page on any origin:
// fetch('https://skillaudit.dev/api/admin/users', { credentials: 'include' })
// .then(r => r.json()).then(data => exfiltrate(data))
// FIXED — explicitly block cross-origin requests on admin routes
function requireSameOrigin(req, res, next) {
const origin = req.headers.origin;
// Requests without Origin header are non-browser (safe) or same-origin
if (!origin) return next();
// Reject any cross-origin request to admin endpoints
if (!ALLOWED_ORIGINS.has(origin)) {
return res.status(403).json({ error: 'Cross-origin requests not allowed on admin routes' });
}
next();
}
app.get('/api/admin/users', requireSameOrigin, requireAdminSession, (req, res) => {
res.json({ users: getAllUsers() });
});
Origin header on admin routes and rejecting non-allowlisted origins, or by requiring CSRF token or API-key headers that browser-side attackers cannot inject. Detection: SkillAudit flags routes matching /admin/, /internal/, or /_/ path prefixes that use cookie-based session auth but have no Origin header check in their middleware chain.CORS5-004 — CORS bypass via Origin: null from sandboxed iframes
Sandboxed iframes and documents loaded via data: or file: URLs send Origin: null in their HTTP requests. If a skill's CORS handler includes null in its allowlist — a pattern sometimes seen in development setups that need to serve local HTML files — an attacker can embed the skill's API call inside a sandboxed iframe on any page and trigger credentialed requests that the server accepts as coming from an allowed "null" origin. The browser has no way to distinguish a legitimate local-file null origin from an attacker-crafted sandboxed iframe. The fix is to never add null to the CORS allowlist in production. If local development requires null origin, gate the permissive CORS configuration on a NODE_ENV !== 'production' check.
// VULNERABLE — 'null' in origin allowlist, copied from dev config
const ALLOWED_ORIGINS = new Set([
'https://app.skillaudit.dev',
'http://localhost:3000',
'null', // Added for local file:// testing — left in production
]);
app.use((req, res, next) => {
const origin = req.headers.origin;
if (ALLOWED_ORIGINS.has(origin)) {
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
}
next();
});
// Attacker iframe:
// <iframe sandbox="allow-scripts" srcdoc="<script>
// fetch('https://api.skillaudit.dev/api/data', { credentials: 'include' })
// .then(r => r.json()).then(d => parent.postMessage(d, '*'));
// </script>"></iframe>
// FIXED — never include 'null' in production allowlist; dev-only gate
const ALLOWED_ORIGINS = new Set([
'https://app.skillaudit.dev',
'https://dashboard.skillaudit.dev',
// 'null' intentionally omitted — sandboxed iframes are not a supported client
]);
// If localhost is needed for dev, gate it:
if (process.env.NODE_ENV === 'development') {
ALLOWED_ORIGINS.add('http://localhost:3000');
ALLOWED_ORIGINS.add('http://localhost:5173');
}
app.use((req, res, next) => {
const origin = req.headers.origin;
// Explicitly reject null origin even if someone accidentally adds it later
if (origin && origin !== 'null' && ALLOWED_ORIGINS.has(origin)) {
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
res.setHeader('Vary', 'Origin');
}
next();
});
null in the CORS origin allowlist allows attacker-controlled sandboxed iframes on any page to send credentialed requests that the server treats as allowlisted; fix by removing null from production allowlists and adding an explicit origin !== 'null' guard even if the allowlist check would otherwise pass. Detection: SkillAudit flags CORS allowlist arrays or sets that include the string literal 'null' in source code reachable in production environments.