Claude MCP skill CORS misconfiguration — admin API and internal service mesh — SA-SKL-CORS22

Admin infrastructure is the highest-value target in any MCP skill registry: whoever can read the admin API can enumerate users, approve or revoke skills, and control billing. SA-SKL-CORS22 covers four CORS misconfiguration patterns that expose the admin API and internal service mesh endpoints to cross-origin browser attacks — from a completely missing CORS configuration on an admin route that was assumed to be intranet-only, to a service mesh control plane with Access-Control-Allow-Origin: * accidentally published on an external firewall port, to subtle CDN cache-poisoning from a missing Vary: Origin header.

SA-SKL-CORS22 findings at a glance
CRITICALCORS22-001 — Admin API endpoint (/api/admin/*) has no CORS configuration at all; endpoint is reachable from the public internet because no network firewall guards it; attacker page fetches /api/admin/users with victim's admin session cookie, returning the full user list
CRITICALCORS22-002 — Internal service mesh API exposed on external port 8080 with Access-Control-Allow-Origin: *; attacker page fetches /api/internal/service-mesh/jobs using victim's client-side admin Bearer token, reading all running skill pipeline jobs
HIGHCORS22-003 — CORS middleware only sets Access-Control-Allow-Origin on HTTP 200 responses; on 4xx/5xx errors the header is absent and the browser blocks the response, but response timing (5ms cached 404 vs 500ms database error) leaks resource existence to cross-origin timing probes
HIGHCORS22-004 — Vary: Origin header missing on CORS responses that use an origin allowlist; CDN caches the first response with ACAO: https://admin.skillaudit.dev and serves it to attacker origin requests, causing the browser to believe cross-origin access is permitted

CORS22-001 — Admin API endpoint missing CORS configuration entirely

During early development, the MCP skill registry admin API (/api/admin/*) was mounted on a separate internal Express application and accessed only from within the private network. No CORS middleware was needed because browsers on the internal network would only be loading the admin dashboard from the same origin. The assumption was sound at the time — but the assumption quietly broke when the admin service was later moved to a shared Kubernetes cluster and the ingress controller began routing all /api/admin traffic from the public internet load balancer. No firewall rule was added to restrict this prefix to internal IPs.

With no CORS headers on the admin API and no network-level restriction, an attacker hosts a malicious page and tricks an admin into visiting it. The page calls fetch('https://api.skillaudit.dev/api/admin/users', { credentials: 'include' }). The browser sends the admin's session cookie — SameSite=Lax means the cookie is sent on top-level same-site navigations and on GET requests initiated by cross-origin pages (Lax only blocks cross-origin POST/PUT/DELETE cookie sending on sub-requests initiated without user gesture, but GET requests always send the cookie). The server processes the request, returns the user list as JSON, and because there is no Access-Control-Allow-Origin header to block the response, the browser — critically — only checks ACAO when the page reads the response. No ACAO means the browser blocks the JavaScript from reading it. But if the endpoint is a simple-request-eligible GET (which it is), the HTTP request still fires and the server processes it. This matters for CSRF risk. For cross-origin reads: a page can still observe whether the response was 200 or not via the response.ok property even when CORS blocks reading the body — leaking information. And on browsers with relaxed SameSite handling or when the admin has also visited the attacker's domain within the same browsing session, the read succeeds fully.

Vulnerable
// CORS22-001 — VULNERABLE
// Admin router mounted without any CORS middleware.
// Originally run on internal-only service; now reachable from public internet.

import express from 'express';
import cors from 'cors';

const app = express();

// Public API has CORS middleware
app.use('/api/v1', cors({ origin: 'https://skillaudit.dev', credentials: true }), publicRouter);

// VULNERABLE: admin router has no CORS middleware at all
// When moved to public ingress, no network-level firewall was added either
app.use('/api/admin', requireAdminSession, adminRouter);

// adminRouter.js
router.get('/users', async (req, res) => {
  // No CORS check — attacker page can fire GET with victim's SameSite=Lax cookie
  // Browser fires the request; server processes it; returns user list
  const users = await db.query('SELECT id, email, role, plan FROM users ORDER BY created_at DESC');
  res.json({ users });
});

router.delete('/users/:id', async (req, res) => {
  // Attacker can initiate deletes; SameSite=Lax does not prevent GET-based state changes
  // if the app uses GET for destructive actions (common in admin UIs)
  await db.query('DELETE FROM users WHERE id = $1', [req.params.id]);
  res.json({ ok: true });
});
Fixed
// CORS22-001 — FIXED
// CORS middleware applied globally before all route handlers.
// Admin routes use a strict allowlist — only the admin dashboard origin is permitted.
// Admin session cookie upgraded to SameSite=Strict to block cross-origin cookie sending entirely.

import cors from 'cors';

const ADMIN_ORIGINS = new Set(['https://admin.skillaudit.dev']);

const adminCors = cors({
  origin: (origin, callback) => {
    // No Origin header = server-to-server call — allow
    if (!origin) return callback(null, true);
    if (ADMIN_ORIGINS.has(origin)) return callback(null, true);
    // Fail-closed: reject any origin not on the allowlist
    return callback(new Error('CORS: origin not permitted on admin API'));
  },
  credentials: true,
  methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
  allowedHeaders: ['Content-Type', 'Authorization', 'X-CSRF-Token'],
});

// Apply admin CORS before the session middleware so OPTIONS preflight returns quickly
app.use('/api/admin', adminCors, requireAdminSession, adminRouter);

// Set SameSite=Strict on admin session cookie — prevents browser from sending
// the cookie on any cross-origin request, regardless of CORS config
app.use(session({
  secret: process.env.SESSION_SECRET,
  cookie: {
    httpOnly: true,
    secure: true,
    sameSite: 'strict', // Upgraded from 'lax' — admin sessions require strict
  },
}));

// Also restrict /api/admin/* at the network level in Kubernetes ingress:
// ingress.kubernetes.io/whitelist-source-range: "10.0.0.0/8,172.16.0.0/12"

Attack scenario: Admin visits https://evil.com/gift. The page runs fetch('https://api.skillaudit.dev/api/admin/users', { credentials: 'include' }).then(r => r.json()).then(data => exfil(data)). With no CORS headers on the admin API, the browser fires the GET request with the admin's session cookie. The server returns the full user list as JSON. Because there is no ACAO header, the browser's CORS check fails — but only after the HTTP request has already been processed server-side. On browsers where SameSite=Lax sends the cookie on cross-origin GET requests initiated by navigation (the default behavior), the response body is accessible to JavaScript. Result: attacker reads every user account, email, role, and plan from the registry.

CORS22-002 — Service mesh API exposed externally with wildcard CORS

The MCP skill registry runs a service mesh control plane that manages inter-service job routing, rate limit enforcement, and skill pipeline scheduling. This control plane exposes an HTTP API for service accounts to submit and query jobs. During a Kubernetes migration, the service mesh API was temporarily bound to 0.0.0.0:8080 so the ops team could debug it from their laptops. The firewall rule added to allow this — ALLOW TCP 8080 from 0.0.0.0/0 — was never removed after debugging finished. The service returns Access-Control-Allow-Origin: * because it was intended to be used by health check scripts running from various internal monitoring tools.

The combination of an externally reachable port and ACAO: * creates a cross-origin read vulnerability against any admin who has a Bearer token stored client-side. The token need not be in localStorage — if the admin dashboard stores the token in memory and the attacker can inject JavaScript (or if the attacker uses a related vulnerability from AUTH15-003 to obtain the token from a service worker cache), the attacker's page can fetch https://api.skillaudit.dev:8080/api/internal/service-mesh/jobs with the Authorization header and read the full list of running skill pipeline jobs, including job IDs, skill metadata, and execution parameters.

Vulnerable
// CORS22-002 — VULNERABLE
// Service mesh API bound to 0.0.0.0:8080 — reachable from internet.
// ACAO:* set for health checks — attacker page can read job list with victim's Bearer token.

import express from 'express';

const internalApp = express();

// VULNERABLE: wildcard CORS applied to service mesh API
internalApp.use((req, res, next) => {
  res.setHeader('Access-Control-Allow-Origin', '*'); // Intended for health checks
  res.setHeader('Access-Control-Allow-Headers', 'Authorization, Content-Type');
  res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
  next();
});

internalApp.get('/api/internal/service-mesh/jobs', authenticateBearer, async (req, res) => {
  // Returns all running skill pipeline jobs — skill IDs, configs, execution state
  const jobs = await serviceMesh.listJobs({ limit: 100 });
  res.json({ jobs });
});

// Server listens on all interfaces — firewall rule 'ALLOW TCP 8080 from 0.0.0.0/0' never removed
internalApp.listen(8080, '0.0.0.0');
Fixed
// CORS22-002 — FIXED
// Service mesh API bound to localhost only — not reachable from external network.
// CORS origin allowlist applied — no wildcard; empty allowlist = deny all browser requests.
// Defense in depth: firewall blocks port 8080 from external IPs.

import express from 'express';
import cors from 'cors';

const internalApp = express();

// Fix 1: apply strict origin allowlist — service mesh has NO browser-accessible origins
// An empty set means: no browser-initiated cross-origin request is ever allowed.
// Server-to-server calls (no Origin header) still pass.
const SERVICE_MESH_ORIGINS = new Set([
  // Add 'https://admin.skillaudit.dev' here only if the admin dashboard calls service mesh directly.
  // Currently: no browser should ever call the service mesh API directly.
]);

internalApp.use(cors({
  origin: (origin, callback) => {
    if (!origin) return callback(null, true); // Server-to-server: allow
    // Browser request: deny unless origin explicitly listed
    if (SERVICE_MESH_ORIGINS.has(origin)) return callback(null, true);
    callback(new Error('CORS: service mesh API does not permit browser-originated cross-origin requests'));
  },
  credentials: false, // Service mesh uses Bearer tokens, not cookies
}));

internalApp.get('/api/internal/service-mesh/jobs', authenticateBearer, async (req, res) => {
  const jobs = await serviceMesh.listJobs({ limit: 100 });
  res.json({ jobs });
});

// Fix 2: bind to localhost only — not reachable from outside the pod
internalApp.listen(8080, '127.0.0.1');

// Fix 3: firewall rule (Kubernetes NetworkPolicy)
// spec:
//   podSelector:
//     matchLabels:
//       app: service-mesh
//   policyTypes: [Ingress]
//   ingress:
//   - from:
//     - podSelector:
//         matchLabels:
//           role: service-account
//     ports:
//     - protocol: TCP
//       port: 8080

Why ACAO:* on authenticated endpoints is always wrong: The spec prohibits combining Access-Control-Allow-Origin: * with Access-Control-Allow-Credentials: true — browsers reject that combination. But a Bearer token sent via the Authorization header is not a "credential" in the CORS sense (it is not a cookie, TLS client certificate, or HTTP basic auth). A browser fetch with headers: { Authorization: 'Bearer ...' } and ACAO: * succeeds. The attacker only needs to obtain the token — JavaScript in the same session context (injected script, service worker, or a related XSS) can read it from memory and pass it to a cross-origin fetch. For token storage security patterns, see SA-SKL-AUTH15.

CORS22-003 — CORS headers missing on error responses enabling timing-based probing

The CORS middleware is applied as an Express middleware that runs before route handlers but only sets the Access-Control-Allow-Origin header inside the route handler's res.json() call path. When the route handler short-circuits with an error — a 404 from a missing resource, a 401 from an expired session, a 500 from a database failure — the Express error handler fires instead of the normal response path, and the error handler does not set CORS headers. The browser blocks the error response from being read cross-origin, which looks like correct behavior. It is not.

Even though the browser blocks the error response body, the cross-origin page can observe the response timing. A 404 returned from an in-memory cache takes around 3–8 milliseconds. A 404 returned after a database lookup for a non-existent resource takes 40–120 milliseconds. A 500 from a database constraint violation takes 200–600 milliseconds. By issuing cross-origin requests for /api/admin/users/alice@example.com, /api/admin/users/bob@example.com, etc., and measuring the response time of each blocked response, the attacker learns which admin usernames exist in the database without reading any response body. The same attack applies to skill IDs, organization IDs, and any other enumerable resource in the admin API.

Vulnerable
// CORS22-003 — VULNERABLE
// CORS middleware runs in route handler — skipped entirely when error handler fires.
// Error response timing leaks resource existence to cross-origin timing probes.

import express from 'express';

const app = express();

// VULNERABLE: CORS set inside route handler, not as global middleware
app.get('/api/admin/users/:email', requireAdminSession, async (req, res, next) => {
  try {
    const user = await db.users.findByEmail(req.params.email);
    if (!user) {
      // No CORS header on this 404 — browser blocks it.
      // But the 404 arrives in ~5ms (cached) vs ~400ms (slow DB query for non-existent user).
      return res.status(404).json({ error: 'User not found' });
    }
    // CORS header only set on 200 responses
    res.setHeader('Access-Control-Allow-Origin', 'https://admin.skillaudit.dev');
    res.setHeader('Vary', 'Origin');
    res.json({ user });
  } catch (err) {
    // Error handler fires — no CORS header set here either
    // 500 timing (200–600ms) distinguishes DB errors from "user not found" 404s
    next(err);
  }
});

// Error handler — no CORS headers
app.use((err, req, res, next) => {
  res.status(500).json({ error: 'Internal server error' });
});
Fixed
// CORS22-003 — FIXED
// CORS middleware applied globally and unconditionally — runs before route handlers and error handlers.
// All responses, including 4xx and 5xx, include the ACAO header.
// Error response bodies are generic — timing normalization added for sensitive lookup endpoints.

import cors from 'cors';

const ADMIN_ORIGINS = new Set(['https://admin.skillaudit.dev']);

// Fix 1: apply CORS as top-level middleware — before routes, before error handler
app.use(cors({
  origin: (origin, callback) => {
    if (!origin || ADMIN_ORIGINS.has(origin)) return callback(null, true);
    callback(new Error('CORS: origin not permitted'));
  },
  credentials: true,
}));
// cors() middleware automatically handles OPTIONS preflight and sets ACAO on ALL responses,
// including error responses, because it registers a response interceptor — not a route handler.

app.get('/api/admin/users/:email', requireAdminSession, async (req, res, next) => {
  try {
    const user = await db.users.findByEmail(req.params.email);

    // Fix 2: normalize timing on user-existence probes to defeat timing oracle
    // Both "found" and "not found" responses are delayed to a minimum floor of 150ms
    if (!user) {
      await delay(150); // Normalize: attacker cannot distinguish cached vs DB miss
      return res.status(404).json({ error: 'Not found' });
    }
    res.json({ user });
  } catch (err) {
    next(err);
  }
});

// Fix 3: error handler — CORS middleware already set ACAO before this fires
// No need to set ACAO here — just handle the error body
app.use((err, req, res, next) => {
  // Log internally but return generic message — do not leak DB error details
  logger.error({ err }, 'Unhandled error in admin API');
  res.status(500).json({ error: 'Internal server error' });
});

function delay(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

CORS middleware placement determines whether error responses are protected: When CORS is set via res.setHeader() inside a route handler, the headers are only written if the route handler completes normally. When CORS is applied via app.use(cors(...)) as a top-level middleware, the cors package patches the response object so that ACAO is included regardless of which handler eventually writes the response. Always apply CORS at the application level, not at the route level. For timing normalization patterns in authentication endpoints, see the constant-time response techniques in SA-SKL-TIMING6.

CORS22-004 — Missing Vary: Origin causes CDN to serve wrong ACAO to attacker origin

When a CORS middleware uses an origin allowlist — returning Access-Control-Allow-Origin: https://admin.skillaudit.dev for requests from the admin dashboard origin and no ACAO header for all other origins — the HTTP response body is identical regardless of the origin. A CDN sitting in front of the API (Cloudflare, AWS CloudFront, Fastly) sees two requests that differ only in the Origin request header. If the response does not include Vary: Origin, the CDN treats both requests as cache-equivalent and serves the first cached response to all subsequent requests.

The attack unfolds as follows: the legitimate admin dashboard at https://admin.skillaudit.dev loads and fires a GET to /api/admin/skills?status=pending. The CDN caches the response, which includes Access-Control-Allow-Origin: https://admin.skillaudit.dev. Within the CDN's cache TTL (say, 60 seconds), an attacker's page at https://evil.com fires the same GET to /api/admin/skills?status=pending. The CDN serves the cached response — including the Access-Control-Allow-Origin: https://admin.skillaudit.dev header. The browser's CORS check compares this header against the requesting origin (https://evil.com) and finds they do not match — the browser still blocks the read. But if the CDN cache was poisoned with an attacker-controlled origin as the first request (possible if the attacker probes the endpoint before any admin does), the cached ACAO would reflect the attacker's origin and the browser would permit the cross-origin read.

Vulnerable
// CORS22-004 — VULNERABLE
// CORS middleware sets dynamic ACAO based on origin allowlist but omits Vary: Origin.
// CDN caches the first response and serves its ACAO to all subsequent origins.

import cors from 'cors';

const ADMIN_ORIGINS = new Set(['https://admin.skillaudit.dev']);

// VULNERABLE: Vary: Origin not set — cors() default behavior
app.use(cors({
  origin: (origin, callback) => {
    if (!origin || ADMIN_ORIGINS.has(origin)) return callback(null, true);
    callback(null, false); // Reject non-allowlist origins — but Vary header missing
  },
  credentials: true,
  // No explicit Vary configuration
}));

// If CDN caches GET /api/admin/skills response from admin dashboard origin,
// it stores ACAO: https://admin.skillaudit.dev with the response.
// Subsequent request from attacker origin hits CDN cache — gets same ACAO header.
// If attacker was first to request this URL, CDN stores ACAO: null (no header)
// and all future admin dashboard requests are broken (browser blocks them too).

app.get('/api/admin/skills', requireAdminSession, async (req, res) => {
  const skills = await db.skills.findPending();
  res.json({ skills });
});
Fixed
// CORS22-004 — FIXED
// Vary: Origin set on all responses — CDN creates separate cache entries per Origin.
// Cache-Control: private added to admin API responses — CDN should not cache them at all.
// preflight OPTIONS responses also include Vary: Origin.

import cors from 'cors';

const ADMIN_ORIGINS = new Set(['https://admin.skillaudit.dev']);

app.use(cors({
  origin: (origin, callback) => {
    if (!origin || ADMIN_ORIGINS.has(origin)) return callback(null, true);
    callback(null, false);
  },
  credentials: true,
}));

// Fix 1: explicitly set Vary: Origin on every response after CORS middleware
// cors() sets Vary: Origin automatically when origin callback is used — verify this in your version.
// Add a manual middleware as belt-and-suspenders insurance:
app.use((req, res, next) => {
  // Append Origin to Vary without overwriting existing Vary values
  const existing = res.getHeader('Vary');
  if (existing) {
    const values = Array.isArray(existing) ? existing : [existing];
    if (!values.some(v => v.toLowerCase().includes('origin'))) {
      res.setHeader('Vary', [...values, 'Origin'].join(', '));
    }
  } else {
    res.setHeader('Vary', 'Origin');
  }
  next();
});

app.get('/api/admin/skills', requireAdminSession, async (req, res) => {
  // Fix 2: Cache-Control: private prevents shared CDN caches from storing admin responses
  res.setHeader('Cache-Control', 'private, no-store');
  const skills = await db.skills.findPending();
  res.json({ skills });
});

// Fix 3: CDN configuration (Cloudflare example)
// Set "Cache Key" to include the Origin header for /api/admin/* paths.
// Or set Cache-Control: private to bypass CDN caching entirely for admin routes.
// Cloudflare Page Rule: /api/admin/* → Cache Level: Bypass

When to use Cache-Control: private vs Vary: Origin: For admin API endpoints, Cache-Control: private, no-store is simpler and safer than relying on Vary: Origin — it instructs shared caches (CDNs, proxies) not to cache the response at all. Use Vary: Origin for public or semi-public resources where CDN caching is desirable and the response legitimately varies by origin (for example, a public skill metadata endpoint that returns slightly different data for authenticated vs unauthenticated origins). Always set both: Vary: Origin ensures correctness; Cache-Control: private ensures safety on admin routes. For related CDN cache interaction patterns, see SA-SKL-CORS21.

How SkillAudit detects SA-SKL-CORS22

SkillAudit's CORS scanner runs four detection passes for the SA-SKL-CORS22 family against MCP skill registry Express codebases:

Summary

IDSeverityRoot causeFix
CORS22-001 Critical Admin API mounted without CORS middleware; assumed intranet-only but exposed publicly after Kubernetes migration with no firewall rule Apply CORS middleware globally with admin-origin allowlist; set SameSite=Strict on admin session cookies; add Kubernetes NetworkPolicy to restrict /api/admin to internal cluster traffic
CORS22-002 Critical Service mesh API bound to 0.0.0.0:8080 and returns ACAO:*; firewall rule opened for debugging and never closed; attacker reads job list via victim's client-side Bearer token Bind service mesh API to 127.0.0.1; replace wildcard CORS with empty-set allowlist; add Kubernetes NetworkPolicy to block port 8080 from external traffic
CORS22-003 High CORS headers only set inside route handler — absent on 4xx/5xx error responses; response timing on blocked errors leaks resource existence (username, skill ID enumeration) Apply CORS as top-level app.use(cors(...)) middleware so all responses including errors include ACAO; add timing normalization on user-existence lookup endpoints
CORS22-004 High Vary: Origin missing on allowlist-based CORS responses; CDN caches first ACAO value and serves it to all origins; attacker-first request poisons cache with absent ACAO, breaking legitimate admin access Always include Vary: Origin when ACAO value depends on request Origin; set Cache-Control: private, no-store on all admin API responses to bypass CDN caching entirely

SkillAudit automatically detects CORS misconfiguration patterns in MCP skill registry codebases. Join the waitlist to audit yours. Related: SA-SKL-CORS21 — SA-SKL-AUTH15