← Blog

Claude MCP skill CORS misconfiguration — WebSocket upgrade and SSE endpoint security — SA-SKL-CORS19

Browsers do not enforce the same-origin policy on WebSocket connections: unlike XHR and Fetch, a WebSocket upgrade from any page succeeds unless the server explicitly validates the Origin header. The same blind spot applies to Server-Sent Events and socket.io polling transports. SA-SKL-CORS19 covers four patterns unique to real-time streaming endpoints in MCP skill registries: WebSocket upgrade without Origin validation, SSE CORS bypass, socket.io wildcard on an authenticated namespace, and long-polling fallback inheriting permissive CORS from static-asset config.

By SkillAudit  |  12 Nov 2026
SA-SKL-CORS19 findings at a glance
CRITICALCORS19-001 — WebSocket upgrade at /api/skills/live-updates does not check the Origin header; browsers do not block cross-origin WebSocket connections; any attacker page can new WebSocket("wss://skillaudit.dev/api/skills/live-updates") and receive a stream of private skill update events including source diffs, audit results in progress, and internal job queue payloads
HIGHCORS19-002 — Server-Sent Events endpoint at /api/audit/stream echoes attacker-supplied callback URL query parameter as the Access-Control-Allow-Origin value; combined with session cookies, an attacker can direct the EventSource response to their origin and read the authenticated audit event stream in real time
CRITICALCORS19-003 — socket.io CORS configured with origin: "*" on the /authenticated namespace; while WebSocket transport does not enforce CORS on the browser side, socket.io's HTTP long-polling transport does; wildcard CORS on polling transport allows an attacker page to io("/authenticated", {transports:["polling"]}) and read authenticated socket messages via XHR polling
HIGHCORS19-004 — Long-polling fallback at /api/skills/poll returns session-authenticated data with Access-Control-Allow-Origin: * inherited from a blanket CORS middleware that was intended only for public static-asset endpoints; attacker page performs credentialed cross-origin read via XHR polling

CORS19-001 — WebSocket upgrade without Origin header validation

When a browser opens a WebSocket connection, it sends an HTTP Upgrade request with an Origin header identifying the page making the request. Unlike XHR or Fetch, the browser does not enforce same-origin policy on WebSocket connections: it does not block the upgrade or restrict cross-origin reads of WebSocket data. This means the entire CORS enforcement burden falls on the server. If the server does not validate the Origin header during the upgrade handshake, any page on the web can connect to the WebSocket endpoint and receive whatever events the server sends — including private skill update events, in-progress audit results, and internal job payloads.

// VULNERABLE — CORS19-001
// ws library upgrade handler: no Origin check.
// Attacker page at evil.com does:
//   const ws = new WebSocket("wss://skillaudit.dev/api/skills/live-updates");
//   ws.onmessage = (e) => exfiltrate(e.data);
// Browser sends the connection — server accepts unconditionally.

const { WebSocketServer } = require('ws');
const wss = new WebSocketServer({ server });

wss.on('connection', (ws, req) => {
  // VULNERABLE: req.headers.origin never checked
  // Any origin can connect and receive private events
  const userId = req.session?.userId;
  if (userId) {
    subscribeToUserEvents(userId, (event) => ws.send(JSON.stringify(event)));
  }
});
// FIXED — CORS19-001
// Fix: Validate the Origin header against an allowlist during the upgrade handshake.
// Reject the upgrade (HTTP 403) if Origin is not in the allowlist.
// This is the only effective CORS enforcement for WebSocket — the browser will not do it.

const ALLOWED_ORIGINS = new Set([
  'https://skillaudit.dev',
  'https://app.skillaudit.dev',
]);

const wss = new WebSocketServer({
  server,
  verifyClient: ({ origin }, callback) => {
    // FIX: Reject upgrade if Origin not in allowlist
    if (!origin || !ALLOWED_ORIGINS.has(origin)) {
      callback(false, 403, 'Forbidden: origin not allowed');
      return;
    }
    callback(true);
  },
});

wss.on('connection', (ws, req) => {
  // Origin already validated by verifyClient
  const userId = req.session?.userId;
  if (userId) {
    subscribeToUserEvents(userId, (event) => ws.send(JSON.stringify(event)));
  }
});

Why browsers do not block cross-origin WebSocket: The WebSocket API predates the modern CORS spec and was deliberately designed to allow cross-origin connections so that WebSocket servers could accept connections from any page. The spec requires browsers to send the Origin header so that servers can decide — but the browser itself will not block a WebSocket connection the way it blocks a cross-origin XHR. This is a commonly misunderstood difference. CORS headers on WebSocket responses (Access-Control-Allow-Origin) have no effect — only the server-side verifyClient check matters.

CORS19-002 — SSE endpoint echoing attacker-supplied URL as ACAO

Server-Sent Events (SSE) connections are made via the browser's EventSource API, which does respect CORS: a cross-origin EventSource connection will be blocked by the browser unless the SSE endpoint responds with an appropriate Access-Control-Allow-Origin header. The vulnerability here is an SSE endpoint that reads the CORS origin from an attacker-supplied query parameter rather than from the request's Origin header — allowing the attacker to inject their own domain as the ACAO value and receive authenticated SSE data cross-origin.

// VULNERABLE — CORS19-002
// SSE endpoint reads 'callback' query param and uses it as ACAO.
// Attacker constructs:
//   const es = new EventSource(
//     "https://skillaudit.dev/api/audit/stream?auditId=123&callback=https://evil.com",
//     { withCredentials: true }
//   );
// Server responds with ACAO: https://evil.com — browser allows the cross-origin read.

app.get('/api/audit/stream', requireAuth, (req, res) => {
  const { auditId, callback } = req.query;

  res.setHeader('Content-Type', 'text/event-stream');
  res.setHeader('Cache-Control', 'no-cache');
  res.setHeader('Connection', 'keep-alive');

  // VULNERABLE: ACAO sourced from attacker-controlled query param
  if (callback) {
    res.setHeader('Access-Control-Allow-Origin', callback);
    res.setHeader('Access-Control-Allow-Credentials', 'true');
  }

  streamAuditEvents(auditId, req.user.id, res);
});
// FIXED — CORS19-002
// Fix: ACAO must always come from the request's Origin header validated against an allowlist.
// Never echo a client-supplied URL as ACAO — treat it like any other injection vector.

const ALLOWED_ORIGINS = new Set([
  'https://skillaudit.dev',
  'https://app.skillaudit.dev',
]);

app.get('/api/audit/stream', requireAuth, (req, res) => {
  const { auditId } = req.query; // FIX: 'callback' param removed entirely

  res.setHeader('Content-Type', 'text/event-stream');
  res.setHeader('Cache-Control', 'no-cache');
  res.setHeader('Connection', 'keep-alive');

  // FIX: Validate Origin from request header, not from query params
  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');
  }

  streamAuditEvents(auditId, req.user.id, res);
});

SSE with credentials requires explicit CORS: new EventSource(url, {'{'} withCredentials: true {'}'} ) is a cross-origin credentialed request — the same CORS rules apply as for XHR with credentials: 'include'. The server must respond with Access-Control-Allow-Origin set to the specific requesting origin (not *) and Access-Control-Allow-Credentials: true. Missing either header causes the browser to block the SSE stream. The fix is the same as for XHR: validate the Origin header against an allowlist and reflect it back.

CORS19-003 — socket.io CORS wildcard on authenticated namespace

socket.io supports two transports: WebSocket (upgraded from HTTP) and long-polling (plain XHR). The CORS configuration in socket.io applies to the HTTP polling transport — it sets Access-Control-Allow-Origin on the HTTP polling responses. When socket.io is configured with cors: { origin: "*" } on a namespace that requires authentication, attackers can force the polling transport and read authenticated socket messages via cross-origin XHR, bypassing the common assumption that WebSocket connections are protected by the WebSocket Origin check.

// VULNERABLE — CORS19-003
// socket.io CORS origin:* on /authenticated namespace.
// Attacker page forces polling transport:
//   const socket = io("https://skillaudit.dev/authenticated", {
//     transports: ["polling"],
//     withCredentials: true,
//   });
//   socket.on("audit:result", (data) => exfiltrate(data));
// Browser XHR polling request gets ACAO:* — browser allows cross-origin read.
// Wait — ACAO:* + withCredentials is blocked by browsers.
// But if attacker omits withCredentials and relies on a separate auth mechanism
// (e.g. token in URL), the wildcard ACAO allows the read.

const io = require('socket.io')(server, {
  cors: {
    // VULNERABLE: wildcard allows cross-origin polling connections from any page
    origin: '*',
    methods: ['GET', 'POST'],
  },
});

const authNamespace = io.of('/authenticated');
authNamespace.use(socketAuthMiddleware); // checks session cookie
authNamespace.on('connection', (socket) => {
  socket.join(`user:${socket.userId}`);
  emitAuditEvents(socket);
});
// FIXED — CORS19-003
// Fix: Provide an origin validation function in socket.io CORS config.
// Never use origin:'*' on authenticated namespaces.
// The function mirrors the same ALLOWED_ORIGINS Set used for HTTP CORS middleware.

const ALLOWED_ORIGINS = new Set([
  'https://skillaudit.dev',
  'https://app.skillaudit.dev',
]);

const io = require('socket.io')(server, {
  cors: {
    // FIX: origin as a function — called with (origin, callback)
    origin: (origin, callback) => {
      if (!origin || ALLOWED_ORIGINS.has(origin)) {
        callback(null, true);
      } else {
        callback(new Error('Origin not allowed'));
      }
    },
    credentials: true,
    methods: ['GET', 'POST'],
  },
});

const authNamespace = io.of('/authenticated');
authNamespace.use(socketAuthMiddleware);
authNamespace.on('connection', (socket) => {
  socket.join(`user:${socket.userId}`);
  emitAuditEvents(socket);
});

WebSocket transport vs. polling transport CORS: socket.io's WebSocket transport uses a raw WebSocket upgrade — the browser does not apply CORS to it, so the server's verifyClient or connection middleware must validate the Origin header manually. socket.io's polling transport uses HTTP XHR — the browser does apply CORS, so the socket.io CORS config controls it. The practical risk is that an attacker can choose the transport that best bypasses a misconfigured server: if WebSocket is protected but polling has wildcard CORS, the attacker uses polling. Both transports must be secured independently.

CORS19-004 — Long-polling fallback inheriting permissive CORS from static asset config

When a WebSocket connection fails (network restrictions, proxy interference), the MCP registry falls back to long-polling at /api/skills/poll. This endpoint was added late, after the main CORS config was already in place, and it was mounted under the same Express router as the static-asset serving paths. A blanket CORS middleware applied to that router emitted Access-Control-Allow-Origin: * for all unauthenticated-looking requests, which the long-polling endpoint matched because its session auth was checked inside the route handler rather than before the CORS middleware.

// VULNERABLE — CORS19-004
// Static-asset router has blanket ACAO:* middleware.
// Long-polling fallback endpoint was added to same router for convenience.
// Session auth check inside route handler runs after CORS headers are sent.
// Attacker page does cross-origin XHR GET /api/skills/poll?since=0 — gets ACAO:*,
// reads poll response body which includes authenticated user data.

// staticRouter.js
const staticRouter = express.Router();

// VULNERABLE: blanket ACAO:* intended for public assets — applied to all routes on this router
staticRouter.use((req, res, next) => {
  res.setHeader('Access-Control-Allow-Origin', '*');
  next();
});

// Public static routes — ACAO:* is fine here
staticRouter.get('/assets/:file', serveStaticAsset);
staticRouter.get('/icons/:name', serveIcon);

// VULNERABLE: long-polling fallback added to same router without recognizing CORS implications
staticRouter.get('/api/skills/poll', (req, res) => {
  if (!req.session?.userId) return res.status(401).json({ error: 'Unauthorized' });
  // CORS headers already sent with ACAO:* before we got here
  pollForSkillUpdates(req.session.userId, req.query.since, res);
});
// FIXED — CORS19-004
// Fix: Move authenticated endpoints to a separate router with strict CORS.
// Never mount authenticated endpoints on a router with blanket ACAO:* middleware.
// Separate CORS config by authentication requirement, not by URL path prefix.

const ALLOWED_ORIGINS = new Set([
  'https://skillaudit.dev',
  'https://app.skillaudit.dev',
]);

// FIX: Authenticated API router with strict CORS
const apiRouter = express.Router();
apiRouter.use((req, res, next) => {
  const origin = req.headers.origin;
  // FIX: Validate origin against allowlist — no wildcard on authenticated routes
  if (origin && ALLOWED_ORIGINS.has(origin)) {
    res.setHeader('Access-Control-Allow-Origin', origin);
    res.setHeader('Access-Control-Allow-Credentials', 'true');
    res.setHeader('Vary', 'Origin');
  }
  if (req.method === 'OPTIONS') return res.sendStatus(204);
  next();
});

apiRouter.get('/api/skills/poll', requireAuth, (req, res) => {
  // requireAuth middleware runs; CORS already set correctly above
  pollForSkillUpdates(req.user.id, req.query.since, res);
});

// Static asset router: ACAO:* only on truly public routes
const staticRouter = express.Router();
staticRouter.use((req, res, next) => {
  res.setHeader('Access-Control-Allow-Origin', '*');
  next();
});
staticRouter.get('/assets/:file', serveStaticAsset);

CORS middleware placement is load-bearing: CORS headers must be set after the routing decision that determines whether a request is for a public or private resource — not before. A blanket middleware applied to an entire router is a footgun: any new authenticated route added to that router inherits the CORS config, often silently. The correct pattern is to define separate routers for public and authenticated paths, each with their own explicit CORS middleware, and never rely on route-level auth checks to protect routes whose CORS middleware already emitted permissive headers.

Summary — SA-SKL-CORS19 at a glance

PatternRoot causeFixSeverity
CORS19-001WebSocket upgrade handler does not check Origin headerverifyClient allowlist check on upgradeCRITICAL
CORS19-002SSE endpoint echoes client-supplied URL as ACAOValidate Origin header; remove callback paramHIGH
CORS19-003socket.io cors: {'{'}origin:"*"{'}'} on authenticated namespaceOrigin validation function in socket.io CORS configCRITICAL
CORS19-004Authenticated long-polling endpoint on blanket-ACAO:* routerSeparate authenticated routes onto their own CORS-aware routerHIGH

SkillAudit's CORS scanner checks all four SA-SKL-CORS19 patterns: it attempts cross-origin WebSocket upgrades, SSE connections with injected callback parameters, socket.io polling transport connections, and long-polling requests — and reports whether any authenticated data is returned cross-origin. See also SA-SKL-CORS18 (credentialed cross-origin reads and cache poisoning) and SA-SKL-CORS17 (GraphQL and WebSocket CORS).