Claude skill CORS third-party integration security — SA-SKL-CORS3
CORS configuration mistakes in MCP skills that integrate with third-party services go beyond the basic wildcard patterns covered in SA-SKL-CORS and SA-SKL-CORS2. SkillAudit finds four advanced patterns: a wildcard on an authenticated API endpoint that is misunderstood as harmless because credentials are absent, a pre-flight cache entry shared across users behind the same NAT IP that enables cross-user request forgery, a WebSocket endpoint whose HTTP upgrade bypasses CORS pre-flight entirely, and a staging domain in the production CORS allowlist that creates a lateral-movement path. CORS3-001 through CORS3-004 cover each with the specific misconfiguration, the attack scenario, and the fix.
Why third-party integration increases CORS attack surface
An MCP skill with no third-party integrations has a simple CORS boundary: its own API endpoints and its own frontend. When the skill adds third-party integrations — a Stripe billing endpoint, a GitHub webhook receiver, a WebSocket channel for real-time audit results — each integration adds a new CORS boundary with its own requirements. Developers often configure CORS per-route rather than globally, leading to inconsistent policies. The staging domain problem is particularly common: a developer adds the staging domain to the CORS allowlist during development and forgets to remove it before production deployment. The result is a persistent lateral-movement path that persists across deployments until an audit or incident forces a review.
SA-SKL-CORS3 in scope: CORS3-001 (wildcard on authenticated endpoint misunderstood), CORS3-002 (pre-flight cache shared across NAT users), CORS3-003 (WebSocket origin not validated), CORS3-004 (staging domain in production CORS allowlist). See also SA-SKL-CORS for the basic wildcard + credentials pattern and SA-SKL-CORS2 for dynamic origin reflection vulnerabilities.
CORS3-001 — CORS wildcard on authenticated API endpoint
The combination of Access-Control-Allow-Origin: * and Access-Control-Allow-Credentials: true is explicitly prohibited by the browser — browsers refuse to send cookies or Authorization headers when the response includes both. Developers who know this sometimes conclude that Access-Control-Allow-Origin: * without credentials is safe on an authenticated API endpoint because the browser won't send session cookies. This is incorrect for two reasons. First, Bearer token authentication via the Authorization header is not a "credential" in CORS terms — it is a request header that the browser explicitly sends in cross-origin requests when the script explicitly sets it. A malicious page at evil.com that holds a stolen JWT can call your API cross-origin because the wildcard allows the response to be read. Second, non-credential endpoints that return user-specific data (based on query parameters) are exposed to cross-origin read even without cookies.
// VULNERABLE: wildcard on authenticated API — misunderstood as "safe without credentials"
const cors = require('cors');
// Developer thinks: "No credentials = wildcard is safe"
// Reality: Bearer token auth is NOT a credential in CORS terms
// A malicious page can call this endpoint cross-origin with a stolen JWT
// VULNERABLE: wildcard allows any origin to read the response
app.use('/api/audits', cors({ origin: '*' })); // Allows cross-origin read
// The authentication check that follows does NOT prevent cross-origin reads
// because CORS checks happen BEFORE authentication middleware in the browser's model
app.use('/api/audits', authMiddleware); // Too late — CORS already allowed the preflight
app.get('/api/audits', async (req, res) => {
// Returns user-specific audit data
// With wildcard CORS, any origin can read this response if the user has a valid JWT
const audits = await db.audits.findAll({ userId: req.user.id });
res.json(audits);
});
// FIXED: explicit origin allowlist even on "unauthenticated-credential" endpoints
const cors = require('cors');
const CORS_ALLOWLIST = process.env.NODE_ENV === 'production'
? ['https://skillaudit.dev', 'https://app.skillaudit.dev']
: ['http://localhost:3000', 'http://localhost:5173'];
const corsOptions = {
origin: function (origin, callback) {
// Allow requests with no origin (server-to-server, curl, etc.)
if (!origin) return callback(null, true);
if (CORS_ALLOWLIST.includes(origin)) {
callback(null, true);
} else {
callback(new Error(`CORS origin not allowed: ${origin}`));
}
},
credentials: false, // Explicit — no cookies needed for Bearer token auth
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Authorization', 'Content-Type', 'X-Request-ID'],
};
// Apply restrictive CORS to all API routes
app.use('/api/', cors(corsOptions));
// For public, truly read-only endpoints (audit badges, public report summaries):
// wildcard IS safe if the data is intentionally public and not user-specific
app.use('/public/', cors({ origin: '*' })); // Intentionally public — documented
// Separate policies for separate trust levels
// Private API: allowlist only
// Public badge API: wildcard OK — no user-specific data, no actions
Access-Control-Allow-Origin: * to an API endpoint that returns user-specific data or accepts authenticated actions; the developer assumed that absent Allow-Credentials: true the wildcard is safe, but Bearer token authentication is not a CORS credential — a malicious origin that holds a stolen JWT can call the endpoint cross-origin and read the response; the wildcard removes the browser's same-origin protection for all users. Fix: use an explicit origin allowlist for all API endpoints that return user-specific data or perform authenticated actions; reserve origin: '*' only for genuinely public, non-user-specific, read-only endpoints. Detection: SkillAudit flags origin: '*' on routes that also include authMiddleware or requireAuth.CORS3-002 — CORS pre-flight cache shared across users on same NAT IP
The Access-Control-Max-Age header tells browsers to cache the CORS pre-flight response for a specified duration. This cache is per-browser, per-origin, per-URL. In a corporate network where many users share the same public IP via NAT, all users on that IP may appear to have the same origin to the server — particularly if the CORS configuration does not include a Vary: Origin response header. Without Vary: Origin, a CDN or shared HTTP cache may serve Victim A's pre-flight response to Victim B. If Victim A's pre-flight was for a request from an allowed origin, Victim B receives a pre-flight response allowing that origin — even if Victim B's request came from a different, disallowed origin. The Vary: Origin header instructs caches to store separate responses per Origin value, preventing this cross-user contamination.
// VULNERABLE: CORS response missing Vary: Origin header
// Without Vary: Origin, CDN/shared caches can serve pre-flight responses across users
app.use((req, res, next) => {
const origin = req.headers.origin;
if (CORS_ALLOWLIST.includes(origin)) {
res.setHeader('Access-Control-Allow-Origin', origin);
// VULNERABLE: No Vary: Origin header
// A CDN caching this response may serve it to users from different origins
// Victims behind a NAT with a cached pre-flight from an allowed origin
// may have that pre-flight applied to requests from disallowed origins
res.setHeader('Access-Control-Allow-Credentials', 'true');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
res.setHeader('Access-Control-Max-Age', '3600'); // Cache for 1 hour — risky without Vary
}
if (req.method === 'OPTIONS') {
return res.sendStatus(204);
}
next();
});
// FIXED: Vary: Origin ensures per-origin cache isolation
app.use((req, res, next) => {
const origin = req.headers.origin;
// FIXED: Always set Vary: Origin when dynamically setting ACAO
// This prevents CDN/shared-proxy caches from serving one user's pre-flight to another
res.setHeader('Vary', 'Origin');
if (origin && CORS_ALLOWLIST.includes(origin)) {
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Authorization, Content-Type, X-Request-ID');
res.setHeader('Access-Control-Max-Age', '600'); // 10 min — shorter is safer
}
// If origin is not in allowlist: no ACAO header — browser blocks the request
if (req.method === 'OPTIONS') {
return res.sendStatus(204);
}
next();
});
// Equivalent using the 'cors' package — which sets Vary: Origin automatically
// when using a function for origin:
const cors = require('cors');
app.use(cors({
origin: (origin, cb) => {
if (!origin || CORS_ALLOWLIST.includes(origin)) cb(null, true);
else cb(new Error('Not allowed by CORS'));
},
credentials: true,
// cors package sets Vary: Origin automatically for dynamic origin functions
}));
Access-Control-Allow-Origin based on the request's Origin header but omits Vary: Origin from the response; without Vary: Origin, a CDN or shared proxy may cache the CORS pre-flight response from an allowed origin and serve it to subsequent requests from disallowed origins — particularly a risk for users sharing a corporate NAT IP. Fix: always include Vary: Origin in responses that set Access-Control-Allow-Origin dynamically; the cors npm package sets this automatically when the origin option is a function. Detection: SkillAudit flags CORS middleware that dynamically sets Access-Control-Allow-Origin without a corresponding Vary: Origin header.CORS3-003 — WebSocket handshake origin not validated
WebSocket connections begin with an HTTP upgrade request. Unlike regular cross-origin HTTP requests, WebSocket upgrades are not subject to CORS pre-flight checks — the browser sends the upgrade request regardless of CORS headers, and the server must enforce origin checking in its own upgrade handler. If the WebSocket server does not validate the Origin header of the HTTP upgrade request, any web page can open a WebSocket connection to the server on behalf of a visiting user. With cookies included in the WebSocket upgrade (same-site cookies), the connection is authenticated as the visiting user. An attacker who gets a user to visit a malicious page can open a WebSocket connection to the MCP skill's audit-results stream, subscribe to audit job notifications, and read all audit data for that user's active session.
// VULNERABLE: WebSocket server accepts connections from any origin
const WebSocket = require('ws');
const { createServer } = require('http');
const server = createServer(app);
const wss = new WebSocket.Server({ server });
// VULNERABLE: no Origin validation on WebSocket upgrade
wss.on('connection', (ws, req) => {
// req.headers.origin is never checked
// Browser sends WebSocket upgrade requests cross-origin WITH cookies
// Any web page can open a connection as an authenticated user
const userId = sessions.get(req.headers.cookie); // Cookie auth works cross-origin for WS
if (!userId) {
ws.close(1008, 'Unauthorized');
return;
}
// Attacker's page opens ws://skillaudit.dev/ws — succeeds with victim's session cookie
// Then subscribes to audit results stream for that user
ws.send(JSON.stringify({ type: 'subscribe', jobId: req.url.split('/').pop() }));
});
// FIXED: validate Origin header in WebSocket upgrade handler
const WebSocket = require('ws');
const url = require('url');
const WS_ALLOWED_ORIGINS = process.env.NODE_ENV === 'production'
? ['https://skillaudit.dev', 'https://app.skillaudit.dev']
: ['http://localhost:3000', 'http://localhost:5173'];
const wss = new WebSocket.Server({
server,
// verifyClient runs synchronously during the HTTP upgrade
verifyClient: ({ origin, req }, callback) => {
// origin is req.headers.origin
if (!origin) {
// Server-to-server connections (no browser origin) — allow if needed
// For browser-only WS: reject undefined origin
callback(false, 403, 'Origin header required');
return;
}
if (!WS_ALLOWED_ORIGINS.includes(origin)) {
// Log attempt — may indicate CSRF scan or attacker probe
logger.warn({ origin, ip: req.socket.remoteAddress }, 'WebSocket origin rejected');
callback(false, 403, 'Origin not allowed');
return;
}
callback(true); // Allow upgrade
},
});
wss.on('connection', (ws, req) => {
// Origin already verified by verifyClient — connection is from allowed origin
const userId = sessions.get(req.headers.cookie);
if (!userId) {
ws.close(1008, 'Unauthorized');
return;
}
// Handle authenticated WebSocket connection
setupAuditResultsStream(ws, userId);
});
Origin header of the HTTP upgrade request; browsers send WebSocket upgrade requests cross-origin including session cookies — CORS pre-flight does not apply to WebSocket upgrades; any web page can open a WebSocket connection to the skill's server as an authenticated user, subscribing to private data streams or triggering authenticated actions. Fix: use ws library's verifyClient option to check origin against an explicit allowlist before accepting the upgrade; reject connections from disallowed origins with HTTP 403; log rejected origins for intrusion detection. Detection: SkillAudit flags WebSocket server configurations that do not include an origin check in the verifyClient callback or equivalent upgrade middleware.CORS3-004 — Staging domain in production CORS allowlist
During development, staging domains are added to the CORS allowlist so that the staging frontend can call the production API (or vice versa). This is a reasonable convenience during development but creates a security boundary violation in production: the staging environment is typically less secure than production — it may have weaker access controls, be accessible to a larger set of developers, or run on a shared infrastructure that is more susceptible to compromise. If a staging deployment is compromised (via a dependency vulnerability, a weaker admin credential, or a leaked deploy key), the attacker gains the ability to make credentialed cross-origin requests to the production API from the compromised staging origin. Because the staging domain is in the production CORS allowlist, these cross-origin requests succeed with full production user credentials.
// VULNERABLE: staging domain hardcoded in production CORS allowlist const CORS_ALLOWLIST = [ 'https://skillaudit.dev', 'https://app.skillaudit.dev', 'https://staging.skillaudit.dev', // VULNERABLE: staging in production allowlist 'https://preview.skillaudit.dev', // VULNERABLE: preview deployments too 'http://localhost:3000', // VULNERABLE: localhost in production ]; // If staging.skillaudit.dev is compromised: // - Attacker serves malicious JS from staging.skillaudit.dev // - Victim visits staging.skillaudit.dev (or is redirected there) // - Malicious JS makes credentialed fetch() to https://skillaudit.dev/api/... // - Browser includes victim's production cookies (same TLD: skillaudit.dev) // - Production API accepts — staging is in the allowlist // - Attacker reads victim's production audit history, billing data, etc.
// FIXED: separate CORS allowlists for production and non-production environments
// Never hardcode non-production domains in production config
// config/cors.js
const PRODUCTION_ORIGINS = [
'https://skillaudit.dev',
'https://app.skillaudit.dev',
];
const STAGING_ORIGINS = [
'https://staging.skillaudit.dev',
'https://preview.skillaudit.dev',
];
const DEVELOPMENT_ORIGINS = [
'http://localhost:3000',
'http://localhost:5173',
'http://127.0.0.1:3000',
];
// Environment-specific allowlist — never mix production with staging/dev
export function getAllowedOrigins() {
switch (process.env.NODE_ENV) {
case 'production':
return PRODUCTION_ORIGINS; // Strictly production only
case 'staging':
return [...STAGING_ORIGINS, ...PRODUCTION_ORIGINS];
// Staging can call production API — but production does NOT allow staging
case 'development':
return [...DEVELOPMENT_ORIGINS, ...STAGING_ORIGINS];
default:
return DEVELOPMENT_ORIGINS;
}
}
// In server.js:
const corsOptions = {
origin: (origin, cb) => {
const allowed = getAllowedOrigins();
if (!origin || allowed.includes(origin)) cb(null, true);
else cb(new Error(`CORS: origin ${origin} not in ${process.env.NODE_ENV} allowlist`));
},
credentials: true,
};
// CI check — fail deployment if production build includes non-production origins:
// In CI: grep -r 'staging.skillaudit.dev' dist/ && echo "FAIL: staging origin in prod bundle" && exit 1
staging.skillaudit.dev can send same-site cookies to skillaudit.dev); the attack requires only a staging deployment compromise, not a production compromise. Fix: maintain separate CORS_ALLOWLIST per NODE_ENV; production allowlist contains only production domains; validate in CI that the production build contains no non-production origins; remove localhost from all non-development configurations. Detection: SkillAudit flags production deployments whose CORS origin allowlist contains hostnames not matching the application's registered production domain.SkillAudit detection summary — SA-SKL-CORS3
| Pattern ID | Severity | What SkillAudit flags | Fix |
|---|---|---|---|
| CORS3-001 | HIGH | origin: '*' on routes also protected by authMiddleware or Bearer token checks | Explicit origin allowlist for all API routes; reserve wildcard for intentionally public, non-user-specific endpoints |
| CORS3-002 | MEDIUM | Dynamic Access-Control-Allow-Origin without corresponding Vary: Origin response header | Always include Vary: Origin; use cors package with function origin (sets Vary automatically) |
| CORS3-003 | HIGH | WebSocket server without verifyClient origin check or equivalent upgrade-handler origin validation | verifyClient callback checks origin against allowlist; reject non-allowed origins with 403 |
| CORS3-004 | HIGH | Production CORS allowlist containing staging, preview, or localhost hostnames | Environment-specific allowlists; CI check fails if production bundle includes non-production origins |
Related patterns: For basic CORS wildcard with credentials vulnerabilities, see SA-SKL-CORS. For dynamic origin reflection enabling subdomain takeover attacks, see SA-SKL-CORS2. For CSRF vulnerabilities that CORS is designed to mitigate, see SA-SKL-CSRF.