SA-SKL-CORS31 — CORS Misconfiguration
CORS Misconfiguration in MCP Skill Registry Audit Report Sharing and Public Badge Endpoints
Audit report sharing and public badge endpoints occupy a unique position in an MCP skill registry: they straddle the boundary between private audit data and publicly accessible content. SA-SKL-CORS31 covers four CORS misconfigurations that allow attackers to read full private audit reports cross-origin via victim session cookies, extract audit metadata from ostensibly public badge endpoints, determine audit record existence via a timing oracle in share link generation, and read findings from any two audit reports via a wildcard CORS policy on the report comparison endpoint.
GET /api/audits/:id/share uses cors({origin:true,credentials:true}) — any origin reads the full private audit report (vulnerability list, severity scores, remediation hints) cross-origin using the victim's session cookieGET /badge/:skillId has Access-Control-Allow-Origin: * but also serves cached audit metadata including last scan timestamp and grade details; any origin reads cross-origin; fix: badge SVG with no metadata beyond grade letterPOST /api/audits/:id/share-link reflects Origin into ACAO before the ownership check; timing oracle reveals audit record existence across all organizations; fix: auth and ownership check before CORS header emissionGET /api/audits/compare has ACAO: *; any origin reads the diff of two audit reports by ID, leaking findings from both reports cross-origin; fix: explicit allowlist + ownership check for both reportIdsCORS31-001 — Credential-bearing CORS on private audit share endpoint
The audit share endpoint GET /api/audits/:id/share is intended to allow users to preview what a shared report looks like before generating a share link. The endpoint is protected by session authentication. However, it uses cors({ origin: true, credentials: true }), which reflects any requesting origin into Access-Control-Allow-Origin while also setting Access-Control-Allow-Credentials: true. This combination allows any attacker-controlled page to fetch the full private audit report — including all vulnerability findings, severity scores, and remediation hints — using the victim's session cookie when the victim visits the attacker's page.
// CORS31-001 — VULNERABLE
// cors({origin: true, credentials: true}) reflects any Origin with credentials allowed.
const cors = require('cors');
router.get('/audits/:id/share', cors({ origin: true, credentials: true }), requireSession, async (req, res) => {
const audit = await db.audits.findById(req.params.id);
if (!audit || audit.orgId !== req.user.orgId) return res.status(404).json({ error: 'Not found' });
res.json(audit); // full audit: vulnerabilities[], severities[], remediations[]
});
// Attacker page:
// fetch('https://skillaudit.dev/api/audits/TARGET_ID/share', { credentials: 'include' })
// .then(r => r.json()).then(data => exfiltrate(data))
Fix: Replace cors({origin: true}) with an explicit allowlist. The share preview endpoint only needs to be called from the SkillAudit dashboard origin itself, so restrict ACAO to that origin only. Strip private remediation hints from the CORS-accessible response — expose only the grade and finding count. For the actual share link, generate an opaque token that serves a public-safe read-only view with no credentials required.
// CORS31-001 — FIXED
const ALLOWED_ORIGINS = new Set(['https://skillaudit.dev', 'https://app.skillaudit.dev']);
function strictCors(req, res, next) {
const origin = req.headers.origin;
if (origin && ALLOWED_ORIGINS.has(origin)) {
res.set('Access-Control-Allow-Origin', origin);
res.set('Access-Control-Allow-Credentials', 'true');
res.set('Vary', 'Origin');
}
if (req.method === 'OPTIONS') return res.sendStatus(204);
next();
}
router.get('/audits/:id/share', strictCors, requireSession, async (req, res) => {
const audit = await db.audits.findByIdAndOrgId(req.params.id, req.user.orgId);
if (!audit) return res.status(404).json({ error: 'Not found' });
// Return only grade and counts — no vulnerability details or remediation hints
res.json({ grade: audit.grade, findingCount: audit.findings.length, scannedAt: audit.scannedAt });
});
CORS31-002 — Badge endpoint serves audit metadata under wildcard CORS
The badge endpoint GET /badge/:skillId serves an SVG image intended for embedding in GitHub READMEs and documentation sites. The endpoint sets Access-Control-Allow-Origin: * so that any page can embed the badge image. However, the same endpoint also serves a cached audit metadata object alongside the SVG — including the last scan timestamp, the numeric vulnerability score, the grade letter, and the count of findings by severity. This cached metadata is returned in an X-Audit-Meta response header and in a JSON variant served when Accept: application/json is included. Any origin can read these headers and the JSON variant cross-origin, leaking internal audit metrics to arbitrary third-party pages.
// CORS31-002 — VULNERABLE
// ACAO:* on badge endpoint also exposes audit metadata via headers and JSON variant.
router.get('/badge/:skillId', async (req, res) => {
res.set('Access-Control-Allow-Origin', '*'); // wildcard — required for image embedding
const audit = await cache.getLatestAudit(req.params.skillId); // Redis cache
if (!audit) return res.status(404).send('');
// VULNERABLE: metadata in response header and JSON variant readable cross-origin
res.set('X-Audit-Meta', JSON.stringify({
score: audit.score, grade: audit.grade, criticalCount: audit.criticalCount,
highCount: audit.highCount, scannedAt: audit.scannedAt
}));
if (req.headers['accept']?.includes('application/json')) {
return res.json(audit); // full audit metadata readable by any origin
}
res.type('image/svg+xml').send(renderBadgeSvg(audit.grade));
});
Fix: Serve the badge SVG from a dedicated CDN path that emits only the SVG content and no metadata headers. Remove the JSON variant from the badge endpoint entirely — callers who need audit metadata should use the authenticated API with appropriate CORS restrictions. The SVG itself should contain only the grade letter and color; numeric scores and counts are not needed in the embeddable badge.
// CORS31-002 — FIXED
router.get('/badge/:skillId', async (req, res) => {
res.set('Access-Control-Allow-Origin', '*'); // only for embedding SVG images
const grade = await cache.getLatestGradeLetter(req.params.skillId); // only grade letter from cache
if (!grade) return res.status(404).type('image/svg+xml').send(renderBadgeSvg('?'));
// No X-Audit-Meta header — no metadata exposed under wildcard CORS
// No JSON variant — authenticated API endpoint handles metadata requests
res.type('image/svg+xml').send(renderBadgeSvg(grade)); // only grade letter in SVG
});
CORS31-003 — Origin reflection before ownership check exposes timing oracle
The share link generation endpoint POST /api/audits/:id/share-link emits a Access-Control-Allow-Origin header reflecting the requesting Origin at the very start of the request handler, before the session authentication check and before the audit ownership check. An unauthenticated attacker can probe this endpoint from any origin and observe the response time: requests for audit IDs that exist in the database are slower (due to the database ownership lookup) than requests for non-existent IDs (which return immediately from an index miss). This timing oracle allows an attacker to enumerate valid audit IDs across all organizations, even without valid credentials.
// CORS31-003 — VULNERABLE
// ACAO reflected before auth/ownership check — timing oracle on audit ID existence.
router.post('/audits/:id/share-link', async (req, res) => {
// VULNERABLE: CORS header emitted before auth check — timing oracle via response time
if (req.headers.origin) {
res.set('Access-Control-Allow-Origin', req.headers.origin);
res.set('Access-Control-Allow-Credentials', 'true');
res.set('Vary', 'Origin');
}
if (!req.session?.userId) return res.status(401).json({ error: 'Unauthorized' });
// DB lookup takes ~5ms if audit exists, ~0.3ms on index miss — measurable timing difference
const audit = await db.audits.findById(req.params.id);
if (!audit || audit.orgId !== req.user.orgId) return res.status(404).json({ error: 'Not found' });
const token = generateShareToken(audit.id);
res.json({ shareUrl: `https://skillaudit.dev/shared/${token}` });
});
Fix: Perform authentication and ownership verification before emitting any CORS headers. Apply a constant-time 404 response for both not-found and not-owned cases to prevent timing-based enumeration. Emit CORS headers only after confirming the request is authorized and the resource belongs to the requesting user's organization.
// CORS31-003 — FIXED
const ALLOWED_ORIGINS = new Set(['https://skillaudit.dev', 'https://app.skillaudit.dev']);
router.post('/audits/:id/share-link', requireSession, async (req, res) => {
// Auth check happens before CORS emission (enforced by requireSession middleware above)
const audit = await db.audits.findByIdAndOrgId(req.params.id, req.user.orgId);
// Constant-time 404 — same response for not-found and not-owned (prevents timing oracle)
if (!audit) return res.status(404).json({ error: 'Not found' });
// Emit CORS headers only after ownership is confirmed
const origin = req.headers.origin;
if (origin && ALLOWED_ORIGINS.has(origin)) {
res.set('Access-Control-Allow-Origin', origin);
res.set('Access-Control-Allow-Credentials', 'true');
res.set('Vary', 'Origin');
}
const token = generateShareToken(audit.id);
res.json({ shareUrl: `https://skillaudit.dev/shared/${token}` });
});
CORS31-004 — Report comparison wildcard CORS leaks findings from both reports
The report comparison endpoint GET /api/audits/compare?a=:id1&b=:id2 returns a structured diff of two audit reports, showing which vulnerabilities appeared, were resolved, or changed severity between the two scans. The endpoint is intended to compare reports within the same organization, but it sets Access-Control-Allow-Origin: * to allow external dashboard integrations. No authentication or ownership check is performed. Any origin can read the full diff of any two audit reports by supplying their IDs, leaking all findings and their remediation status to arbitrary third-party pages.
// CORS31-004 — VULNERABLE
// ACAO:* on compare endpoint with no auth/ownership check — any origin reads report diffs.
router.get('/audits/compare', async (req, res) => {
res.set('Access-Control-Allow-Origin', '*'); // VULNERABLE: wildcard with sensitive report data
const { a, b } = req.query;
const [auditA, auditB] = await Promise.all([db.audits.findById(a), db.audits.findById(b)]);
if (!auditA || !auditB) return res.status(404).json({ error: 'Not found' });
// Returns full diff: new findings, resolved findings, severity changes — from both reports
res.json(diffAudits(auditA, auditB));
});
Fix: Require session authentication on the compare endpoint. Add an ownership check confirming both report IDs belong to the requesting user's organization before returning any diff data. Replace the CORS wildcard with an explicit origin allowlist. If cross-org comparison is a desired feature, generate a time-limited comparison token server-side and serve a public comparison view only for explicitly shared comparison tokens.
// CORS31-004 — FIXED
const ALLOWED_ORIGINS = new Set(['https://skillaudit.dev', 'https://app.skillaudit.dev']);
router.get('/audits/compare', requireSession, async (req, res) => {
const origin = req.headers.origin;
if (origin && ALLOWED_ORIGINS.has(origin)) {
res.set('Access-Control-Allow-Origin', origin);
res.set('Access-Control-Allow-Credentials', 'true');
res.set('Vary', 'Origin');
}
const { a, b } = req.query;
// Ownership check for BOTH reports — both must belong to the authenticated user's org
const [auditA, auditB] = await Promise.all([
db.audits.findByIdAndOrgId(a, req.user.orgId),
db.audits.findByIdAndOrgId(b, req.user.orgId)
]);
if (!auditA || !auditB) return res.status(404).json({ error: 'Not found' });
// Return only grade diff and finding counts — no full finding details in CORS-accessible response
res.json({ gradeA: auditA.grade, gradeB: auditB.grade, diff: summarizeDiff(auditA, auditB) });
});
Summary
| Finding | Pattern | Severity | Fix |
|---|---|---|---|
| CORS31-001 | cors({origin:true,credentials:true}) on private share endpoint | CRITICAL | Explicit origin allowlist; strip private fields from CORS-accessible response |
| CORS31-002 | Badge ACAO:* also serves audit metadata in headers and JSON variant | HIGH | Badge SVG only; remove metadata headers and JSON variant from badge endpoint |
| CORS31-003 | Origin reflected before ownership check — timing oracle on audit IDs | MEDIUM | Auth and ownership check before CORS header emission; constant-time 404 |
| CORS31-004 | Report comparison ACAO:* with no auth/ownership check | HIGH | Explicit allowlist + session auth + ownership check for both reportIds |
Related: SA-SKL-CORS30 (audit webhook replay and delivery confirmation CORS), SA-SKL-CORS29 (API key management and developer credential endpoints CORS). Run SkillAudit to detect all CORS31 patterns in your MCP skill registry.