← Blog

Claude skill CORS misconfiguration in MCP microservice internal APIs — SA-SKL-CORS11

CORS in a microservice architecture is not just an application-layer concern — it intersects with CDN caching, service mesh authentication, and rate limiting in ways that create security gaps invisible to any single layer. SA-SKL-CORS11 covers four patterns unique to MCP skill deployments that use internal microservices: a wildcard CORS policy on an internal service that is reachable from browser contexts via CDN passthrough; mTLS at the sidecar layer that creates a false sense of authentication at the application layer; a missing Vary: Origin header on OPTIONS responses that causes CDN cache poisoning; and CORS preflight consumption of rate limit quota that disadvantages legitimate cross-origin callers.

By SkillAudit  |  7 Nov 2026

Internal APIs are not automatically inaccessible from browser contexts

The common assumption — that an "internal" microservice is unreachable from the public internet and therefore needs no CORS policy — holds only when the network topology is correctly designed and no CDN or reverse proxy passes CORS headers from internal upstream services to external browser clients. In practice, MCP skill platforms often route all traffic through a single API gateway or CDN, which forwards requests to internal services. If the CDN is configured to pass upstream response headers transparently, a wildcard Access-Control-Allow-Origin: * set by an internal service becomes visible to and honoured by browsers making cross-origin requests.

Similarly, service mesh mTLS is a network-layer control, not an application-layer authentication control. It proves that the caller is a registered mesh member, not that the caller is authorized to perform the requested operation. A compromised peer service within the mesh can call any internal API endpoint with any payload, completely bypassing application-layer authorization checks that were written with the assumption that only the legitimate upstream service would call them. SkillAudit's SA-SKL-CORS11 scanner checks for all four patterns in a single scan of the service configuration and application code.

SA-SKL-CORS11 findings at a glance
HIGHCORS11-001 — Internal microservice CORS wildcard: CDN passthrough makes it browser-reachable from any origin
HIGHCORS11-002 — mTLS terminates at sidecar; application auth skipped for in-mesh calls — compromised peer bypasses auth
MEDIUMCORS11-003 — OPTIONS cached without Vary: Origin: CDN serves wrong ACAO to second origin
MEDIUMCORS11-004 — CORS before rate limit: OPTIONS preflights consume quota, exhausting limit for cross-origin callers

CORS11-001 — Internal microservice wildcard CORS reachable from browser via CDN passthrough

An internal audit-worker microservice with Access-Control-Allow-Origin: * set on its responses is intended to service calls from other internal services, never from browser clients. The developer's reasoning: "it's not public, browsers can't reach it, so the CORS policy doesn't matter." This breaks when a CDN or API gateway sits in front of the entire platform and forwards both requests and response headers from upstream internal services. A browser script on any origin can send a request to the CDN edge URL, which proxies it to the internal service, which responds with ACAO: * — and the browser honours that header. The browser-same-origin policy is bypassed.

The correct approach is for internal APIs that should never be directly callable from browser contexts to set no CORS headers at all. The absence of an Access-Control-Allow-Origin header means the browser will block the response — which is the desired behaviour. Apply network segmentation (the internal service should not be reachable via the CDN at all) as the primary control, and no-CORS-header as a defence-in-depth secondary control. Never set ACAO: * on an endpoint unless it truly has no session context and all data it returns is public.

// VULNERABLE — internal microservice sets ACAO:* on all responses
import express from 'express';
import cors from 'cors';

const app = express();

// Developer thinks: "this is an internal service, only called by other services"
// But CDN sits in front and passes these headers to browsers
app.use(cors({ origin: '*' }));  // VULNERABLE: ACAO:* on internal service

app.post('/internal/run-audit', async (req, res) => {
  // Contains private audit data, API keys, internal configuration
  // Now accessible from any browser origin via CDN
  const result = await runAudit(req.body.repoUrl);
  res.json(result);
});
// FIXED — no CORS headers on internal services + network segmentation
import express from 'express';

const app = express();

// No cors() middleware — internal service sets NO CORS headers
// If a browser tries to make a cross-origin request, the absence of ACAO
// means the browser blocks the response (same-origin policy applies)

// Add a middleware that explicitly strips any accidentally-added CORS headers
app.use((req, res, next) => {
  // Remove CORS headers if any upstream middleware added them
  res.removeHeader('Access-Control-Allow-Origin');
  res.removeHeader('Access-Control-Allow-Credentials');

  // Reject requests that have an Origin header (browser cross-origin requests)
  // Internal service-to-service calls do NOT set Origin headers
  if (req.headers.origin) {
    return res.status(403).json({ error: 'Cross-origin requests not permitted' });
  }

  next();
});

// Network segmentation (Caddy config — internal service not routed from public CDN)
// In Caddyfile: the /internal/* routes should only be served from internal network
// Never exposed via the public-facing :443 block
app.post('/internal/run-audit', requireServiceToken, async (req, res) => {
  const result = await runAudit(req.body.repoUrl);
  res.json(result);
});

CORS11-002 — mTLS terminates at sidecar; application auth skipped for in-mesh calls

Service mesh mTLS (mutual TLS) authenticates the identity of the calling service using client certificates — it proves that the caller is a registered member of the mesh (a Kubernetes pod with a valid service account certificate). What it does not prove is that the caller is authorised to perform the specific operation being requested with the specific data being passed. When an application developer writes an internal endpoint with the comment "this is only called by the billing service, so we don't need to check auth here," they are relying on mTLS to enforce that invariant. A compromised billing service, or any other compromised service in the mesh with network access to the endpoint, can send arbitrary requests to that endpoint and have them accepted without any application-layer check.

The fix is defence-in-depth: apply application-layer authentication even for in-mesh calls. Use short-lived signed service tokens (JWTs issued by an internal token service, valid for 60 seconds, bound to the caller's service identity and the target operation) or Kubernetes service account tokens for Kubernetes-native auth. The mTLS layer verifies transport security; the application layer verifies that the specific caller is authorised for the specific operation.

// VULNERABLE — application auth skipped because mTLS "proves" the caller
app.post('/internal/charge-credits', async (req, res) => {
  // VULNERABLE: "mTLS proves this is the billing service, so no auth check"
  // A compromised payment-processor service (also in the mesh) can call this endpoint
  // mTLS only proves mesh membership, not authorization for this specific operation

  const { userId, amount, reason } = req.body;
  // No: JWT verification, service identity check, operation allowlist, or audit log
  await Credits.deduct(userId, amount, reason);
  res.json({ success: true });
});
// FIXED — application-layer service token + operation validation + audit log
import jwt from 'jsonwebtoken';

// Service tokens: short-lived JWTs issued by internal token service
// Each service has a known audience claim; this endpoint only accepts 'billing-svc'
const ALLOWED_SERVICE = 'billing-svc';

function requireServiceAuth(allowedService) {
  return (req, res, next) => {
    const token = req.headers['x-service-token'];
    if (!token) return res.status(401).json({ error: 'Service token required' });

    try {
      const payload = jwt.verify(token, process.env.SERVICE_JWT_PUBLIC_KEY, {
        algorithms: ['RS256'],
        issuer: 'internal-token-svc.skillaudit.svc.cluster.local',
        audience: 'credits-svc',  // this service's audience
      });

      // Check the calling service identity — not just valid signature
      if (payload.sub !== allowedService) {
        return res.status(403).json({ error: `Service ${payload.sub} not permitted` });
      }

      req.callerService = payload.sub;
      next();
    } catch (err) {
      res.status(401).json({ error: 'Invalid service token' });
    }
  };
}

app.post('/internal/charge-credits',
  requireServiceAuth(ALLOWED_SERVICE),  // application-layer auth
  async (req, res) => {
    const { userId, amount, reason } = req.body;

    // Additional operation validation
    if (!Number.isInteger(amount) || amount <= 0 || amount > 1000) {
      return res.status(400).json({ error: 'Invalid amount' });
    }

    await Credits.deduct(userId, amount, reason);

    // Audit log with caller identity
    await AuditLog.insert({
      action: 'credit_deduction',
      caller: req.callerService,
      userId, amount, reason,
      timestamp: new Date(),
    });

    res.json({ success: true });
  }
);

CORS11-003 — OPTIONS cached without Vary: Origin causes CDN cache poisoning

The Access-Control-Allow-Origin (ACAO) response header value depends on the request's Origin header — a correctly configured CORS middleware returns the requested origin if it is in the allowlist, or omits the header otherwise. When a CDN caches the OPTIONS preflight response without including Vary: Origin in the cache key, the CDN stores the ACAO value from the first request and serves it to all subsequent requests regardless of their Origin. If https://app.skillaudit.dev sends the first preflight and gets back ACAO: https://app.skillaudit.dev, then a later preflight from https://evil.com gets the same cached response — including ACAO: https://app.skillaudit.dev — which the browser treats as a granted permission. The attacker now has effective CORS access to the API endpoint.

The fix is straightforward: add Vary: Origin to all CORS responses, including OPTIONS preflights. The cors npm package does this automatically when origin is set to a function or an array — verify that you have not disabled it. For CDNs, also configure the cache key to include the Origin request header so that different origins get separate cache entries. In Cloudflare, use a Cache Rule; in AWS CloudFront, forward and whitelist the Origin header in the cache policy.

// VULNERABLE — CORS middleware responds correctly but Vary:Origin missing or stripped
import cors from 'cors';

const corsOptions = {
  origin: ['https://app.skillaudit.dev', 'https://dashboard.skillaudit.dev'],
  credentials: true,
  methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
};

app.use(cors(corsOptions));
// cors() sets Vary:Origin automatically — but CDN may not include Origin in cache key
// If CDN caches OPTIONS without Origin in cache key: cache poisoning occurs

// Also vulnerable: custom CORS middleware that forgets Vary
app.options('*', (req, res) => {
  const origin = req.headers.origin;
  const allowed = ['https://app.skillaudit.dev'];
  if (allowed.includes(origin)) {
    res.setHeader('Access-Control-Allow-Origin', origin);
    res.setHeader('Access-Control-Allow-Credentials', 'true');
    // MISSING: res.setHeader('Vary', 'Origin');
    // CDN caches this response and serves it to all origins
  }
  res.sendStatus(204);
});
// FIXED — Vary:Origin on all CORS responses + CDN cache key includes Origin
import cors from 'cors';

const corsOptions = {
  origin: (origin, callback) => {
    const allowed = new Set([
      'https://app.skillaudit.dev',
      'https://dashboard.skillaudit.dev',
    ]);
    // cors() sets Vary:Origin automatically when using a function here
    if (!origin || allowed.has(origin)) {
      callback(null, true);
    } else {
      callback(new Error('Not allowed by CORS'));
    }
  },
  credentials: true,
  methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
  optionsSuccessStatus: 204,
};

app.use(cors(corsOptions));

// Belt-and-suspenders: explicit Vary:Origin middleware after cors()
// Ensures CDN cache key varies by Origin even if cors() behavior changes
app.use((req, res, next) => {
  if (req.headers.origin) {
    // Append Origin to Vary without overwriting existing Vary values
    const existing = res.getHeader('Vary') || '';
    const vary = existing ? `${existing}, Origin` : 'Origin';
    res.setHeader('Vary', vary);
  }
  next();
});

// CDN configuration note (Cloudflare Cache Rules):
// Cache Rule: "If Path equals /api/*"
//   Cache Key: include "Origin" request header
// This ensures OPTIONS responses are cached per-origin, not globally

CORS11-004 — CORS before rate limiting: preflights consume quota for cross-origin callers

When CORS middleware runs before rate limit middleware in Express, an OPTIONS preflight request is handled and responds before the rate limit counter is incremented — but many rate limit configurations apply the counter to OPTIONS requests as well as actual API requests. Cross-origin browser callers (using fetch() or XMLHttpRequest) send two HTTP requests per API call: one OPTIONS preflight and one actual request. Same-origin callers or non-browser clients (curl, server-to-server) send only the actual request. The result is that cross-origin browser callers exhaust their rate limit quota twice as fast as same-origin or non-browser callers, creating an operational disadvantage that can degrade the user experience or trigger a false-positive rate limit block.

The fix is to exclude OPTIONS requests from the rate limit counter, or to give preflight requests their own higher-limit bucket. The express-rate-limit skip option allows skipping the counter for specific request methods. Alternatively, place the rate limit middleware after CORS middleware so that preflights are handled and responded to without touching the counter — OPTIONS returns 204 before reaching the rate limit layer.

// VULNERABLE — rate limit applies to OPTIONS preflights; cross-origin callers pay double
import rateLimit from 'express-rate-limit';
import cors from 'cors';

const limiter = rateLimit({
  windowMs: 60 * 1000,
  max: 100,
  // No skip for OPTIONS — preflights consume quota
});

// Middleware order: rate limit FIRST, then cors
app.use(limiter);           // OPTIONS consumed here
app.use(cors(corsOptions));

// Cross-origin browser caller:
//   OPTIONS /api/audit → counter: 1 (preflight, no actual work)
//   POST /api/audit   → counter: 2 (actual request)
// 50 API calls = 100 counter increments → rate limited after 50 calls instead of 100

// Same-origin / curl caller:
//   POST /api/audit → counter: 1 (no preflight)
// 100 API calls = 100 counter increments → full quota used
// FIXED — skip OPTIONS from rate limit counter; cors before rate limit
import rateLimit from 'express-rate-limit';
import cors from 'cors';
import RedisStore from 'rate-limit-redis';
import { createClient } from 'redis';

const redisClient = createClient({ url: process.env.REDIS_URL });
await redisClient.connect();

// CORS runs first — OPTIONS preflights return 204 before reaching rate limit
app.use(cors(corsOptions));
app.options('*', cors(corsOptions));  // explicit OPTIONS handler returns before rate limit

const limiter = rateLimit({
  windowMs: 60 * 1000,
  max: 100,
  store: new RedisStore({ sendCommand: (...args) => redisClient.sendCommand(args) }),

  // Option A: skip OPTIONS entirely from rate limit counter
  skip: (req) => req.method === 'OPTIONS',

  // Option B: alternatively, use separate (higher) limit for OPTIONS
  // keyGenerator can include method to give OPTIONS its own bucket
  // keyGenerator: (req) => `${req.ip}:${req.method === 'OPTIONS' ? 'preflight' : 'api'}`,
});

// Rate limit applies AFTER cors handles OPTIONS
app.use(limiter);

// All callers — same-origin, cross-origin browser, curl — now get equal quota
// Cross-origin: OPTIONS returns 204 from cors handler (no counter); POST hits limiter (counter++)
// Same-origin: POST hits limiter (counter++)
// Equal treatment: 100 actual API calls = 100 counter increments for all caller types

Summary table — SA-SKL-CORS11 patterns

IDSeverityRoot causeFix
CORS11-001HIGHInternal service ACAO:* — reachable from browser via CDN header passthroughNo CORS headers on internal services + reject Origin header in middleware
CORS11-002HIGHmTLS proves mesh membership, not operation auth — compromised peer bypasses app authApplication-layer service JWT + operation allowlist + audit log
CORS11-003MEDIUMOPTIONS cached without Vary:Origin — CDN serves wrong ACAO to second originVary:Origin on all CORS responses + CDN cache key includes Origin header
CORS11-004MEDIUMCORS after rate limit — OPTIONS preflights consume quota; cross-origin callers pay doubleCORS before rate limit + skip OPTIONS from counter or give preflight its own bucket

SkillAudit scans for all four SA-SKL-CORS11 patterns automatically. Run a free scan at skillaudit.dev or see related patterns: SA-SKL-CORS10, SA-SKL-RATELIMIT6.