← Blog

Claude skill CORS preflight caching misconfigurations — SA-SKL-CORS6

CORS preflight responses are cached by browsers according to the Access-Control-Max-Age header, which creates a window during which a tightened CORS policy is not enforced. SA-SKL-CORS6 covers four preflight caching vulnerabilities: a stale preflight cache surviving a policy tightening, a credentialed request with wildcard origin accepted by legacy proxies, an Access-Control-Allow-Headers: * wildcard passing custom auth headers cross-origin, and CDN caches sharing preflight responses across origins via an unsplit cache key.

By SkillAudit  |  6 Nov 2026

Why CORS preflight caching creates persistent vulnerabilities after policy tightening

When a browser sends a cross-origin request with a non-simple method or custom headers, it first sends an OPTIONS preflight request. If the server returns a permissive Access-Control-Allow-Origin response with a long Access-Control-Max-Age value, the browser caches that preflight response and skips the OPTIONS request for subsequent same-origin same-URL requests for the cache duration — up to 86400 seconds (24 hours) on Chrome, up to 7200 seconds (2 hours) by spec maximum. If you discover a CORS misconfiguration and tighten the policy at the server, browsers that already have the permissive preflight cached will continue to honor the old permission for the duration of the max-age window. For skills that have been allowing cross-origin credentialed access from an overly broad origin set, this creates a 24-hour window during which the old permitted origins can still make authenticated cross-origin requests even after the server configuration change.

MCP skill APIs must set low max-age values on preflight responses for sensitive endpoints, and must include Vary: Origin to prevent shared caches (CDN and reverse proxies) from serving a preflight response cached for one origin to a request from a different origin.

SA-SKL-CORS6 in scope: CORS6-001 (86400s max-age preflight poisoning after policy tightening), CORS6-002 (credentialed request with Access-Control-Allow-Origin: * accepted by legacy proxies), CORS6-003 (Access-Control-Allow-Headers: * with credentials passes custom auth headers), CORS6-004 (CDN preflight cache shared across origins via missing Vary: Origin). Each pattern includes SkillAudit detection rules and correct fixes.

CORS6-001 — Long max-age preflight cache survives CORS policy tightening

An MCP skill API sets Access-Control-Max-Age: 86400 on preflight responses while development is ongoing, allowing a broad origin list including localhost:* patterns and staging domains. When the team discovers that the production policy is too permissive and tightens it to only allow https://app.skillaudit.dev, browsers that have already cached the permissive preflight response will continue to allow cross-origin credentialed requests from the old origins for up to 24 hours. The fix is to set a low max-age (300 seconds or less) for all endpoints that check the Origin header, and to respond with Vary: Origin so that cached preflight responses are keyed per origin rather than per URL. When you need to invalidate existing caches immediately after a policy change, the only reliable mechanism is to change the URL path of the affected endpoints.

// VULNERABLE — 86400s preflight cache survives a CORS policy tightening for 24 hours
app.options('/api/audits/*', (req, res) => {
  const origin = req.headers.origin;
  // Old permissive list includes staging, localhost, and partner domains
  const allowedOrigins = [
    'https://app.skillaudit.dev',
    'https://staging.skillaudit.dev',
    'http://localhost:3000',
    'http://localhost:5173',
    'https://partner.example.com',
  ];

  if (origin && allowedOrigins.includes(origin)) {
    res.setHeader('Access-Control-Allow-Origin', origin);
    res.setHeader('Access-Control-Allow-Credentials', 'true');
    res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE');
    res.setHeader('Access-Control-Allow-Headers', 'Content-Type,Authorization,X-Audit-Token');
    // 24-hour max-age: browsers cache this response for 86400 seconds
    // Removing localhost from allowedOrigins won't take effect until this cache expires
    res.setHeader('Access-Control-Max-Age', '86400');
  }
  res.sendStatus(204);
});
// FIXED — short max-age limits the stale-preflight-cache window to 5 minutes
app.options('/api/audits/*', (req, res) => {
  const origin = req.headers.origin;
  const PRODUCTION_ORIGINS = new Set(['https://app.skillaudit.dev']);

  // Always set Vary: Origin so CDNs and proxies key the cache per origin
  res.setHeader('Vary', 'Origin');

  if (origin && PRODUCTION_ORIGINS.has(origin)) {
    res.setHeader('Access-Control-Allow-Origin', origin);
    res.setHeader('Access-Control-Allow-Credentials', 'true');
    res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE');
    res.setHeader('Access-Control-Allow-Headers', 'Content-Type,Authorization,X-Audit-Token');
    // 300s max-age: stale cache window after a policy tightening is at most 5 minutes
    res.setHeader('Access-Control-Max-Age', '300');
  }
  // Origins not in the allowlist receive no CORS headers — browser blocks the request
  res.sendStatus(204);
});
HIGH
SA-SKL-CORS6-001 — Skills that set Access-Control-Max-Age greater than 300 seconds on preflight responses for credentialed endpoints create a window of up to 24 hours during which a tightened CORS policy is not enforced by browsers that already cached the permissive response; fix by capping max-age at 300 for all CORS-authenticated endpoints and including Vary: Origin to prevent shared-cache poisoning. Detection: SkillAudit flags CORS middleware that sets Access-Control-Max-Age above 300 on routes that also set Access-Control-Allow-Credentials: true.

CORS6-002 — Credentialed request with Access-Control-Allow-Origin: * accepted by legacy proxies

The Fetch specification prohibits the combination of Access-Control-Allow-Origin: * and Access-Control-Allow-Credentials: true — browsers will refuse to expose the response to JavaScript if both headers are present simultaneously on a credentialed request. However, some older reverse proxies, CDNs, and edge runtimes that implement their own CORS filtering (rather than relying on browser enforcement) accept this combination because they predate the spec tightening. An MCP skill running behind one of these proxies may have a production deployment that behaves differently from local development: in production, the proxy's CORS handler permits the credentialed wildcard request and returns the response to the calling script, while in local testing the browser correctly blocks it. The fix is to never combine wildcard origin with credentials — always enumerate the specific origins or implement origin reflection with an allowlist.

// VULNERABLE — wildcard + credentials is spec-violating; legacy proxies may accept it
app.use((req, res, next) => {
  // Developer intended "allow all origins" for development convenience
  // then forgot to remove it before deploying behind a permissive CDN
  res.setHeader('Access-Control-Allow-Origin', '*');
  res.setHeader('Access-Control-Allow-Credentials', 'true'); // spec violation — browser blocks
  res.setHeader('Access-Control-Allow-Methods', 'GET,POST');
  res.setHeader('Access-Control-Allow-Headers', 'Content-Type,Authorization');
  if (req.method === 'OPTIONS') return res.sendStatus(204);
  next();
});
// FIXED — always use explicit origin allowlist when credentials are required
const ALLOWED_ORIGINS = new Set([
  'https://app.skillaudit.dev',
  'https://skillaudit.dev',
]);

app.use((req, res, next) => {
  const origin = req.headers.origin;
  res.setHeader('Vary', 'Origin'); // Essential for proxy/CDN cache correctness

  if (origin && ALLOWED_ORIGINS.has(origin)) {
    // Reflect the specific allowlisted origin — never use wildcard with credentials
    res.setHeader('Access-Control-Allow-Origin', origin);
    res.setHeader('Access-Control-Allow-Credentials', 'true');
    res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE');
    res.setHeader('Access-Control-Allow-Headers', 'Content-Type,Authorization,X-Audit-Token');
    res.setHeader('Access-Control-Max-Age', '300');
  }
  // No CORS headers for non-allowlisted origins
  if (req.method === 'OPTIONS') return res.sendStatus(204);
  next();
});
HIGH
SA-SKL-CORS6-002 — The combination of Access-Control-Allow-Origin: * and Access-Control-Allow-Credentials: true is spec-violating; compliant browsers block it, but legacy reverse proxies and CDN edge runtimes may accept and forward the credentialed wildcard response to the requesting script; fix by always reflecting an explicit allowlisted origin rather than using the wildcard when credentials are involved. Detection: SkillAudit flags any HTTP middleware that sets both Access-Control-Allow-Origin: * and Access-Control-Allow-Credentials: true simultaneously.

CORS6-003 — Access-Control-Allow-Headers: * with credentials passes custom auth headers cross-origin

Chrome 108+ (and most current browsers) accept Access-Control-Allow-Headers: * as meaning "allow all request headers" for non-credentialed requests. However, the Fetch specification states that the wildcard value does not cover the Authorization header — it must be listed explicitly even when using the wildcard. When credentials are involved (Access-Control-Allow-Credentials: true), the wildcard is not permitted at all for headers and must be replaced with an explicit enumeration. Some older browser versions, Node.js-based HTTP libraries used by browser extensions, and Electron-based desktop app contexts accept the headers wildcard with credentials and proceed to send custom auth headers such as X-API-Key, X-Audit-Token, or Authorization: Bearer cross-origin. The fix is to enumerate all allowed headers explicitly when credentials are required.

// VULNERABLE — wildcard for allowed headers with credentials enabled
app.options('*', (req, res) => {
  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('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE,PATCH');
    // Wildcard for headers with credentials: spec-non-compliant; Authorization
    // is NOT covered by * per spec, and older runtimes pass custom auth headers anyway
    res.setHeader('Access-Control-Allow-Headers', '*');
    res.setHeader('Access-Control-Max-Age', '300');
    res.setHeader('Vary', 'Origin');
  }
  res.sendStatus(204);
});
// FIXED — enumerate allowed headers explicitly when credentials are involved
app.options('*', (req, res) => {
  const origin = req.headers.origin;
  res.setHeader('Vary', 'Origin');

  if (origin && ALLOWED_ORIGINS.has(origin)) {
    res.setHeader('Access-Control-Allow-Origin', origin);
    res.setHeader('Access-Control-Allow-Credentials', 'true');
    res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE,PATCH');
    // Explicit enumeration — no wildcard when credentials are required
    // Authorization must always be listed explicitly (wildcard never covers it)
    res.setHeader(
      'Access-Control-Allow-Headers',
      'Content-Type, Authorization, X-Audit-Token, X-Request-ID'
    );
    res.setHeader('Access-Control-Max-Age', '300');
  }
  res.sendStatus(204);
});
HIGH
SA-SKL-CORS6-003 — Access-Control-Allow-Headers: * does not cover the Authorization header per spec and must not be used with Access-Control-Allow-Credentials: true; older browser runtimes and Electron contexts may send custom auth headers cross-origin when this combination is present; fix by enumerating all allowed headers explicitly on any endpoint that sets credentials to true. Detection: SkillAudit flags CORS middleware that sets Access-Control-Allow-Headers: * in combination with Access-Control-Allow-Credentials: true.

CORS6-004 — CDN preflight cache shared across origins via missing Vary: Origin

When a CDN or reverse proxy caches an HTTP OPTIONS preflight response without a Vary: Origin header, it stores a single cached response keyed only on the URL path. The first origin that makes a preflight request gets its response cached, and subsequent preflight requests from different origins receive that same cached response — including the Access-Control-Allow-Origin value that names the first origin. If the first requester was an allowed origin, their CORS permission is now leaked to all other origins that share the CDN cache for that path. Cloudflare and CloudFront do not cache OPTIONS responses by default, but many CDN configurations are modified to cache all responses for performance, inadvertently including preflights. The fix is to always include Vary: Origin on OPTIONS responses and to configure the CDN to include Origin in its cache key for OPTIONS requests.

// VULNERABLE — OPTIONS response cached by CDN without Vary: Origin
// First request from https://allowed-origin.com is cached
// All subsequent requests (even from https://attacker.com) receive the cached response
// with Access-Control-Allow-Origin: https://allowed-origin.com
app.options('/api/*', (req, res) => {
  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('Access-Control-Allow-Methods', 'GET,POST');
    res.setHeader('Access-Control-Allow-Headers', 'Content-Type,Authorization');
    res.setHeader('Access-Control-Max-Age', '300');
    // Missing Vary: Origin — CDN caches this response keyed only on the URL path
  }
  res.sendStatus(204);
});
// FIXED — Vary: Origin on every OPTIONS response + CDN cache key configuration
app.options('/api/*', (req, res) => {
  const origin = req.headers.origin;

  // Always set Vary: Origin — required even when CORS headers are absent
  // so that CDN/proxy caches create separate entries per origin value
  res.setHeader('Vary', 'Origin');

  if (origin && ALLOWED_ORIGINS.has(origin)) {
    res.setHeader('Access-Control-Allow-Origin', origin);
    res.setHeader('Access-Control-Allow-Credentials', 'true');
    res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE');
    res.setHeader('Access-Control-Allow-Headers', 'Content-Type,Authorization,X-Audit-Token');
    res.setHeader('Access-Control-Max-Age', '300');
  }
  res.sendStatus(204);
});

// CDN configuration fix (Cloudflare example) — include Origin in cache key:
// Cache Rules → Custom cache key → Add Origin header to cache key for OPTIONS method
// This ensures Cloudflare stores a separate preflight response per origin value
// and does not serve a cached response for origin-A to a preflight from origin-B
HIGH
SA-SKL-CORS6-004 — OPTIONS preflight responses without Vary: Origin can be cached by CDNs and reverse proxies as a single entry keyed only on URL path; a preflight cached for an allowed origin is then served to requests from non-allowed origins, leaking the allowed origin's CORS permission; fix by always setting Vary: Origin on OPTIONS responses and configuring the CDN cache key to include the Origin request header for OPTIONS requests. Detection: SkillAudit flags CORS middleware that sets Access-Control-Allow-Origin without also setting Vary: Origin.

Detection summary

ID Severity Pattern Fix
CORS6-001 HIGH Access-Control-Max-Age > 300 on credentialed endpoints — stale cache window after policy tightening Set max-age ≤ 300 on all credentialed CORS routes; set Vary: Origin
CORS6-002 HIGH Access-Control-Allow-Origin: * + Access-Control-Allow-Credentials: true — spec violation accepted by legacy proxies Always reflect explicit allowlisted origin when credentials are required
CORS6-003 HIGH Access-Control-Allow-Headers: * with credentials — wildcard passes custom auth headers in older runtimes Enumerate allowed headers explicitly; Authorization must always be listed
CORS6-004 HIGH Missing Vary: Origin on OPTIONS response — CDN caches single preflight for all origins Add Vary: Origin unconditionally; configure CDN to key cache on Origin

Related patterns: SA-SKL-CORS5 covers credentialed cross-origin requests and preflight cache poisoning via arbitrary origin reflection. SA-SKL-CORS7 covers CORS policy enforcement on WebSocket upgrade requests, which bypass the standard OPTIONS preflight mechanism entirely. Security headers audit covers the full set of headers SkillAudit checks on every skill response.