← Blog

Claude MCP skill CORS bypass via trusted subdomain XSS and localhost in production — SA-SKL-CORS14

CORS allowlists create a web of trust: every origin in the list is a potential attack surface against the API. The SA-SKL-CORS14 rule set covers four patterns that expand that surface beyond what developers intend — including a docs subdomain whose XSS exposure (from Markdown injection in user-contributed content or a third-party docs tool) can be used to read credentialed API responses; a middleware wiring error that applies CORS validation only to preflight routes while the main request handler reflects the Origin header unchecked; a non-TLS entry in the allowlist that is interceptable by a network-level attacker; and localhost origins that persist from development into production configuration.

By SkillAudit  |  8 Nov 2026

CORS allowlist trust chains in MCP skill deployments

CORS is a browser-enforced mechanism that limits which origins can read cross-origin responses carrying credentials. When you add docs.skillaudit.dev to the api.skillaudit.dev CORS allowlist and set Access-Control-Allow-Credentials: true, you are asserting that every page on that docs subdomain is as trustworthy as the API itself. If an attacker can inject executable JavaScript into any page on the docs subdomain — through a stored XSS in user-contributed content, a Markdown injection in the docs platform, or a vulnerability in a third-party documentation tool — they can make credentialed API requests to the production API and read the responses. The same logic applies to localhost origins and non-TLS origins: a localhost origin can be exploited by any process on the same machine, and a non-TLS origin can be intercepted and replaced by any network-level attacker on the same path.

The correct mental model is: your CORS allowlist defines the minimum-security boundary of your API. Every entry in the list must have a security posture at least as strong as the API itself. Subdomains with user-contributed content, development origins, and non-TLS origins all fail this test.

SA-SKL-CORS14 findings at a glance
HIGHCORS14-001 — docs.skillaudit.dev in CORS allowlist; XSS on docs subdomain via Markdown injection or third-party docs tool reads credentialed api.skillaudit.dev responses; Access-Control-Allow-Credentials: true confirmed
HIGHCORS14-002 — CORS middleware applied only to OPTIONS preflight handler; main request handler reflects Origin without re-checking allowlist; non-simple requests bypass CORS validation after preflight cache (Access-Control-Max-Age) expires
HIGHCORS14-003 — CORS allowlist contains http:// (non-TLS) origin; unencrypted traffic from that origin interceptable by network MitM; attacker injects arbitrary response from the allowed non-TLS origin
MEDIUMCORS14-004 — Production CORS config permits localhost:3000 and localhost:8080; any process on the same host can make credentialed API requests; developer left dev origins in production CORS_ALLOWED_ORIGINS

CORS14-001 — Docs subdomain in allowlist enables XSS-to-API pivot

Documentation subdomains are frequently built on platforms that allow user-contributed content — feedback widgets, community comments, editable example snippets, or the documentation system itself rendering untrusted Markdown. These platforms often have a weaker XSS posture than the core product, because the security review focuses on the main application and the docs tool is treated as a static site. When this subdomain appears in the API's CORS allowlist with credentials: true, any script executing on the docs subdomain can make authenticated API requests on behalf of the logged-in user.

There are two independent controls to apply: remove the docs subdomain from the API CORS allowlist (use a dedicated preview API or public read-only endpoints for any documentation that needs live data), and harden the docs subdomain's Content Security Policy to block inline scripts and restrict script-src to known hosts. The CSP is a defense in depth measure — the allowlist change is the primary fix.

// VULNERABLE — docs subdomain in CORS allowlist with credentials: true
import cors from 'cors';

const ALLOWED_ORIGINS = [
  'https://app.skillaudit.dev',
  'https://docs.skillaudit.dev',  // VULNERABLE: docs subdomain with user content
];

app.use(cors({
  origin: (origin, callback) => {
    if (!origin || ALLOWED_ORIGINS.includes(origin)) {
      callback(null, true);
    } else {
      callback(new Error('Not allowed by CORS'));
    }
  },
  credentials: true, // combined with docs subdomain = XSS pivot to API
}));
// FIXED — docs subdomain removed from allowlist; CSP added to docs subdomain
import cors from 'cors';

// Only origins that are under tight security control belong here.
// docs.skillaudit.dev was removed — the docs tool uses only public read-only endpoints.
const ALLOWED_ORIGINS = [
  'https://app.skillaudit.dev',
];

app.use(cors({
  origin: (origin, callback) => {
    // No origin = same-origin request (server-to-server or curl) — allow
    if (!origin) return callback(null, true);
    if (ALLOWED_ORIGINS.includes(origin)) {
      callback(null, true);
    } else {
      // Log rejected origins for monitoring — may indicate probe or misconfiguration
      logger.warn('CORS origin rejected', { origin, path: req?.path });
      callback(new Error('Not allowed by CORS'));
    }
  },
  credentials: true,
}));

// docs.skillaudit.dev Caddyfile — CSP prevents XSS from using credentialed fetch
// even if an attacker finds a way back into the allowlist in the future
// skillaudit-docs.dev {
//   header Content-Security-Policy "default-src 'self'; script-src 'self'; object-src 'none';"
//   header X-Frame-Options "DENY"
//   reverse_proxy localhost:4000
// }

CORS14-002 — Preflight-only CORS check bypassed after cache expiry

The cors() middleware in Express and similar frameworks handles both the OPTIONS preflight request and sets CORS headers on the actual response. A common mistake is to apply the middleware only to a dedicated OPTIONS route handler, reasoning that the preflight is where CORS validation happens. This misunderstands the browser CORS model: the preflight cache (Access-Control-Max-Age) has a finite lifetime, and after it expires the browser will re-send a preflight — but the main request handler still reflects the Origin header from whatever origin sent the request, without rechecking the allowlist. An attacker who times their request correctly, or who sends a non-simple request type that the browser does not cache, can receive a reflected Access-Control-Allow-Origin from the main handler without passing through the allowlist check.

The fix is to apply the CORS middleware to all routes — not just the OPTIONS handler. The cors() middleware correctly handles both preflights and sets CORS response headers on actual requests in a single app.use() call.

// VULNERABLE — cors() applied only to OPTIONS route; main handlers reflect Origin freely
import cors from 'cors';
import express from 'express';

const app = express();

const corsOptions = {
  origin: ['https://app.skillaudit.dev'],
  credentials: true,
};

// VULNERABLE: cors middleware only on OPTIONS — main route handlers not covered
app.options('*', cors(corsOptions));

// This handler reflects Origin in its own ACAO header without checking allowlist
app.get('/api/audits', (req, res) => {
  // VULNERABLE: manually sets ACAO to whatever Origin was sent; allowlist not checked
  res.set('Access-Control-Allow-Origin', req.headers.origin);
  res.set('Access-Control-Allow-Credentials', 'true');
  res.json({ audits: [] });
});
// FIXED — cors() middleware applied globally before all routes
import cors from 'cors';
import express from 'express';

const app = express();

const ALLOWED_ORIGINS = ['https://app.skillaudit.dev'];

const corsOptions = {
  origin: (origin, callback) => {
    if (!origin || ALLOWED_ORIGINS.includes(origin)) {
      callback(null, true);
    } else {
      callback(new Error('Not allowed by CORS'));
    }
  },
  credentials: true,
  // Explicit allowedHeaders — do not use '*' with credentials: true
  allowedHeaders: ['Content-Type', 'Authorization', 'X-Request-Id'],
  methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
  maxAge: 600, // preflight cache: 10 minutes
};

// Apply cors() BEFORE all route definitions — handles both OPTIONS and actual requests
app.use(cors(corsOptions));

// Now this handler benefits from CORS headers set by middleware; no manual ACAO header
app.get('/api/audits', auth, async (req, res) => {
  const audits = await getAudits(req.user.orgId);
  res.json({ audits }); // CORS headers already set correctly by middleware
});

// Never set Access-Control-Allow-Origin manually in route handlers
// — always let the cors() middleware manage it

CORS14-003 — Non-TLS origin in allowlist enables network MitM

An HTTP (non-TLS) origin in the CORS allowlist means that any network-level attacker on the path between a user's browser and http://app.skillaudit.dev can intercept the request, inject an arbitrary response, and that response will be treated by the browser as coming from an allowed CORS origin. On shared WiFi, in cloud hosting environments where multiple tenants share a network segment, or on any network where the attacker can perform ARP spoofing or DNS hijacking, this gives the attacker full read access to credentialed API responses. The browser has no mechanism to distinguish a legitimate HTTP response from an injected one — TLS is the only protection.

The fix is to audit the CORS allowlist and reject any origin that does not use the https:// scheme. This check should be enforced programmatically in the allowlist validation function so that even if a developer accidentally adds an HTTP origin to the environment variable, it is rejected at startup.

// VULNERABLE — HTTP origin in allowlist; network MitM can inject responses
const ALLOWED_ORIGINS = [
  'https://app.skillaudit.dev',
  'http://app.skillaudit.dev',  // VULNERABLE: non-TLS; interceptable on the wire
  'http://beta.skillaudit.dev', // VULNERABLE: beta environment using HTTP
];

app.use(cors({
  origin: (origin, callback) => {
    if (!origin || ALLOWED_ORIGINS.includes(origin)) {
      callback(null, true);
    } else {
      callback(new Error('Not allowed by CORS'));
    }
  },
  credentials: true,
}));
// FIXED — allowlist validation enforces https:// scheme; http:// origins rejected at startup
function buildCorsAllowlist(rawOrigins) {
  const origins = rawOrigins
    .split(',')
    .map(o => o.trim())
    .filter(Boolean);

  for (const origin of origins) {
    // Reject non-TLS origins — they are interceptable on the network
    if (origin.startsWith('http://')) {
      throw new Error(
        `CORS allowlist contains non-TLS origin: ${origin}. ` +
        `Only https:// origins are permitted. ` +
        `Fix CORS_ALLOWED_ORIGINS in the production environment.`
      );
    }
    // Reject wildcard or overly broad entries
    if (origin === '*' || origin.includes('*')) {
      throw new Error(`CORS allowlist contains wildcard origin: ${origin}`);
    }
    // Reject localhost in production
    if (origin.includes('localhost') || origin.includes('127.0.0.1')) {
      if (process.env.NODE_ENV === 'production') {
        throw new Error(`CORS allowlist contains localhost origin in production: ${origin}`);
      }
    }
  }
  return origins;
}

// Called at server startup — throws immediately if config is insecure
const ALLOWED_ORIGINS = buildCorsAllowlist(process.env.CORS_ALLOWED_ORIGINS ?? '');

app.use(cors({
  origin: (origin, callback) => {
    if (!origin || ALLOWED_ORIGINS.includes(origin)) {
      callback(null, true);
    } else {
      callback(new Error('Not allowed by CORS'));
    }
  },
  credentials: true,
}));

CORS14-004 — Localhost origins in production CORS configuration

It is common practice to add localhost:3000 and localhost:8080 to the CORS allowlist during development so that the local React dev server can make credentialed requests to the API. The problem occurs when the same environment variable (or the same configuration file) is used for the production deployment without removing the localhost entries. Any process running on the same machine as the production API server — a misconfigured background job, a compromised dependency, another tenant's container on shared hosting — can make credentialed API requests using a fake localhost origin and read the responses. Cloud shell environments, shared hosting platforms, and CI runners that keep containers alive between jobs are all scenarios where this matters.

The correct fix is to maintain separate CORS_ALLOWED_ORIGINS values per deployment environment, enforced by the startup validation function above. The production value should contain no localhost entries. If the development workflow requires localhost in the allowlist, it should be set only in .env.development and never committed to the production environment configuration.

# VULNERABLE — .env shared across environments; localhost left in production config
# .env (used for both development and production)
CORS_ALLOWED_ORIGINS=https://app.skillaudit.dev,localhost:3000,localhost:8080
# localhost:3000 and localhost:8080 grant API access to any process on the same host
# FIXED — separate environment variables per deployment

# .env.development (never committed to production infra)
CORS_ALLOWED_ORIGINS=https://app.skillaudit.dev,http://localhost:3000,http://localhost:8080

# .env.production (or secrets manager entry for production)
# No localhost, no http:// origins
CORS_ALLOWED_ORIGINS=https://app.skillaudit.dev

# Dockerfile or deployment config — only mount the production env file
# ENV NODE_ENV=production
# COPY .env.production .env

# Or in docker-compose.prod.yml:
# environment:
#   - CORS_ALLOWED_ORIGINS=https://app.skillaudit.dev
#   - NODE_ENV=production
// Runtime enforcement — reject localhost in production at startup, not silently
// Add this check to the buildCorsAllowlist() function shown in CORS14-003 above:

if (process.env.NODE_ENV === 'production') {
  const localhostOrigins = origins.filter(
    o => o.includes('localhost') || o.includes('127.0.0.1') || o.includes('0.0.0.0')
  );
  if (localhostOrigins.length > 0) {
    // Fail hard at startup rather than silently permitting a security misconfiguration
    throw new Error(
      `Production CORS allowlist contains localhost origins: ${localhostOrigins.join(', ')}. ` +
      `Remove these from CORS_ALLOWED_ORIGINS in the production environment.`
    );
  }
}

Detection with SkillAudit

SkillAudit's SA-SKL-CORS14 rule set inspects CORS configuration through static analysis of the repository and a runtime probe phase. The static pass reads the cors() middleware configuration, extracts the origin allowlist from environment variable assignments and configuration files, and flags HTTP origins, localhost entries, and wildcard origins. It also traces the middleware application pattern to identify cases where cors() is applied only to OPTIONS routes rather than globally. The runtime probe sends credentialed cross-origin requests from a synthesized non-allowlisted origin directly to both the OPTIONS endpoint and the main handler to verify that both respond with the correct CORS headers — catching the preflight-only wiring error even when the static analysis suggests the allowlist is correct.

Run SA-SKL-CORS14 on your skill: Paste your MCP skill's GitHub URL at skillaudit.dev to get a full scan. The free tier covers public repositories and returns a shareable security badge.

FindingSeverityVulnerable patternFix
CORS14-001HighDocs subdomain in CORS allowlist; XSS on docs reads credentialed API responsesRemove docs subdomain from allowlist; harden docs CSP (script-src 'self')
CORS14-002Highcors() applied only to OPTIONS route; main handler reflects Origin without allowlist checkApply app.use(cors(corsOptions)) globally before all route definitions
CORS14-003Highhttp:// origin in allowlist; network MitM intercepts and injects arbitrary responseValidate allowlist at startup; reject any origin not using https:// scheme
CORS14-004MediumLocalhost origins in production CORS_ALLOWED_ORIGINS; any co-located process gets API accessSeparate env configs per deployment; throw at startup if localhost found in production