← Blog

Claude skill CORS advanced security — SA-SKL-CORS2

Most MCP skill CORS audits stop at "don't use origin: '*' with credentials." That basic check misses four bypass patterns that survive a naive allowlist: subdomain wildcard via endsWith string matching, null origin from sandboxed iframes, pre-flight result caching via long maxAge that delays enforcement of CORS policy changes, and legacy JSONP endpoints that bypass CORS entirely. CORS2-001 through CORS2-004 cover each pattern with the specific code that fails and the exact allowlist or protocol-based fix.

By SkillAudit  |  5 Nov 2026

Why CORS is harder than it looks for MCP skills

CORS is a browser-enforced policy, not a server-enforced access control. The server sets response headers; the browser decides whether to expose the response to the requesting script. MCP skills that serve both API calls and dashboard UIs must configure CORS for the dashboard origin while rejecting everything else. The temptation is to implement the allowlist as a string match — and string matching is exactly where the bypasses live. CORS2-001 bypasses a suffix match. CORS2-002 exploits a spec edge case where the browser legitimately sends Origin: null. CORS2-003 is not a bypass but a timing vulnerability: pre-flight caching means that tightening your CORS policy doesn't take effect immediately on all clients. CORS2-004 is a category error: JSONP sidesteps CORS entirely via a <script> tag that the browser does not subject to same-origin policy.

SA-SKL-CORS2 in scope: CORS2-001 (subdomain wildcard endsWith bypass), CORS2-002 (null origin via sandboxed iframe), CORS2-003 (maxAge pre-flight cache delays enforcement), CORS2-004 (JSONP endpoint bypasses CORS). Each includes SkillAudit detection rules and exact fixes. For the basic origin: '*' and reflected-origin patterns see SA-SKL-CORS.

CORS2-001 — Subdomain wildcard via endsWith check

When a skill needs to allow multiple subdomains (staging, preview, app) it is tempting to match origins with origin.endsWith('.skillaudit.dev'). This check passes https://app.skillaudit.dev correctly, but it also passes https://evil.skillaudit.dev.attacker.com because that string does end with .skillaudit.dev. The attacker registers a domain with that suffix, hosts a malicious page, and the skill's CORS policy grants it cross-origin read access to authenticated API responses. The fix is an exact Set lookup or a regex anchored at both ends.

// VULNERABLE: endsWith check is bypassable via attacker-controlled suffix domain
const cors = require('cors');

const allowedOrigins = [
  'https://skillaudit.dev',
  'https://app.skillaudit.dev',
  'https://staging.skillaudit.dev',
];

app.use(cors({
  origin: (origin, callback) => {
    // VULNERABLE: endsWith('.skillaudit.dev') passes evil.skillaudit.dev.attacker.com
    if (!origin || allowedOrigins.includes(origin) || origin.endsWith('.skillaudit.dev')) {
      return callback(null, true);
    }
    callback(new Error('CORS: origin not allowed'));
  },
  credentials: true,
}));
// FIXED: exact Set lookup — no substring matching
const ALLOWED_ORIGIN_SET = new Set([
  'https://skillaudit.dev',
  'https://app.skillaudit.dev',
  'https://staging.skillaudit.dev',
]);

app.use(cors({
  origin: (origin, callback) => {
    // No origin = same-origin or non-browser request (curl, server-to-server)
    if (!origin) return callback(null, true);

    if (ALLOWED_ORIGIN_SET.has(origin)) {
      return callback(null, true);
    }

    // Log blocked origin for incident investigation
    console.warn('[CORS] Blocked origin:', origin);
    callback(new Error('CORS: origin not allowed'));
  },
  credentials: true,
}));
HIGH
SA-SKL-CORS2-001 — Skill CORS origin check uses endsWith('.yourdomain.com') or a regex with an unanchored suffix match; an attacker registers a domain ending in .yourdomain.com (e.g., evil.yourdomain.com.attacker.io) and gains full cross-origin read access to authenticated responses; credentials are exposed to the attacker's origin. Fix: exact Set.has(origin) lookup against an explicit allowlist of known origins; never use substring or suffix matching for CORS origin validation. Detection: SkillAudit flags endsWith, includes, and unanchored regex patterns in CORS origin callback functions.

CORS2-002 — Null origin via sandboxed iframe

Browsers send Origin: null (the literal string "null") in several scenarios: requests from sandboxed iframes without allow-same-origin, cross-origin redirects, and file:// URLs. Many CORS validators treat a falsy or missing origin as "allow" (for server-to-server requests) using if (!origin) return allow. But !origin is false when origin is the string "null" — that check doesn't fire. So a validator that explicitly handles origin === 'null' as allowed, or falls through to a broad allow clause for unrecognized values, grants CORS access to any page that loads the skill API in a sandboxed iframe. An attacker hosts a page with <iframe sandbox> containing a script that calls your API — the browser sends Origin: null, your CORS validator allows it, and the authenticated response is returned.

// VULNERABLE: null origin string passes the falsy check and may hit an allow-all fallback
app.use(cors({
  origin: (origin, callback) => {
    if (!origin) {
      // This check: !origin is false when origin === 'null' (the string)
      // So the string 'null' falls through to the else branch below
      return callback(null, true);  // allows server-to-server — OK
    }

    if (ALLOWED_ORIGIN_SET.has(origin)) {
      return callback(null, true);
    }

    // VULNERABLE: some implementations add a catch-all that allows unknown origins
    // or allow 'null' string explicitly "for local development"
    if (origin === 'null') {
      return callback(null, true);  // VULNERABLE — allows sandboxed iframe attacks
    }

    callback(new Error('CORS: origin not allowed'));
  },
  credentials: true,
}));
// FIXED: explicitly block the string 'null'; treat it like any other unknown origin
app.use(cors({
  origin: (origin, callback) => {
    // No origin header = same-origin or server-to-server — allow
    if (origin === undefined || origin === null) {
      return callback(null, true);
    }

    // The string 'null' is a browser-sent value from sandboxed iframes — block it
    // Never allow 'null' string even in development; use localhost origin instead
    if (ALLOWED_ORIGIN_SET.has(origin)) {
      return callback(null, true);
    }

    callback(new Error('CORS: origin not allowed'));
  },
  credentials: true,
}));
HIGH
SA-SKL-CORS2-002 — Skill CORS validator explicitly allows or falls through on origin === 'null' (the string); browsers send this literal value from sandboxed iframes without allow-same-origin; an attacker page loads the skill API in a sandboxed iframe and reads authenticated responses cross-origin. Fix: treat the string 'null' as an unknown, disallowed origin — only use if (!origin) to handle the undefined/null JavaScript value (no header present), never to handle the string 'null'. Detection: SkillAudit flags CORS validators where origin === 'null' or origin == null (loose equality, matches the string) results in an allow response.

CORS2-003 — maxAge pre-flight cache delays enforcement

When a CORS policy sets maxAge: 86400 (24 hours), browsers cache the pre-flight OPTIONS result for that duration. This is a performance optimization: the browser does not re-send the pre-flight request for subsequent same-origin cross-origin requests within the cache window. The security implication is that if you discover a CORS misconfiguration and tighten your policy (remove an origin, shorten credentials scope), already-authenticated browsers continue to operate under the old policy for up to 24 hours. If an incident response requires immediate CORS tightening — for example, a compromised third-party subdomain — the 24-hour cache prevents immediate effect. The fix for new deployments is a short maxAge (600 seconds or less) that balances performance with incident response speed.

// VULNERABLE: maxAge=86400 means CORS policy changes take 24 hours to propagate
app.use(cors({
  origin: ALLOWED_ORIGIN_SET,
  credentials: true,
  methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
  allowedHeaders: ['Content-Type', 'Authorization'],
  maxAge: 86400,  // VULNERABLE: browser caches pre-flight result for 24 hours
  // A compromised subdomain added to allowedOrigins today cannot be removed
  // from active browser caches for 24 hours even after removing it here
}));
// FIXED: short maxAge balances pre-flight overhead with incident response capability
app.use(cors({
  origin: (origin, callback) => {
    if (!origin || ALLOWED_ORIGIN_SET.has(origin)) return callback(null, true);
    callback(new Error('CORS: origin not allowed'));
  },
  credentials: true,
  methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
  allowedHeaders: ['Content-Type', 'Authorization'],
  // 600 seconds = 10 minutes: browsers re-check pre-flight every 10 minutes
  // Trade-off: one extra OPTIONS request per 10 minutes per origin per route
  // Benefit: policy tightening takes effect within 10 minutes for all clients
  maxAge: 600,
}));
MEDIUM
SA-SKL-CORS2-003 — Skill CORS configuration sets maxAge to 3600 or greater (commonly 86400 = 24 hours); browser pre-flight cache persists the allowed-origins list; if the CORS policy must be tightened urgently (e.g., compromised subdomain, leaked credential), the old policy remains effective in existing browser sessions until the TTL expires; incident response is degraded. Fix: set maxAge to 600 seconds (10 minutes) or less; the small performance cost (one extra OPTIONS request per 10 minutes) is acceptable compared to a 24-hour policy-enforcement lag. Detection: SkillAudit flags maxAge values ≥3600 in CORS configuration objects.

CORS2-004 — JSONP endpoint bypasses all CORS restrictions

JSONP (JSON with Padding) is a legacy cross-origin technique that wraps JSON data in a function call: callback({"user": "alice"}). The browser loads this via a <script src="…?callback=myFunc"> tag, which is not subject to CORS restrictions — script tags can load from any origin regardless of CORS headers. Any authenticated JSONP endpoint on your skill's API is cross-origin-readable by any page that can load a script tag. The attacker calls your JSONP endpoint from their page with a cookie-bearing request (cookies are always sent with script tag loads if SameSite is not Strict), receives the authenticated JSON as a function call argument, and reads it. CORS headers are irrelevant — JSONP bypasses the entire CORS mechanism. The only fix is to remove JSONP endpoints entirely and use standard JSON APIs with proper CORS.

// VULNERABLE: JSONP endpoint is cross-origin readable regardless of CORS configuration
// CORS headers are irrelevant for <script> tag loads
app.get('/api/skill/audit_result', authMiddleware, async (req, res) => {
  const { jobId, callback } = req.query;

  const result = await db.auditResults.findById(jobId, req.user.id);

  // VULNERABLE: callback parameter wraps authenticated data in a script call
  // Any page can load: <script src="https://skillaudit.dev/api/skill/audit_result?jobId=X&callback=steal">
  // The browser sends the session cookie, the response contains authenticated data,
  // and the script tag delivers it to the attacker's steal() function
  if (callback) {
    // Validate callback is identifier — but this doesn't prevent the attack
    if (!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(callback)) {
      return res.status(400).json({ error: 'Invalid callback' });
    }
    res.type('application/javascript');
    return res.send(`${callback}(${JSON.stringify(result)})`);
  }

  res.json(result);
});
// FIXED: remove JSONP entirely; use standard JSON API with CORS
// If JSONP was added for legacy browser support, that use case ended in 2015
app.get('/api/skill/audit_result', authMiddleware, async (req, res) => {
  const { jobId } = req.query;

  // No callback parameter — only JSON responses
  // CORS headers on this route control browser cross-origin access
  const result = await db.auditResults.findById(jobId, req.user.id);

  // Standard JSON response — CORS handles cross-origin access control
  res.json(result);
});

// If a JSONP endpoint must be preserved for a specific legacy integration,
// scope it to non-authenticated, non-sensitive data ONLY and add:
// - Vary: Origin
// - Cache-Control: private, no-store
// - Strip all authentication — treat JSONP routes as fully public
HIGH
SA-SKL-CORS2-004 — Skill exposes a JSONP endpoint (URL accepts a callback query parameter and returns callback(data) as application/javascript); browser <script> tags load cross-origin without CORS restrictions, session cookies are sent, and authenticated data is delivered to attacker-controlled JavaScript regardless of CORS headers; CORS headers provide no protection for JSONP responses. Fix: remove all JSONP endpoints; replace with standard JSON APIs gated by CORS origin allowlist; if legacy JSONP must remain, scope it exclusively to non-authenticated public data with Cache-Control: private, no-store. Detection: SkillAudit flags routes that accept a callback query parameter and return res.send(callback + '(' + JSON.stringify(data) + ')') patterns, particularly when the route also includes authentication middleware.

SkillAudit detection summary — SA-SKL-CORS2

Pattern IDSeverityWhat SkillAudit flagsFix
CORS2-001HIGHendsWith, includes, or unanchored regex in CORS origin callbackExact Set.has(origin) allowlist
CORS2-002HIGHCORS validator allows or falls through on origin === 'null' (string)Block string 'null' explicitly
CORS2-003MEDIUMmaxAge ≥3600 in CORS configSet maxAge: 600 (10 min)
CORS2-004HIGHRoute accepts callback param and returns JS function call with authenticated dataRemove JSONP; use JSON + CORS

Related patterns: For basic CORS origin:* and reflected-origin issues, see SA-SKL-CORS. For cookie SameSite interactions with CORS, see SA-SKL-SSECOOKIE. For CSRF via cross-origin form submissions enabled by broad CORS, see SA-SKL-CSRF.