← Blog

Claude skill CORS on internal admin routes and health endpoints — SA-SKL-CORS12

Most CORS security guidance focuses on the public API surface. SA-SKL-CORS12 covers the inverse case: CORS middleware applied to routes that should never be cross-origin accessible at all. When a global CORS middleware runs before the route-level authentication check, it sets Access-Control-Allow-Origin: * on admin routes, Prometheus metrics endpoints, and health check endpoints — making internal service topology, audit engine configuration, and billing data readable from any attacker-controlled website via a cross-site fetch. Two additional patterns round out the set: the null origin reflecting case that enables sandboxed-iframe exfiltration, and the stale preflight cache that reveals the existence of deleted routes long after they were removed.

By SkillAudit  |  8 Nov 2026

CORS on sensitive internal routes in MCP skill deployments

An MCP skill platform typically applies a single CORS middleware at the Express application level using app.use(cors(config)). If /admin, /health, and /metrics routes are mounted on the same Express app instance, they inherit the CORS headers even though they were never intended to be cross-origin accessible. The error is not in the CORS configuration itself — it's in the assumption that "all routes" need CORS. Admin routes should be protected by network-level isolation (VPC-only, or a separate internal service) and never served with cross-origin headers. Health and metrics endpoints similarly should be accessible only from monitoring infrastructure, not from browser origins. SA-SKL-CORS12 covers the full scope: global wildcard on admin; metrics exposure; null origin reflection; and stale preflight TTL.

SA-SKL-CORS12 findings at a glance
CRITICALCORS12-001 — global CORS middleware sets ACAO: * on /admin/* routes; admin endpoints readable from any browser origin despite session-cookie auth; CSRF and data exfil risk
HIGHCORS12-002 — /health and /metrics with ACAO: *; Prometheus metrics expose worker pool size, Redis queue depth, internal service hostnames to any origin
HIGHCORS12-003 — ACAO reflected from Origin header via allowlist but missing null check; ACAO: null reflects for sandboxed iframes; exfiltrates responses via <iframe sandbox>
MEDIUMCORS12-004 — CORS preflight cached with Allow-Methods: DELETE after DELETE route removed; stale browser cache continues to send DELETE preflight; reveals deleted route until TTL expires

CORS12-001 — Global CORS middleware applies ACAO: * to /admin/* routes

Express applies middleware in mount order. When app.use(cors(...)) is called before app.use('/admin', adminRouter), every admin route response includes the CORS headers configured for the public API — including Access-Control-Allow-Origin: * if the CORS configuration uses a wildcard. The CORS header alone does not bypass the admin's authentication check, but it removes the browser's same-origin restriction, allowing an attacker's website to make credentialed cross-origin requests (with credentials: 'include') if the CORS configuration reflects the Origin header instead of using a static list. Even with a wildcard ACAO, unauthenticated GET requests to admin endpoints are permitted cross-origin, potentially leaking route discovery data. The fix is to never mount CORS middleware globally — apply it only to the specific routes that require cross-origin access.

// VULNERABLE — global cors() applied before admin router; ACAO:* on admin routes
import express from 'express';
import cors from 'cors';

const app = express();
// VULNERABLE: cors() runs on ALL routes including /admin/*
app.use(cors({ origin: '*' }));

app.use('/api', publicApiRouter);
app.use('/admin', adminMiddleware, adminRouter); // ACAO:* still set by global cors()
app.use('/health', healthRouter);               // ACAO:* on health endpoint too
// FIXED — cors() applied only to public API routes; no CORS on admin/health/metrics
import express from 'express';
import cors from 'cors';

const app = express();
// No global cors() — apply only where needed

const allowedOrigins = ['https://skillaudit.dev', 'https://app.skillaudit.dev'];
const publicCors = cors({
  origin: (origin, callback) => {
    // Allow no-origin requests (server-to-server) and allowlisted origins only
    if (!origin || allowedOrigins.includes(origin)) return callback(null, true);
    callback(new Error('Origin not in CORS allowlist'));
  },
  credentials: true,
  methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
  allowedHeaders: ['Content-Type', 'Authorization'],
});

// CORS only on the public API — not on /admin, /health, /metrics
app.use('/api', publicCors, publicApiRouter);
app.use('/admin', adminMiddleware, adminRouter);     // no CORS — network-isolated only
app.use('/health', internalNetworkOnly, healthRouter); // no CORS
app.use('/metrics', internalNetworkOnly, metricsRouter);

CORS12-002 — /health and /metrics endpoints with ACAO: *

Health check and Prometheus metrics endpoints expose operational data: worker pool active/idle thread counts, Redis queue depth and latency, database connection pool saturation, and internal service endpoint hostnames from service discovery labels. When these endpoints carry Access-Control-Allow-Origin: *, an attacker's website can fetch them from a victim's browser using fetch('/metrics') across origins — without needing CSRF tokens, because the browser will include the ACAO-allowlisted response. The resulting Prometheus output reveals internal service hostnames, job queue names, and audit engine version — all valuable for a targeted attack. These endpoints should be accessible only from the monitoring subnet (Prometheus scrape targets) and never from browser origins.

// VULNERABLE — /metrics with ACAO:* exposes internal topology cross-origin
app.get('/metrics', cors({ origin: '*' }), async (req, res) => {
  // VULNERABLE: Prometheus output readable from any browser origin
  // includes: job_queue_name="audits", redis_host="redis.internal:6379",
  //           worker_version="1.4.2", audit_engine_path="/opt/audit-engine"
  res.set('Content-Type', register.contentType);
  res.send(await register.metrics());
});
// FIXED — /metrics restricted to internal network; no CORS headers
function internalNetworkOnly(req, res, next) {
  const ip = req.socket.remoteAddress || req.ip;
  // Allow loopback and RFC1918 ranges only (Prometheus scrape target is internal)
  const allowed = ['::1', '127.0.0.1', '::ffff:127.0.0.1'];
  const isInternal = allowed.includes(ip) ||
    ip.startsWith('10.') ||
    ip.startsWith('172.16.') || ip.startsWith('172.17.') ||
    ip.startsWith('192.168.');
  if (!isInternal) return res.status(403).json({ error: 'Internal only' });
  // Explicitly remove any CORS headers that may have been set upstream
  res.removeHeader('Access-Control-Allow-Origin');
  res.removeHeader('Access-Control-Allow-Credentials');
  next();
}

// No cors() middleware — no ACAO header set
app.get('/metrics', internalNetworkOnly, async (req, res) => {
  res.set('Content-Type', register.contentType);
  res.send(await register.metrics());
});

app.get('/health', internalNetworkOnly, (req, res) => {
  res.json({ status: 'ok', uptime: process.uptime() });
});

CORS12-003 — ACAO: null reflects for sandboxed iframes

When a CORS middleware reflects the request's Origin header back as the Access-Control-Allow-Origin value only if it appears in an allowlist, the implementation typically looks like: if (ALLOWLIST.includes(origin)) res.setHeader('ACAO', origin). If the allowlist check does not explicitly exclude the string 'null', and an attacker embeds the target skill in a sandboxed iframe with sandbox="allow-scripts allow-same-origin" and no allow-same-origin restriction, the iframe's origin is the string null. The request arrives with Origin: null. If the CORS handler reflects null back as ACAO: null, the browser permits the cross-origin read — the sandboxed iframe can exfiltrate the response. The fix is to check that the origin is not the literal string 'null' before reflecting.

// VULNERABLE — reflects 'null' origin when ALLOWLIST check doesn't exclude it
const ALLOWLIST = ['https://skillaudit.dev', 'https://app.skillaudit.dev'];

app.use((req, res, next) => {
  const origin = req.headers.origin;
  // VULNERABLE: 'null' string passes this check if added to allowlist or if
  // the check is: if (origin && ALLOWLIST.includes(origin))
  // But also: if developer accidentally does ALLOWLIST.includes('null') = false
  // then checks the else branch with: if (origin) res.setHeader('ACAO', origin)
  // which reflects ACAO:null for sandboxed iframe requests
  if (origin) {
    if (ALLOWLIST.includes(origin)) {
      res.setHeader('Access-Control-Allow-Origin', origin); // ACAO:null reflects
      res.setHeader('Vary', 'Origin');
    }
  }
  next();
});
// FIXED — explicit 'null' check; never reflect 'null' as ACAO
const ALLOWLIST = new Set(['https://skillaudit.dev', 'https://app.skillaudit.dev']);

app.use((req, res, next) => {
  const origin = req.headers.origin;
  if (
    origin &&
    origin !== 'null' && // explicitly reject the null origin string
    ALLOWLIST.has(origin)
  ) {
    res.setHeader('Access-Control-Allow-Origin', origin);
    res.setHeader('Access-Control-Allow-Credentials', 'true');
    res.setHeader('Vary', 'Origin');
  }
  // If origin is 'null', absent, or not in allowlist: no ACAO header set
  next();
});

CORS12-004 — Stale preflight cache with Allow-Methods: DELETE after route removal

Browsers cache CORS preflight responses for the duration of Access-Control-Max-Age. When a CORS middleware returns Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS with a long max-age (e.g., 86400 seconds = 24 hours), and the application later removes the DELETE /api/audits/:id route, existing browser sessions continue to send DELETE preflights without getting a new preflight response — because the old preflight is still cached. This allows attackers to enumerate which HTTP methods a route previously accepted (by observing which methods skip the preflight based on cached responses), revealing deleted route signatures in distributed pentest tooling. The fix is to always set Vary: Origin on CORS responses and use a short Access-Control-Max-Age: 60 to minimize the window of stale cache entries.

// VULNERABLE — long max-age preflight with broad Allow-Methods; stale after route removal
app.options('*', cors({
  origin: allowedOrigins,
  methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], // includes DELETE
  allowedHeaders: ['Content-Type', 'Authorization'],
  maxAge: 86400, // 24 hours — stale preflight persists after route removal
}));
// FIXED — short max-age; Vary:Origin; methods list matches current routes only
import { Router } from 'express';

// Generate current allowed methods by inspecting the router stack
function getAllowedMethods(router) {
  const methods = new Set(['GET', 'OPTIONS']);
  for (const layer of router.stack) {
    if (layer.route) {
      Object.keys(layer.route.methods)
        .filter(m => m !== '_all')
        .forEach(m => methods.add(m.toUpperCase()));
    }
  }
  return [...methods].join(', ');
}

app.options('*', (req, res) => {
  const origin = req.headers.origin;
  if (!origin || origin === 'null' || !ALLOWLIST.has(origin)) {
    return res.status(204).end();
  }
  res.setHeader('Access-Control-Allow-Origin', origin);
  res.setHeader('Access-Control-Allow-Credentials', 'true');
  res.setHeader('Access-Control-Allow-Methods', getAllowedMethods(app._router));
  res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
  res.setHeader('Access-Control-Max-Age', '60'); // 60 seconds — minimizes stale cache
  res.setHeader('Vary', 'Origin');               // prevent shared-cache origin mixing
  res.status(204).end();
});

Related patterns: CORS on WebSocket upgrade and SSE long-poll endpoints is covered in SA-SKL-CORS10. For CORS interaction with HTTP request smuggling that enables cache poisoning of CORS preflight responses, see SA-SKL-DESYNC1. The earlier SA-SKL-CORS11 covers subdomain wildcard and pattern-matching bypasses in allowlist implementations.

FindingSeverityVulnerable patternFix
CORS12-001CriticalGlobal cors() sets ACAO: * on /admin/*; admin endpoints cross-origin readableRemove global cors(); apply only to /api routes; /admin network-isolated + no CORS
CORS12-002HighACAO: * on /health and /metrics; Prometheus topology readable from any origininternalNetworkOnly middleware; no CORS on health/metrics; scrape via VPC only
CORS12-003HighAllowlist CORS reflects ACAO: null for sandboxed iframes; exfil via <iframe sandbox>Explicit origin !== 'null' check before reflecting; never set ACAO: null
CORS12-004MediumPreflight max-age=86400; stale Allow-Methods:DELETE after route removal; reveals deleted routeAccess-Control-Max-Age: 60; Vary: Origin on all CORS responses; derive methods from router