← Security advisories

Claude MCP skill CORS misconfiguration — skill API key and token management endpoints — SA-SKL-CORS58

SA-SKL-CORS58 documents four CORS misconfiguration patterns in MCP skill registry skill API key and token management endpoints. API key management endpoints hold the credentials that authenticate CI pipelines, webhook consumers, and third-party integrations — not session tokens that expire on logout, but durable keys that survive account password changes and remain valid until explicitly revoked. A CORS misconfiguration here exposes complete key values and their scope metadata to any origin using the victim's session, allows creation of attacker-controlled keys under victim admin identity, enables identification of skills with active CI integrations via a usage-velocity timing oracle, and permits silent revocation of all keys for a skill, breaking every automated integration that authenticates with those keys.

SA-SKL-CORS58 findings at a glance
CRITICALCORS58-001 — cors({origin:true,credentials:true}) on GET /api/skills/:id/api-keys; any origin reads full API key list including key values, scopes, expiry dates, and last-used metadata using victim admin session; API keys are durable credentials authenticating CI pipelines, webhooks, and third-party integrations; fix: allowlist; requireSession + requireRole('admin'); return only key metadata (name, created, lastUsed, scopes) — never return key values after creation
CRITICALCORS58-002 — ACAO: * on POST /api/skills/:id/api-keys; any page creates attacker-controlled API keys under victim admin identity with attacker-specified scopes; created keys are immediately usable to authenticate as the skill owner to external integrations; fix: remove wildcard; require session; requireRole('admin'); CSRF token; Zod ApiKeySchema; audit log; rate-limit per userId+skillId
MEDIUMCORS58-003 — ACAO origin reflection on GET /api/skills/:id/api-keys/usage emitted before ownership check; timing oracle reveals API key usage velocity tiers identifying skills with active CI integrations as CORS58-001 targets for key exfiltration during active pipeline runs; fix: auth before CORS emission; unified WHERE clause; normalize 403/404 latency
CRITICALCORS58-004 — cors({origin:true,credentials:true}) on DELETE /api/skills/:id/api-keys/:keyId; any origin revokes any API key using victim admin session, breaking all CI pipelines and third-party integrations that authenticate with that key without notifying the key owner; fix: allowlist + requireSession + ownership check + notification to affected integration + audit log on key revocation events

CORS58-001 — Credential-bearing CORS on API key list exposes complete key values and scope metadata

Severity: CRITICAL

The GET /api/skills/:id/api-keys endpoint is configured with cors({origin:true,credentials:true}) applied at the router level. Any origin can read the full API key list document using the victim's browser session. The document includes the full key string values — not just key name or truncated suffix — along with the complete scope array for each key, expiry dates, and last-used timestamps. API keys are stored unhashed in the registry database to allow retrieval for display in the management UI, meaning the GET response contains the actual authenticable credential string.

API keys that authenticate CI pipelines are especially high value because they carry the CI runner's full permission scope — typically publish, deploy, and version-management permissions that allow the key holder to modify the skill's production behavior. An attacker who reads these key values via CORS58-001 gains the ability to authenticate as the skill owner to any external integration that accepts API key authentication, without requiring the victim's session to remain active after the exfiltration event.

API keys should never be returned in list responses. The key value must be transmitted once — in the creation response body — and stored as a hash on the server. If the GET /api-keys endpoint is returning full key strings, the keys are either stored unhashed or are being decrypted for retrieval — both represent a separate architectural vulnerability that CORS58-001 makes trivially exploitable.

Vulnerable
// GET /api/skills/:id/api-keys — cors({origin:true,credentials:true}) at router level
router.use(cors({ origin: true, credentials: true }));

router.get('/:id/api-keys', requireSession, async (req, res) => {
  const keys = await ApiKey.find({ skillId: req.params.id })
    .select('+keyValue +scopes +expiresAt +lastUsedAt');  // exposes full credentials
  return res.json(keys);
});
Fixed
// GET /api/skills/:id/api-keys — per-route allowlist CORS + metadata-only response
const ALLOWED = process.env.ALLOWED_ORIGINS.split(',');
const keyCors = cors({ origin: ALLOWED, credentials: true });

router.get('/:id/api-keys', keyCors, requireSession, requireRole('admin'), async (req, res) => {
  const keys = await ApiKey.find({ skillId: req.params.id })
    .select('name scopes expiresAt lastUsedAt createdAt prefix -keyValue');
  return res.json(keys);
});

CORS58-002 — Wildcard ACAO on key creation enables attacker-controlled key issuance under victim admin identity

Severity: CRITICAL

The API key creation endpoint returns Access-Control-Allow-Origin: *. Any web page can submit a key creation request using the victim admin's browser session, controlling the key name, scope array, and expiry date. The created key is immediately usable to authenticate as the skill owner to any external service that accepts the registry's API key authentication scheme.

Unlike session-based attacks, the attacker does not need the victim's session to remain active after the creation event. Once the key is created, the attacker possesses a durable credential that authenticates independently. The key appears in the audit log as created by the victim admin, and nothing in the key's metadata distinguishes it from a legitimately created key.

Vulnerable
// POST /api/skills/:id/api-keys — ACAO:* from upstream cors() middleware
router.post('/:id/api-keys', requireSession, async (req, res) => {
  const { name, scopes, expiresAt } = req.body;
  const rawKey = crypto.randomBytes(32).toString('hex');
  const key = await ApiKey.create({
    skillId:  req.params.id,
    createdBy: req.session.userId,
    name,
    scopes,       // attacker-controlled
    expiresAt,    // attacker-controlled
    keyValue: rawKey,
  });
  return res.status(201).json({ id: key.id, keyValue: rawKey });
});
Fixed
// POST /api/skills/:id/api-keys — allowlist CORS + requireRole + CSRF + Zod + rate limit
import { z } from 'zod';

const ApiKeySchema = z.object({
  name: z.string().min(1).max(100),
  scopes: z.array(z.enum(['read', 'publish', 'deploy', 'webhook'])).min(1).max(4),
  expiresAt: z.string().datetime().optional(),
});

router.post(
  '/:id/api-keys',
  keyCors,
  requireSession,
  requireRole('admin'),
  verifyCsrf,
  rateLimit({
    windowMs: 300_000,
    max: 5,
    keyGenerator: r => `apikey:${r.session.userId}:${r.params.id}`,
    message: { error: 'API key creation rate limit exceeded' },
  }),
  async (req, res) => {
    const parsed = ApiKeySchema.safeParse(req.body);
    if (!parsed.success) return res.status(400).json({ error: 'Invalid key payload' });

    const rawKey = `ska_${crypto.randomBytes(32).toString('hex')}`;
    const key = await ApiKey.create({
      skillId:   req.params.id,
      createdBy: req.session.userId,
      name:      parsed.data.name,
      scopes:    parsed.data.scopes,
      expiresAt: parsed.data.expiresAt ?? null,
      keyHash:   await bcrypt.hash(rawKey, 10),
    });

    await AuditLog.create({
      action: 'apikey.created', actorId: req.session.userId,
      keyId: key.id, skillId: req.params.id, scopes: parsed.data.scopes,
      origin: req.headers.origin, at: new Date(),
    });

    // keyValue returned ONLY here — never in subsequent GET responses
    return res.status(201).json({ id: key.id, keyValue: rawKey });
  }
);

CORS58-003 — Timing oracle on key usage endpoint reveals active CI-integrated skills

Severity: MEDIUM

The API key usage endpoint reflects the Origin header before the ownership check executes. This creates a timing oracle: skills with active CI integrations generate frequent key usage events that are cached in an in-memory LRU store (sub-5 ms response), while skills without active CI have no cached usage data (20–50 ms full query). An attacker iterates skill IDs and measures preflight-to-response RTT, identifying which skills have active CI integrations. These are the highest-value CORS58-001 targets because active CI integrations indicate that the skill's API keys are being used frequently and that any pipeline using those keys will break immediately if the keys are revoked via CORS58-004.

Vulnerable
// GET /api/skills/:id/api-keys/usage — Origin reflected before auth
router.get('/:id/api-keys/usage', async (req, res) => {
  res.setHeader('Access-Control-Allow-Origin', req.headers.origin || '*');
  res.setHeader('Access-Control-Allow-Credentials', 'true');

  const skill = await Skill.findById(req.params.id);
  if (!skill || skill.ownerId !== req.session?.userId) {
    return res.status(403).json({ error: 'Forbidden' });
  }
  const usage = usageCache.get(req.params.id) || await computeUsage(req.params.id);
  return res.json(usage);
});
Fixed
// GET /api/skills/:id/api-keys/usage — auth before CORS + constant-time floor
router.get('/:id/api-keys/usage', requireSession, async (req, res) => {
  const start = Date.now();
  const skill = await Skill.findOne({ _id: req.params.id, ownerId: req.session.userId });
  if (!skill) {
    await sleep(60 - (Date.now() - start));
    return res.status(404).json({ error: 'Not found' });
  }
  keyCors(req, res, async () => {
    const usage = usageCache.get(req.params.id) || await computeUsage(req.params.id);
    await sleep(Math.max(0, 60 - (Date.now() - start)));
    return res.json(usage);
  });
});

CORS58-004 — Credential-bearing CORS on key deletion breaks all CI pipelines and integrations without notification

Severity: CRITICAL

The API key deletion endpoint shares the router-level cors({origin:true,credentials:true}) policy. Any web page can issue a credentialed DELETE request using the victim admin's browser session. The endpoint performs no ownership check and writes no audit log. When a CI pipeline's authentication key is revoked, the pipeline fails at next execution with an authentication error. The integration owner receives no notification — they discover the revocation only when their pipeline fails and they manually investigate the cause.

Vulnerable
// DELETE /api/skills/:id/api-keys/:keyId
// No ownership check, no audit log, no notification
router.delete('/:id/api-keys/:keyId', requireSession, async (req, res) => {
  await ApiKey.deleteOne({ _id: req.params.keyId });
  return res.status(204).end();
});
Fixed
// DELETE /api/skills/:id/api-keys/:keyId
// Allowlist CORS + ownership check + audit log + integration notification
router.delete('/:id/api-keys/:keyId', keyCors, requireSession, async (req, res) => {
  const key = await ApiKey.findOne({ _id: req.params.keyId, skillId: req.params.id });
  if (!key) return res.status(404).json({ error: 'Key not found' });

  const isOwner = String(key.createdBy) === req.session.userId;
  const isAdmin = req.session.role === 'admin';
  if (!isOwner && !isAdmin) return res.status(403).json({ error: 'Forbidden' });

  await key.deleteOne();

  await AuditLog.create({
    action: 'apikey.deleted', actorId: req.session.userId,
    keyId: req.params.keyId, skillId: req.params.id,
    origin: req.headers.origin, at: new Date(),
  });

  if (!isOwner) {
    await notify(key.createdBy, {
      type: 'apikey.revoked', keyId: req.params.keyId,
      skillId: req.params.id, by: req.session.userId,
    });
  }

  return res.status(204).end();
});

These four CORS vulnerabilities compose into a chain: the timing oracle (CORS58-003) identifies active CI-integrated skills; CORS58-001 exfiltrates the actual API key values for those skills; CORS58-002 creates backdoor keys for attacker-controlled external identities; CORS58-004 revokes the legitimate CI keys to break existing pipelines. SkillAudit's CORS rule pack detects all four patterns with AST-level queries targeting router-level cors() application, Origin reflection before auth, and DELETE key handlers without audit log writes. See also the related SA-SKL-CORS57 advisory on permission and access control management endpoints for the companion chain targeting access grants rather than API credentials.