← Blog

Claude skill CORS null origin preflight bypass and credential caching — SA-SKL-CORS8

CORS is designed to protect credentialed cross-origin requests — but each corner case in the specification opens a distinct bypass path. The null origin value is a common misconfiguration that explicitly whitelists sandboxed iframes and Blob URLs. Missing Vary: Origin header causes CDN caches to serve stale ACAO headers across different callers. HTTP origins in the allowlist expose the CORS exchange to plaintext interception. And Access-Control-Allow-Origin: * on authenticated API endpoints creates a confused-deputy vulnerability developers mistake for safe. SA-SKL-CORS8 covers all four.

By SkillAudit  |  7 Nov 2026

CORS8-001 — Access-Control-Allow-Origin: null allows sandboxed iframe attacks

The null origin is a special value in the Fetch specification sent by browsers in several contexts: documents loaded from file://, sandboxed iframes without the allow-same-origin attribute, Blob URL navigations, and certain data: URI contexts. When a server responds with Access-Control-Allow-Origin: null combined with Access-Control-Allow-Credentials: true, the browser permits the cross-origin request from any of these null-origin contexts. An attacker who controls a web page can create a sandboxed iframe with an inline data URL (<iframe sandbox="allow-scripts" src="data:text/html,...">) that sends a credentialed fetch to the skill's API. Because the iframe is sandboxed without allow-same-origin, the browser sends Origin: null — which the server explicitly allows. The attacker's iframe can read the full credentialed response, including the authenticated user's audit reports and account data, as long as the victim visits the attacker's page while logged into the skill.

// VULNERABLE — CORS8-001
// cors-config.js — explicitly allows null origin with credentials
import cors from 'cors';

app.use('/api/', cors({
  origin: ['https://skillaudit.dev', 'null'], // DANGEROUS: 'null' string whitelists sandboxed iframes
  credentials: true,
}));

// Or sometimes written as a function:
app.use('/api/', cors({
  origin: (origin, callback) => {
    if (!origin || origin === 'null') callback(null, true); // DANGEROUS: null = sandboxed iframe
    else if (allowedOrigins.includes(origin)) callback(null, true);
    else callback(new Error('CORS not allowed'));
  },
  credentials: true,
}));

// Attacker page:
// <iframe sandbox="allow-scripts" src="data:text/html,
//   <script>
//     fetch('https://api.skillaudit.dev/api/audits', {credentials:'include'})
//       .then(r => r.json()).then(data => parent.postMessage(data, '*'))
//   </script>
// "></iframe>
// FIXED — CORS8-001
// Never include 'null' in the allowed origins list; always check with explicit string match
import cors from 'cors';

const allowedOrigins = new Set([
  'https://skillaudit.dev',
  'https://www.skillaudit.dev',
  // Note: 'null' is NOT here and NEVER should be
]);

app.use('/api/', cors({
  origin: (origin, callback) => {
    // Undefined origin = same-origin request (server-to-server or curl) — allow
    if (origin === undefined) return callback(null, true);
    // Explicitly reject null origin — never allow sandboxed iframe access
    if (!origin || origin === 'null') return callback(new Error('CORS: null origin not allowed'));
    if (allowedOrigins.has(origin)) return callback(null, true);
    callback(new Error(`CORS: origin ${origin} not in allowlist`));
  },
  credentials: true,
}));
HIGH
SA-SKL-CORS8-001 — Setting Access-Control-Allow-Origin: null combined with Access-Control-Allow-Credentials: true explicitly whitelists sandboxed iframes and Blob URL contexts — an attacker controls a sandboxed <iframe> that sends credentialed fetch requests to the API and reads back the authenticated user's data; fix by explicitly rejecting the null origin in the CORS origin function and never including the string 'null' in an allowed origins list. Detection: SkillAudit flags CORS configurations where the allowed origin list includes the string 'null', or origin-callback functions that return true when origin === 'null'.

CORS8-002 — Missing Vary: Origin causes CDN to cache wrong ACAO header

When a server responds to a CORS request with a dynamic Access-Control-Allow-Origin header (reflecting the requesting origin from a whitelist rather than using *), the response must also include Vary: Origin to tell caches that the response content varies based on the Origin request header. Without Vary: Origin, a CDN (Cloudflare, AWS CloudFront, Fastly) treats the response as the same for all origins. The first origin to request a resource gets its own origin reflected in the ACAO header, and that response is cached. All subsequent requests from different origins receive the cached response with the first origin's ACAO value. If origin A's credentialed request is cached as allowed and origin B (which should be blocked) hits the CDN edge, it receives the cached ACAO header for origin A — which does not match origin B, and the browser blocks the request. Conversely, if origin A is an internal admin tool and origin B is an external attacker — and the CDN cached origin A's permissive ACAO response before the first external request — the attacker sees Access-Control-Allow-Origin: https://admin.skillaudit.dev, which the browser rejects because it does not match the attacker's origin. The concrete harm is subtle but real: either CORS breaks for legitimate users (broken cross-origin requests) or the CDN cache is poisoned to serve mismatched headers that cause intermittent CORS failures across all cached edge nodes.

// VULNERABLE — CORS8-002
// No Vary: Origin header — CDN caches the first ACAO response for all origins
app.use('/api/', (req, res, next) => {
  const origin = req.headers.origin;
  if (allowedOrigins.has(origin)) {
    res.setHeader('Access-Control-Allow-Origin', origin); // Dynamic — varies by origin
    res.setHeader('Access-Control-Allow-Credentials', 'true');
    // BUG: missing Vary: Origin — CDN doesn't know to vary the cache key on Origin header
  }
  next();
});
// FIXED — CORS8-002: always set Vary: Origin when reflecting origin dynamically
app.use('/api/', (req, res, next) => {
  const origin = req.headers.origin;
  // Always set Vary: Origin — tells CDN the response depends on the Origin header
  // This applies even when the origin is NOT in the allowlist (the absence of ACAO also varies)
  res.setHeader('Vary', 'Origin');

  if (origin && allowedOrigins.has(origin)) {
    res.setHeader('Access-Control-Allow-Origin', origin);
    res.setHeader('Access-Control-Allow-Credentials', 'true');
  }
  next();
});

// When using the cors npm package, it sets Vary: Origin automatically for dynamic origins.
// If writing manual CORS middleware, always add Vary: Origin before responding.
MEDIUM
SA-SKL-CORS8-002 — Dynamic CORS responses that reflect the requesting origin without also setting Vary: Origin cause CDN edge nodes to cache the ACAO header for the first origin and serve it to all subsequent origins — breaking legitimate cross-origin requests for users whose origin differs from the cached one, and creating difficult-to-diagnose intermittent CORS failures at the edge; fix by always including Vary: Origin in responses that set a dynamic Access-Control-Allow-Origin header. Detection: SkillAudit flags route handlers that call res.setHeader('Access-Control-Allow-Origin', origin) (dynamic reflection) without a corresponding res.setHeader('Vary', 'Origin') in the same middleware chain.

CORS8-003 — CORS allowlist includes HTTP origins enabling downgrade MITM

CORS origin allowlists sometimes include both the HTTPS and HTTP versions of trusted origins — either because a developer is testing locally over HTTP or because an older subdomain still serves over HTTP. Including http://trusted.example.com in a CORS allowlist means that any request claiming that origin will receive the ACAO header permitting cross-origin access. An attacker on the same network as the victim (coffee shop WiFi, corporate proxy, ISP-level injection) can intercept a request to http://trusted.example.com, inject a malicious page, and have that page issue credentialed cross-origin requests to the skill's API — which the server allows because the HTTP origin is in the allowlist. HTTPS origins in the allowlist are not exploitable this way: the browser enforces TLS and the attacker cannot intercept the HTTPS connection to inject their malicious page. The fix is simply to allow only https:// origins in the CORS allowlist — never http:// for production domains.

// VULNERABLE — CORS8-003
// allowlist includes http:// origins — MITM on the HTTP origin enables CORS bypass
const allowedOrigins = new Set([
  'https://skillaudit.dev',
  'http://skillaudit.dev',          // DANGEROUS: HTTP origin — interceptable
  'http://localhost:3000',          // OK for local dev, but must NEVER reach production
  'http://staging.skillaudit.dev',  // DANGEROUS: staging still on HTTP
]);

// Attacker on the same network:
// 1. Intercepts victim's HTTP request to http://skillaudit.dev
// 2. Responds with malicious HTML:
//    <script>
//      fetch('https://api.skillaudit.dev/api/my-audits', {credentials:'include'})
//        .then(r => r.json()).then(data => exfiltrate(data))
//    </script>
// 3. The API allows Origin: http://skillaudit.dev — attacker reads response
// FIXED — CORS8-003: only https:// origins in production allowlist
const allowedOrigins = new Set([
  'https://skillaudit.dev',
  'https://www.skillaudit.dev',
  'https://staging.skillaudit.dev',
  // http://localhost:3000 is added ONLY in development (NODE_ENV !== 'production')
  ...(process.env.NODE_ENV !== 'production' ? ['http://localhost:3000', 'http://localhost:3001'] : []),
]);

// Also add an origin validator that rejects all http:// origins in production:
function validateCorsOrigin(origin) {
  if (!origin) return true; // same-origin / server-to-server
  if (origin.startsWith('http://') && process.env.NODE_ENV === 'production') {
    return false; // reject all plaintext origins in production
  }
  return allowedOrigins.has(origin);
}
HIGH
SA-SKL-CORS8-003 — CORS allowlists that include http:// origins for production domains allow an attacker with network-level access (shared WiFi, ISP injection) to serve a malicious page from the HTTP origin that sends credentialed cross-origin requests to the API, bypassing CORS protection; fix by allowing only https:// origins in the CORS allowlist in production, adding http://localhost:* only via a NODE_ENV !== 'production' guard. Detection: SkillAudit flags CORS allowlists containing strings that begin with http:// (not localhost) where the application is configured for a production deployment.

CORS8-004 — Access-Control-Allow-Origin: * on user-specific endpoints

Using Access-Control-Allow-Origin: * (wildcard) is correct for public, unauthenticated API endpoints that return the same data for all callers — such as a public package metadata endpoint or an open badge image. The mistake is applying the wildcard to endpoints that return user-specific data, even when those endpoints require an Authorization: Bearer header. The browser does not block the request — credentials in the Authorization header are not "cookies and TLS client certificates" so the browser sends them even with a wildcard ACAO. The developer's mental model ("* means anyone can call it, so it's not secret") is wrong for token-authenticated endpoints: an attacker who obtains or guesses a bearer token can call the endpoint from any origin and read the response. More subtly, a misconfigured API gateway that strips authentication headers for pre-flight responses may set ACAO: * on a preflight response for a route that should only allow specific origins for authenticated calls — causing the browser to treat the subsequent credentialed request as cross-origin allowed. The fix is to use a specific origin allowlist for all endpoints that return user-specific data, regardless of authentication method.

// VULNERABLE — CORS8-004
// Wildcard ACAO on endpoint that returns user-specific audit history
app.use('/api/', cors({ origin: '*' })); // Sets ACAO: * for all /api/ routes

app.get('/api/my-audits', requireAuth, async (req, res) => {
  // requireAuth validates the Bearer token — req.user is set
  // But the ACAO: * header above means any origin can read this response
  const audits = await db.query(
    'SELECT * FROM audits WHERE user_id = $1',
    [req.user.id]
  );
  res.json(audits.rows); // User's private audit history is cross-origin readable by any origin
});

// Developer's reasoning: "It requires auth so it's safe" — wrong.
// ACAO: * + Authorization: Bearer means any origin can send the token and read the response.
// FIXED — CORS8-004: use specific origin allowlist for all user-specific endpoints
import cors from 'cors';

const publicCors = cors({ origin: '*' }); // OK for truly public, unauthenticated endpoints
const authenticatedCors = cors({          // For user-specific endpoints
  origin: allowedOrigins,                 // Explicit allowlist — not wildcard
  credentials: true,
});

// Apply public CORS only to genuinely public endpoints
app.get('/api/badges/:repoId', publicCors, (req, res) => {
  // Public badge data — same for all callers — ACAO: * is correct here
  res.json({ grade: 'A', repoId: req.params.repoId });
});

// Apply specific-origin CORS to user-specific endpoints
app.get('/api/my-audits', authenticatedCors, requireAuth, async (req, res) => {
  const audits = await db.query('SELECT * FROM audits WHERE user_id = $1', [req.user.id]);
  res.json(audits.rows);
});
MEDIUM
SA-SKL-CORS8-004 — Access-Control-Allow-Origin: * applied to API endpoints that return user-specific data makes that data readable by any origin even when the endpoint requires bearer token authentication — an attacker who controls the token or exploits a token-forwarding XSS in another context can read the victim's private data from any origin; fix by applying a specific origin allowlist (not *) to all endpoints that return user-specific data, reserving the wildcard only for genuinely public, unauthenticated responses. Detection: SkillAudit flags route handlers that use both cors({ origin: '*' }) and an authentication middleware (requireAuth, verifyJwt) in the same middleware chain.

Detection summary

ID Severity Pattern Fix
CORS8-001 HIGH ACAO: null + credentials — sandboxed iframe cross-origin access Explicitly reject origin === 'null' in the origin callback
CORS8-002 MEDIUM Dynamic ACAO without Vary: Origin — CDN caches wrong header for all origins Always set Vary: Origin alongside dynamic ACAO responses
CORS8-003 HIGH HTTP origin in allowlist — MITM injects page at HTTP origin, reaches credentialed API Allow only https:// origins in production; guard localhost on dev flag
CORS8-004 MEDIUM ACAO: * on authenticated user-data endpoints — any origin reads private data Use specific origin allowlist (not *) for all user-specific endpoints

Related patterns: SA-SKL-CORS7 covers CORS preflight misconfiguration and reflected origin regex bypass — the same middleware settings that cause CORS8-002 and CORS8-003. SA-SKL-CORS6 covers CORS on WebSocket upgrade requests where Origin validation is handled differently from HTTP. SA-SKL-SESSION2 covers session and JWT security — the credential tokens that CORS8-003 and CORS8-004 expose when misconfigured.