Claude MCP skill SSRF — npm package dependency resolution and lockfile fetch endpoints

SA-SKL-SSRF38 documents four SSRF vulnerabilities in MCP skill registry npm package dependency resolution and lockfile fetch endpoints. User-supplied registry URLs, tarball locations, peer registry endpoints, and provenance attestation URLs are all fetched server-side without validation, enabling attackers to pivot the registry worker into the cloud metadata service, internal object storage, service discovery infrastructure, and time-series databases.

Critical SSRF38-001 — Package resolution endpoint fetches user-supplied npmRegistryUrl; attacker sets to 169.254.169.254; IAM credentials in metadata response logged and stored as dependency metadata and displayed to all registry users
Critical SSRF38-002 — Lockfile integrity check fetches tarball from user-supplied tarballUrl; attacker sets to internal S3-compatible storage; arbitrary bucket read returns stored API keys as tarball bytes
High SSRF38-003 — Peer dependency resolution fetches user-supplied peerRegistryUrl with redirect:follow; attacker controls CNAME to internal Consul; Consul /v1/agent/members response stored as peer dep metadata
High SSRF38-004 — Package provenance verification pings user-supplied provenanceUrl; attacker sets to internal InfluxDB HTTP API; InfluxDB response body stored as provenance attestation and returned to any registry viewer

SSRF38-001 — Custom npmRegistryUrl reaches IMDS for IAM credentials

The package resolution endpoint accepts a npmRegistryUrl parameter to support private or mirror npm registries. Without a hostname allowlist, an attacker sets it to http://169.254.169.254/latest/meta-data/iam/security-credentials/. The registry worker fetches the IMDS endpoint, receives the IAM role credentials JSON, and — because the error handler logs the full response body for debugging — stores the credential payload as the “registry response” in the dependency metadata record visible to all users of the registry.

Vulnerable
// SSRF38-001 — VULNERABLE
router.post('/packages/resolve', requireSession, async (req, res) => {
  const { packageName, version, npmRegistryUrl } = req.body;
  // No URL validation — attacker sets npmRegistryUrl to 169.254.169.254
  const response = await fetch(`${npmRegistryUrl}/${packageName}/${version}`);
  const meta = await response.json(); // IMDS JSON parsed as "package metadata"
  await db.dependencies.upsert({ packageName, version, meta }); // stored and displayed
  res.json(meta);
});

IMDS v2 is not a full mitigation: IMDSv2 requires a PUT request to get a session token before accessing credentials. However, some EC2 instances still have IMDSv1 enabled, and an SSRF that can follow redirects or make PUT requests (from a curl-based fetch library) can still reach IMDSv2. The correct fix is a hostname allowlist that blocks all RFC 1918, link-local (169.254.0.0/16), and loopback addresses at the DNS resolution level.

Fixed
// SSRF38-001 — FIXED
const { Resolver } = require('dns').promises;
const resolver = new Resolver();

const NPM_REGISTRY_ALLOWLIST = new Set([
  'registry.npmjs.org',
  'registry.yarnpkg.com',
  'npm.pkg.github.com',
]);

const PRIVATE_RANGES = [
  /^10\./,/^172\.(1[6-9]|2\d|3[01])\./,/^192\.168\./,
  /^127\./,/^169\.254\./,/^::1$/,/^fc00:/,/^fd/,
];

async function safeNpmFetch(registryUrl, packageName, version) {
  const url = new URL(`/${packageName}/${version}`, registryUrl);
  if (!NPM_REGISTRY_ALLOWLIST.has(url.hostname)) {
    throw new Error(`Registry hostname not in allowlist: ${url.hostname}`);
  }
  // Also validate resolved IPs to block DNS rebinding
  const addrs = await resolver.resolve4(url.hostname);
  for (const addr of addrs) {
    if (PRIVATE_RANGES.some(r => r.test(addr))) throw new Error('Registry resolves to private IP');
  }
  const response = await fetch(url.toString(), { redirect: 'error' });
  const { name, version: ver, description, dist } = await response.json();
  return { name, version: ver, description, dist }; // return parsed fields only
}

SSRF38-002 — Tarball URL to internal S3 returns stored API keys

The lockfile integrity check accepts a tarballUrl from the submitted lockfile to fetch and hash the package tarball for integrity verification. An attacker submits a lockfile with tarballUrl: "http://internal-s3.example.com/secure-bucket/api-keys.json". The registry worker fetches the internal S3 URL (which requires no auth from inside the VPC), reads the response body (which contains stored API keys), and — since the hash computation fails because the content is JSON rather than a tarball — stores the raw response body in the error log alongside the tarball URL, exposing the keys.

Vulnerable
// SSRF38-002 — VULNERABLE
async function checkLockfileIntegrity(tarballUrl, expectedSha512) {
  // No URL validation — attacker sets tarballUrl to internal S3 object URL
  const response = await fetch(tarballUrl);
  const buffer = await response.arrayBuffer();
  const actual = crypto.createHash('sha512').update(Buffer.from(buffer)).digest('hex');
  if (actual !== expectedSha512) {
    // Logs response body on mismatch — API keys exposed to log aggregator
    console.error('Integrity mismatch', { tarballUrl, body: buffer.toString() });
    return false;
  }
  return true;
}
Fixed
// SSRF38-002 — FIXED
// Allowlist of npm CDN hostnames; validate Content-Type: application/octet-stream;
// compute hash only, discard bytes; never log response bodies.

const TARBALL_HOSTNAME_ALLOWLIST = new Set([
  'registry.npmjs.org',
  'registry.yarnpkg.com',
  'github.com',  // github releases
]);

async function checkLockfileIntegrity(tarballUrl, expectedSha512) {
  const url = new URL(tarballUrl);
  if (!TARBALL_HOSTNAME_ALLOWLIST.has(url.hostname)) {
    throw new Error(`Tarball hostname not allowed: ${url.hostname}`);
  }
  const response = await fetch(url.toString(), { redirect: 'error' });
  const ct = response.headers.get('content-type') || '';
  if (!ct.includes('application/octet-stream') && !ct.includes('application/gzip')) {
    throw new Error(`Unexpected Content-Type for tarball: ${ct}`);
  }
  const buffer = await response.arrayBuffer();
  const actual = crypto.createHash('sha512').update(Buffer.from(buffer)).digest('hex');
  // Compare hash only — never return or log response bytes
  return actual === expectedSha512;
}

SSRF38-003 — Peer registry redirect follows CNAME to internal Consul

Peer dependency resolution accepts a peerRegistryUrl and uses fetch(url, {redirect: 'follow'}). An attacker registers a domain with a CNAME pointing to consul.internal. The redirect:follow option means the fetch library follows the DNS-level redirect to Consul, and the registry worker stores the Consul cluster member list as “peer dependency metadata.”

Vulnerable
// SSRF38-003 — VULNERABLE
async function resolvePeerDep(peerRegistryUrl, peerName, version) {
  const response = await fetch(
    `${peerRegistryUrl}/${peerName}/${version}`,
    { redirect: 'follow' }  // VULNERABLE: follows CNAME to internal Consul
  );
  return response.json(); // Consul /v1/agent/members stored as peer dep metadata
}
Fixed
// SSRF38-003 — FIXED
// redirect:error prevents redirect chains; hostname allowlist blocks private ranges;
// Zod schema extracts only name/version fields from the response.
const { z } = require('zod');
const PeerDepSchema = z.object({
  name: z.string().max(214),
  version: z.string().max(50),
});

async function resolvePeerDep(peerRegistryUrl, peerName, version) {
  const url = new URL(`/${peerName}/${version}`, peerRegistryUrl);
  if (!NPM_REGISTRY_ALLOWLIST.has(url.hostname)) throw new Error('Peer registry not allowed');
  const response = await fetch(url.toString(), { redirect: 'error' }); // no redirect following
  return PeerDepSchema.parse(await response.json()); // only name/version extracted
}

SSRF38-004 — Provenance URL reaches internal InfluxDB

Package provenance verification fetches a user-supplied provenanceUrl to retrieve a Sigstore-signed DSSE envelope. Without an allowlist, an attacker sets it to http://influxdb.internal:8086/query?q=SELECT+*+FROM+metrics. The registry worker fetches the InfluxDB query endpoint, stores the time-series data as the “provenance attestation,” and returns it to any user viewing the package provenance page.

Vulnerable
// SSRF38-004 — VULNERABLE
async function verifyProvenance(provenanceUrl, packageName, version) {
  const response = await fetch(provenanceUrl); // no validation — reaches internal InfluxDB
  const attestation = await response.json();   // InfluxDB metrics stored as provenance
  return { verified: true, attestation };       // returned to all viewers
}
Fixed
// SSRF38-004 — FIXED
const PROVENANCE_ALLOWLIST = new Set([
  'rekor.sigstore.dev',
  'witness.dev',
  'fulcio.sigstore.dev',
]);
const DSSEEnvelopeSchema = z.object({
  payloadType: z.literal('application/vnd.in-toto+json'),
  payload: z.string().base64(),
  signatures: z.array(z.object({ sig: z.string(), keyid: z.string().optional() })),
});

async function verifyProvenance(provenanceUrl) {
  const url = new URL(provenanceUrl);
  if (!PROVENANCE_ALLOWLIST.has(url.hostname)) throw new Error('Provenance URL not allowed');
  const response = await fetch(url.toString(), { redirect: 'error' });
  return DSSEEnvelopeSchema.parse(await response.json()); // only DSSE fields extracted
}

Related advisories: For SSRF in npm registry proxy and package metadata fetch endpoints, see SA-SKL-SSRF36. For code injection in code coverage and test runner invocation endpoints, see SA-SKL-INJECTION26.

Scan your MCP server or Claude skill

SkillAudit checks for SSRF38, CORS, injection, deserialization, and 50+ more vulnerability patterns — in 60 seconds.

Get early access