Claude MCP skill CORS misconfiguration in GraphQL endpoints and WebSocket upgrade requests — SA-SKL-CORS17
CORS (Cross-Origin Resource Sharing) is the browser security mechanism that prevents a malicious page at evil.com from reading authenticated API responses from skillaudit.dev. CORS misconfigurations are especially subtle at non-REST endpoints — GraphQL, WebSocket, and Server-Sent Event (SSE) endpoints — because developers apply CORS middleware to their Express REST routes but forget that these specialized endpoints have their own CORS considerations. GraphQL POSTs with text/plain content-type skip the preflight entirely, WebSocket upgrade requests carry cookies but have no browser-enforced CORS check, and SSE streams are GET requests that also carry cookies and bypass CORS preflights. SA-SKL-CORS17 covers four CORS misconfiguration patterns specific to MCP skill real-time and GraphQL infrastructure.
/graphql has no CORS policy applied; attacker page sends a simple POST with Content-Type: text/plain (a "simple" request type) which skips browser preflight; attacker reads all audit data for the authenticated user including source code findings and security reportsOrigin request header; browser sends Origin on every WebSocket upgrade; attacker page opens ws://skillaudit.dev/ws with the user's session cookies and receives real-time audit completion events and report data/graphql responds with Access-Control-Allow-Origin: * by default for introspection queries; schema exposed cross-origin to any attacker page; combined with CORS17-001, enables full cross-origin data accessEventSource); browser sends cookies on SSE GET request without preflight; Origin header present in SSE request but server does not validate it; attacker page receives real-time audit events for the authenticated userCORS17-001 — GraphQL POST with text/plain bypasses CORS preflight
Browser CORS preflights are only triggered by "non-simple" requests. A POST with Content-Type: application/json triggers a preflight OPTIONS request. A POST with Content-Type: text/plain is a "simple" request and no preflight is sent — the browser fires the POST directly. GraphQL servers that accept any content-type (including text/plain) are vulnerable: an attacker page can POST a valid GraphQL query as a plain text body and read the response body because no preflight was required.
// VULNERABLE — CORS17-001
// GraphQL endpoint with no CORS policy — simple POST bypasses preflight.
// Attacker page sends: fetch("https://skillaudit.dev/graphql", {
// method: "POST", credentials: "include",
// headers: { "Content-Type": "text/plain" },
// body: JSON.stringify({ query: "{ currentUser { audits { id score findings } } }" })
// })
// No preflight — CORS17-001 returns all audit data to attacker origin.
import { createHandler } from 'graphql-http/lib/use/express';
// VULNERABLE: CORS middleware not applied to this route
app.use('/graphql', createHandler({ schema, rootValue: resolvers }));
// FIXED — CORS17-001
// Fix 1: Apply explicit CORS middleware to /graphql with the same origin allowlist as REST API.
// Fix 2: Reject requests with Content-Type other than application/json (closes simple-request bypass).
// Fix 3: Validate Content-Type in the GraphQL handler before processing.
import cors from 'cors';
const ALLOWED_ORIGINS = ['https://skillaudit.dev', 'https://app.skillaudit.dev'];
const graphqlCors = cors({
origin: (origin, callback) => {
if (!origin || ALLOWED_ORIGINS.includes(origin)) {
callback(null, true);
} else {
callback(new Error('CORS: origin not allowed'));
}
},
credentials: true,
});
// FIX: CORS middleware applied to /graphql
app.use('/graphql', graphqlCors);
// FIX: Reject non-application/json content-type to close simple-request bypass
app.use('/graphql', (req, res, next) => {
const ct = req.headers['content-type'] || '';
if (!ct.includes('application/json')) {
return res.status(415).json({ error: 'Content-Type must be application/json' });
}
next();
});
app.use('/graphql', createHandler({ schema, rootValue: resolvers }));
Why text/plain bypasses preflight: The CORS simple request rules allow POST with Content-Type values of application/x-www-form-urlencoded, multipart/form-data, or text/plain without a preflight. GraphQL's JSON body is normally application/json (which triggers a preflight), but most GraphQL servers will parse the body regardless of the declared content-type. Rejecting non-JSON content-type at the middleware layer is a critical defense-in-depth measure.
CORS17-002 — WebSocket upgrade Origin header not validated
WebSocket connections are initiated with an HTTP upgrade request. Browsers always include the Origin header on WebSocket upgrade requests. Unlike regular HTTP requests, there is no browser-enforced CORS policy for WebSocket connections — the server must validate the Origin header itself. If the server does not check the Origin on upgrade, any page can open a WebSocket connection to the skill's server using the victim's cookies (since cookies are sent on the upgrade request). The attacker page then receives all messages pushed over the WebSocket including real-time audit events.
// VULNERABLE — CORS17-002
// WebSocket upgrade handler does not validate Origin header.
// Attacker page at evil.com opens: new WebSocket("wss://skillaudit.dev/ws")
// Browser sends Origin: https://evil.com in upgrade request — server ignores it.
// User's session cookie attached — socket authenticated as victim user.
import { WebSocketServer } from 'ws';
const wss = new WebSocketServer({ server });
server.on('upgrade', (req, socket, head) => {
// VULNERABLE: Origin header not validated
wss.handleUpgrade(req, socket, head, (ws) => {
wss.emit('connection', ws, req);
});
});
wss.on('connection', (ws, req) => {
const session = getSessionFromCookie(req); // authenticated via cookie
subscribeToAuditEvents(session.userId, (event) => ws.send(JSON.stringify(event)));
});
// FIXED — CORS17-002
// Fix: Validate Origin header in the upgrade handler — reject non-allowlisted origins.
const ALLOWED_WS_ORIGINS = new Set(['https://skillaudit.dev', 'https://app.skillaudit.dev']);
server.on('upgrade', (req, socket, head) => {
const origin = req.headers.origin;
// FIX: Reject upgrade requests from non-allowlisted origins
if (!origin || !ALLOWED_WS_ORIGINS.has(origin)) {
socket.write('HTTP/1.1 403 Forbidden\r\n\r\n');
socket.destroy();
return;
}
wss.handleUpgrade(req, socket, head, (ws) => {
wss.emit('connection', ws, req);
});
});
CORS17-003 — Apollo Server default CORS exposes schema cross-origin
Apollo Server's default configuration responds to introspection queries (and all other GraphQL queries) with Access-Control-Allow-Origin: *. This means any page on the internet can read the full GraphQL schema via an introspection query. Combined with the text/plain preflight bypass from CORS17-001, any page can also read actual data. The fix is to apply explicit CORS configuration to the Apollo Server instance and to disable introspection in production environments.
// VULNERABLE — CORS17-003
// Apollo Server default CORS sends ACAO:* — schema readable from any origin.
// Attacker page sends introspection query as text/plain POST — no preflight, schema returned.
import { ApolloServer } from '@apollo/server';
import { expressMiddleware } from '@apollo/server/express4';
const apollo = new ApolloServer({ typeDefs, resolvers });
await apollo.start();
// VULNERABLE: expressMiddleware with default CORS (ACAO:*)
app.use('/graphql', expressMiddleware(apollo));
// FIXED — CORS17-003
// Fix 1: Pass explicit corsOptions to expressMiddleware — same allowlist as REST API.
// Fix 2: Disable introspection in production via NODE_ENV check.
// Fix 3: Reject text/plain content-type as in CORS17-001 fix.
const apollo = new ApolloServer({
typeDefs,
resolvers,
// FIX 2: Disable introspection in production
introspection: process.env.NODE_ENV !== 'production',
});
await apollo.start();
app.use('/graphql',
// FIX 3: Reject non-JSON
(req, res, next) => {
if (req.method === 'POST' && !(req.headers['content-type'] || '').includes('application/json')) {
return res.status(415).end();
}
next();
},
// FIX 1: Explicit CORS configuration — no ACAO:* in production
expressMiddleware(apollo, {
cors: {
origin: ALLOWED_ORIGINS,
credentials: true,
},
})
);
CORS17-004 — SSE (EventSource) endpoint missing Origin validation
Server-Sent Events (SSE) use the browser's EventSource API, which always uses GET requests. GET requests are "simple" requests under CORS rules — no preflight is sent, and the browser includes the user's cookies on the GET request. The server must validate the Origin header manually on SSE endpoints. Without this check, any page can subscribe to real-time audit events by calling new EventSource("https://skillaudit.dev/api/events", { withCredentials: true }) and receive all events pushed to the authenticated user.
// VULNERABLE — CORS17-004
// SSE endpoint does not validate Origin header — attacker page subscribes with victim's cookies.
// new EventSource("https://skillaudit.dev/api/events", { withCredentials: true })
// No preflight for GET — attacker receives all real-time audit events.
app.get('/api/events', requireAuth, (req, res) => {
// VULNERABLE: Origin not checked — any page receives SSE stream as authenticated user
res.setHeader('Content-Type', 'text/event-stream');
res.setHeader('Cache-Control', 'no-cache');
res.setHeader('Connection', 'keep-alive');
const cleanup = subscribeToEvents(req.user.id, (event) => {
res.write(`data: ${JSON.stringify(event)}\n\n`);
});
req.on('close', cleanup);
});
// FIXED — CORS17-004
// Fix: Validate Origin header on SSE endpoint before streaming events.
// SSE is a GET — CORS middleware alone is insufficient; Origin must be checked explicitly.
app.get('/api/events', requireAuth, (req, res) => {
const origin = req.headers.origin;
// FIX: Validate Origin before streaming — treat missing Origin as suspicious
if (!origin || !ALLOWED_ORIGINS.includes(origin)) {
return res.status(403).end();
}
// FIX: Set explicit CORS headers on SSE response
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
res.setHeader('Content-Type', 'text/event-stream');
res.setHeader('Cache-Control', 'no-cache');
res.setHeader('Connection', 'keep-alive');
const cleanup = subscribeToEvents(req.user.id, (event) => {
res.write(`data: ${JSON.stringify(event)}\n\n`);
});
req.on('close', cleanup);
});
Summary — SA-SKL-CORS17 at a glance
| Pattern | Root cause | Fix | Severity |
|---|---|---|---|
| CORS17-001 | GraphQL endpoint has no CORS policy; text/plain POST bypasses preflight; cross-origin read of all authenticated user data | Explicit CORS middleware on /graphql; reject non-application/json content-type | Critical |
| CORS17-002 | WebSocket upgrade handler ignores Origin header; browser-enforced CORS does not apply to WS; attacker page subscribes with victim cookies | Validate Origin in upgrade handler; destroy socket on non-allowlisted origin | Critical |
| CORS17-003 | Apollo Server default sends ACAO: *; introspection schema readable cross-origin; combined with text/plain bypass allows full data access | Explicit cors: { origin: allowlist } in expressMiddleware; disable introspection in production | High |
| CORS17-004 | SSE (EventSource) is a simple GET; no preflight fires; Origin not checked on SSE endpoint; attacker receives real-time audit events | Validate Origin header on SSE endpoint; set explicit ACAO header to matched origin | High |
Does your MCP skill's GraphQL and WebSocket infrastructure enforce CORS correctly?
SkillAudit scans for missing CORS middleware on GraphQL endpoints, WebSocket upgrade handlers that skip Origin validation, Apollo Server default CORS headers, and SSE endpoints that miss the Origin check — before an attacker reads your users' audit reports cross-origin.
Audit your MCP skill →