← Blog

Claude skill CORS credential exposure via subdomain wildcard, origin reflection, wildcard with credentials and CRLF header injection in MCP skills — SA-SKL-CORS13

CORS misconfigurations in MCP skill endpoints enable cross-origin credential theft when the Access-Control-Allow-Origin header is set too permissively. SA-SKL-CORS13 covers four patterns: an origin allowlist that uses endsWith('.skillaudit.dev') to match subdomains, which is bypassed by registering a domain ending in that suffix like evil-skillaudit.dev or xsskillaudit.dev; a CORS configuration that sets both Access-Control-Allow-Origin: * and Access-Control-Allow-Credentials: true — which modern browsers block but older CORS middleware versions accept, creating a discrepancy between what should be safe and what is actually deployed; a server that validates the Origin header only during CORS preflight but not for simple requests (those with safe methods and simple content types), allowing credentialed simple requests from any origin; and an Access-Control-Allow-Origin header whose value is sourced from a database-stored tenant configuration, where an attacker who can modify their tenant config can inject a CRLF sequence to split the HTTP response and inject additional headers.

By SkillAudit  |  8 Nov 2026

CORS credential exposure — why Origin validation must be strict

The browser's same-origin policy prevents JavaScript from reading responses to cross-origin requests. CORS is the mechanism by which a server explicitly grants permission for specific cross-origin origins to read responses, and when Access-Control-Allow-Credentials: true is set, those granted origins can also receive responses to credentialed requests (requests that carry session cookies, authorization headers, or client certificates). A CORS misconfiguration that grants credentials access to an unintended origin is therefore equivalent to a session hijacking vulnerability — the attacker's JavaScript can issue authenticated API calls on the victim's behalf and read the responses. The severity is highest when the endpoint returns sensitive data (tokens, PII, audit reports) and when the allowed origin is under the attacker's control.

SA-SKL-CORS13 findings at a glance
CRITICALCORS13-001 — origin.endsWith('.skillaudit.dev') subdomain check; attacker registers evil-skillaudit.dev or xsskillaudit.dev; full credential access granted
HIGHCORS13-002 — ACAO: * combined with ACAC: true; modern browsers block but old CORS middleware versions accept; credentialed wildcard grants
HIGHCORS13-003 — Origin validated on preflight only; simple requests (GET + Authorization header) bypass validation; credentials sent from any origin
HIGHCORS13-004 — ACAO header set from database-stored tenant config; attacker injects \r\n CRLF to split HTTP response; additional headers injected

CORS13-001 — endsWith subdomain check bypassed by crafted domain registration

The endsWith approach to origin matching is intended to allow all subdomains of a trusted domain. origin.endsWith('.skillaudit.dev') passes for https://app.skillaudit.dev and https://docs.skillaudit.dev. It also passes for https://evil-skillaudit.dev (because the string ends with skillaudit.dev) and for https://xsskillaudit.dev. The correct check for subdomain matching requires confirming that the origin's hostname is exactly the trusted domain or is a strict subdomain of it — the character before the domain must be a dot or the hostname must equal the domain exactly. The safest approach is an explicit allowlist of exactly the origins that should be permitted, with no wildcard matching at all.

// VULNERABLE — endsWith('.skillaudit.dev') bypassed by evil-skillaudit.dev
import cors from 'cors';

app.use(cors({
  origin: (origin, callback) => {
    // VULNERABLE: endsWith passes for 'https://evil-skillaudit.dev'
    // and 'https://xsskillaudit.dev' — attacker registers these domains
    if (!origin || origin.endsWith('.skillaudit.dev') || origin === 'https://skillaudit.dev') {
      callback(null, true);
    } else {
      callback(new Error('Not allowed by CORS'));
    }
  },
  credentials: true,
}));
// FIXED — explicit allowlist with exact hostname matching; no suffix matching
import cors from 'cors';

const CORS_ALLOWED_ORIGINS = new Set([
  'https://skillaudit.dev',
  'https://app.skillaudit.dev',
  'https://docs.skillaudit.dev',
  // Add additional origins explicitly — never use substring or suffix matching
]);

function isAllowedOrigin(origin) {
  if (!origin) return false;
  try {
    const url = new URL(origin);
    // FIXED: exact Set lookup — no suffix matching possible
    return CORS_ALLOWED_ORIGINS.has(origin) &&
           url.protocol === 'https:'; // require HTTPS; never allow http:
  } catch {
    return false;
  }
}

app.use(cors({
  origin: (origin, callback) => {
    if (isAllowedOrigin(origin)) {
      callback(null, origin); // reflect exact allowed origin, not '*'
    } else {
      callback(new Error('Not allowed by CORS'));
    }
  },
  credentials: true,
}));

CORS13-002 — Wildcard ACAO with credentials=true in legacy CORS middleware

The Fetch specification prohibits browsers from sending credentialed requests (cookies, authorization headers) to a server that responds with Access-Control-Allow-Origin: *. Modern browsers enforce this strictly. However, some older versions of CORS middleware (pre-2.8.5 of the cors npm package, and some Express middleware bundles) have bugs that accept the combination and set both headers on the response. When an MCP skill has not pinned its CORS middleware version, a dependency update may introduce or remove this behavior silently. Additionally, some proxy layers (Nginx, Caddy) may add ACAO: * to proxied responses regardless of what the application sets, creating the combination. The fix is to never configure the CORS middleware with origin: '*' combined with credentials: true — if credentials are required, the origin must be explicit. If the endpoint is intended to be public (no credentials), use origin: '*' without credentials: true.

// VULNERABLE — wildcard ACAO with credentials=true; accepted by some old middleware versions
import cors from 'cors';

// VULNERABLE: this combination is prohibited by the Fetch spec but
// some old cors package versions accept it without warning
app.use(cors({
  origin: '*',          // VULNERABLE: wildcard
  credentials: true,    // VULNERABLE: combined with wildcard — grants credential access to any origin
  methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
}));
// FIXED — credentials endpoint: explicit origin list; public endpoint: wildcard no credentials
import cors from 'cors';

// For credential-bearing endpoints: explicit origin, credentials=true
const credentialedCors = cors({
  origin: (origin, callback) => {
    if (isAllowedOrigin(origin)) {
      callback(null, origin);
    } else {
      callback(new Error('Not allowed by CORS'));
    }
  },
  credentials: true,
  methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
});

// For public read endpoints: wildcard, no credentials
const publicCors = cors({
  origin: '*',          // FIXED: wildcard only on endpoints that never use credentials
  credentials: false,   // FIXED: never combine wildcard with credentials
  methods: ['GET', 'OPTIONS'],
});

// Apply appropriate CORS policy per route
app.use('/api', credentialedCors);        // authenticated API — strict origin
app.use('/public', publicCors);           // public badge endpoint — wildcard OK

CORS13-003 — Origin not validated on simple requests (only on preflight)

CORS preflight — an HTTP OPTIONS request sent before the actual request — is triggered for non-simple requests: those with non-simple content types, non-simple headers (like Authorization or Content-Type: application/json), or non-simple methods. Simple requests (GET, HEAD, POST with text/plain/application/x-www-form-urlencoded/multipart/form-data) do not trigger a preflight. Some CORS middleware implementations validate the Origin header only in the preflight handler, not in the main request handler. When a simple GET request with an Authorization header comes from an unauthorized origin, the middleware may pass the Origin check on the OPTIONS preflight (which the browser did not send, since the GET+Authorization combination is a non-simple request that does require a preflight) but fail to re-validate on the actual GET. The fix is to validate the Origin header on every request, not only in the OPTIONS handler.

// VULNERABLE — Origin validated in OPTIONS handler only; simple requests bypass check
app.options('/api/*', (req, res) => {
  const origin = req.headers.origin;
  if (isAllowedOrigin(origin)) {
    res.setHeader('Access-Control-Allow-Origin', origin);
    res.setHeader('Access-Control-Allow-Credentials', 'true');
    res.setHeader('Access-Control-Allow-Methods', 'GET,POST,DELETE');
    res.setHeader('Access-Control-Allow-Headers', 'Content-Type,Authorization');
    res.sendStatus(204);
  } else {
    res.sendStatus(403);
  }
});

// VULNERABLE: main handler does not re-validate Origin
// A GET request from an unauthorized origin with an Authorization header
// does trigger preflight (Authorization is non-simple), but the actual GET
// does not go through the OPTIONS handler; if the main handler doesn't check Origin
// and sets ACAO based on the Origin header, the credential request leaks data
app.get('/api/audits', authenticate, async (req, res) => {
  const origin = req.headers.origin;
  // VULNERABLE: sets ACAO without validating it's in the allowlist
  if (origin) res.setHeader('Access-Control-Allow-Origin', origin);
  res.setHeader('Access-Control-Allow-Credentials', 'true');
  // ... return sensitive data
});
// FIXED — Origin validated on every request via middleware, not just OPTIONS
import cors from 'cors';

const corsOptions = {
  origin: (origin, callback) => {
    // FIXED: this callback is called for ALL requests (preflight AND actual)
    // when using the cors() middleware — not just OPTIONS
    if (!origin || isAllowedOrigin(origin)) {
      callback(null, origin ?? false);
    } else {
      callback(new Error('Not allowed by CORS'));
    }
  },
  credentials: true,
  methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
  allowedHeaders: ['Content-Type', 'Authorization', 'X-CSRF-Token'],
};

// FIXED: apply cors middleware to all routes — it validates Origin on every request
// and only sets ACAO for requests from allowed origins
app.use('/api', cors(corsOptions));

app.get('/api/audits', authenticate, async (req, res) => {
  // cors() middleware already validated Origin and set ACAO before reaching here
  // No need to manually set ACAO — middleware handles it
  const audits = await getAuditsForUser(req.user.id);
  res.json(audits);
});

CORS13-004 — ACAO header set from database-stored tenant config allows CRLF injection

Multi-tenant MCP skill platforms sometimes allow tenants to configure their own allowed CORS origins via a settings dashboard. The origin value is stored in the database and read at request time to set the Access-Control-Allow-Origin header. If the value is used without sanitization, an attacker who can modify their tenant configuration can inject a CRLF sequence (\r\n) into the allowed origin value. HTTP headers are terminated by CRLF; injecting a CRLF causes the HTTP response parser to interpret everything after the injection point as a new header or as the response body. This allows the attacker to inject arbitrary response headers (Content-Security-Policy, Set-Cookie, custom headers) or to manipulate the response body. The fix is to validate the CORS origin value against a strict URL regular expression that excludes control characters before saving it to the database, and to validate it again before using it in a response header.

// VULNERABLE — ACAO header set from DB config without sanitization; CRLF injection
app.use(async (req, res, next) => {
  const origin = req.headers.origin;
  if (!origin) return next();

  const tenantId = req.user?.tenantId;
  if (!tenantId) return next();

  const tenantConfig = await db.tenantConfigs.findOne({ tenantId });

  // VULNERABLE: tenantConfig.allowedOrigin from DB set directly in header
  // Attacker stores: "https://evil.com\r\nSet-Cookie: session=hijacked; Path=/"
  // Result: response contains two headers — ACAO and a forged Set-Cookie
  if (tenantConfig?.allowedOrigin === origin) {
    res.setHeader('Access-Control-Allow-Origin', tenantConfig.allowedOrigin);
    res.setHeader('Access-Control-Allow-Credentials', 'true');
  }
  next();
});
// FIXED — strict URL validation before saving to DB and before setting header
// Validation at save time (settings endpoint):
const SAFE_ORIGIN_RE = /^https:\/\/[a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?)*(?::\d{2,5})?$/;

function isSafeOrigin(value) {
  if (typeof value !== 'string') return false;
  if (value.length > 253) return false;
  // No CRLF, whitespace, or non-ASCII characters
  if (/[\r\n\t\s\x00-\x1f\x7f-\xff]/.test(value)) return false;
  // Must match strict HTTPS URL pattern — no path, no query string
  return SAFE_ORIGIN_RE.test(value);
}

app.put('/api/settings/cors', authenticate, async (req, res) => {
  const { allowedOrigin } = req.body;
  // FIXED: validate before saving to DB
  if (!isSafeOrigin(allowedOrigin)) {
    return res.status(400).json({ error: 'Invalid CORS origin — must be a valid HTTPS URL' });
  }
  await db.tenantConfigs.update({ tenantId: req.user.tenantId }, { allowedOrigin });
  res.json({ ok: true });
});

// At header-set time:
app.use(async (req, res, next) => {
  const origin = req.headers.origin;
  if (!origin) return next();

  const tenantConfig = await db.tenantConfigs.findOne({ tenantId: req.user?.tenantId });
  const storedOrigin = tenantConfig?.allowedOrigin;

  // FIXED: re-validate at use time — defense in depth against stale data or migration
  if (storedOrigin && isSafeOrigin(storedOrigin) && storedOrigin === origin) {
    res.setHeader('Access-Control-Allow-Origin', storedOrigin);
    res.setHeader('Access-Control-Allow-Credentials', 'true');
  }
  next();
});

Related patterns: For CSRF attacks that exploit permissive CORS policies in combination with SameSite cookie weaknesses, see SA-SKL-CSRF4. For the earlier CORS patterns covering origin reflection and null origin bypass, see SA-SKL-CORS12. For XSS in MCP skill output that enables cross-origin JavaScript execution needed to exploit CORS misconfigs, see SA-SKL-ESCAPE6.

FindingSeverityVulnerable patternFix
CORS13-001Criticalorigin.endsWith('.skillaudit.dev') passes for evil-skillaudit.dev and xsskillaudit.dev; full credential access granted to attacker-controlled domainExplicit Set allowlist with exact origin strings; CORS_ALLOWED_ORIGINS.has(origin); no suffix or substring matching
CORS13-002HighACAO: * combined with ACAC: true; Fetch spec violation; old CORS middleware accepts combination; credentialed wildcard grantsNever combine origin:'*' with credentials:true; public endpoints use wildcard without credentials; authenticated endpoints use explicit origin list
CORS13-003HighOrigin validated in OPTIONS handler only; main request handler reflects Origin without allowlist check; credentialed simple requests from any origin allowedUse cors() middleware on all routes — it validates Origin for every request method; never manually set ACAO without validation
CORS13-004HighACAO value from DB tenant config set in header without sanitization; CRLF injection splits response; arbitrary headers injectedStrict SAFE_ORIGIN_RE regex rejects CRLF and non-ASCII; validate at save time AND at use time; defense in depth