Claude MCP skill SSRF — package metadata fetch and npm registry proxy — SA-SKL-SSRF23
MCP skill registries that support custom npm registry configurations, README badge rendering, and package dependency resolution perform outbound HTTP requests triggered by user-supplied URLs. Each of these fetch operations is a potential SSRF vector if the URL is not validated against an allowlist or RFC1918/link-local blocklist before the request is made. SA-SKL-SSRF23 covers four SSRF patterns in package metadata and npm proxy operations: custom registry URLs, README badge image fetching, Host-header injection in npm proxies, and attacker-controlled tarball URLs in published package metadata.
http://10.0.0.1:6379 for Redis probe or http://169.254.169.254/latest/meta-data/ for EC2 instance metadata exfiltrationhttp://169.254.169.254/latest/meta-data/iam/security-credentials/; response content cached and potentially served to other usersregistry.npmjs.org using the user-supplied Host header to construct the upstream URL; attacker sets Host: 169.254.169.254; proxy fetches the EC2 metadata endpoint instead of npm registrydist.tarball URL in package.json; attacker publishes a package with a crafted dist.tarball pointing to an internal service; registry fetches it during installation or previewSSRF23-001 — User-supplied npm registry URL fetched without SSRF guard
Some MCP skill registries support custom npm registry configuration — allowing skill authors to point the registry at a private npm instance (Verdaccio, Nexus, Artifactory) for installing private dependencies. The user supplies the registry URL in their skill configuration. When the registry platform fetches package metadata from this URL, it makes an outbound HTTP request to a user-controlled destination. Without an SSRF guard — DNS resolution + RFC1918/link-local/loopback blocklist check — this fetch reaches any internal service: Redis on port 6379, the EC2 metadata endpoint at 169.254.169.254, internal Kubernetes API servers, and development databases that are not publicly reachable.
// SSRF23-001 — VULNERABLE
// Package metadata fetched from user-supplied npm registry URL without SSRF guard.
router.post('/api/skills/:skillId/install', authenticate, async (req, res) => {
const { packageName, registryUrl } = req.body;
// Attacker sends registryUrl: "http://10.0.0.1:6379/npmpackage/name"
// VULNERABLE: direct fetch to user-supplied URL — no SSRF guard
const metaUrl = new URL(`/${packageName}`, registryUrl).toString();
const response = await fetch(metaUrl);
const metadata = await response.json();
res.json({ version: metadata['dist-tags']?.latest });
});
// SSRF23-001 — FIXED
// SSRF guard: DNS resolution + RFC1918/link-local/loopback blocklist.
// HTTPS-only for user-supplied registry URLs.
import dns from 'node:dns/promises';
import { isPrivateIP } from './ssrf-guard.js'; // shared utility
const REGISTRY_ALLOWLIST = /^https:\/\/([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}\//;
async function validateRegistryUrl(rawUrl) {
const url = new URL(rawUrl); // throws on malformed URL
// Fix 1: HTTPS only — prevents cleartext credential interception
if (url.protocol !== 'https:') throw new Error('Registry URL must use HTTPS');
// Fix 2: reject IP literals directly (no DNS needed for these)
if (/^\d{1,3}(\.\d{1,3}){3}$/.test(url.hostname)) {
if (isPrivateIP(url.hostname)) throw new Error('Registry URL resolves to private IP');
}
// Fix 3: DNS resolution check — catches DNS rebinding and hostname aliasing
const addresses = await dns.resolve4(url.hostname);
for (const addr of addresses) {
if (isPrivateIP(addr)) throw new Error(`Registry hostname resolves to private IP: ${addr}`);
}
return url;
}
router.post('/api/skills/:skillId/install', authenticate, async (req, res) => {
const { packageName, registryUrl } = req.body;
const validatedUrl = await validateRegistryUrl(registryUrl);
const metaUrl = new URL(`/${encodeURIComponent(packageName)}`, validatedUrl).toString();
const response = await fetch(metaUrl, { redirect: 'error' }); // no redirect following
const metadata = await response.json();
res.json({ version: metadata['dist-tags']?.latest });
});
Redis responds to HTTP requests and leaks data: Redis's inline command protocol accepts HTTP-formatted input and responds with error messages that include command echoes. A fetch to http://10.0.0.1:6379/ will receive a Redis error response that often includes the last command processed. More targeted attacks send Redis commands in the request path: /KEYS *\r\nGET session:admintoken\r\n. The registry platform then returns the Redis response as a "metadata fetch error" containing the leaked data. For SSRF patterns in webhook URL delivery, see SA-SKL-SSRF22.
SSRF23-002 — README badge image fetched to CDN without SSRF validation
MCP skill registry pages often display README badges — Shields.io-style SVG images that show build status, coverage percentage, and license type. When the registry renders the README server-side (or pre-fetches badge images to its CDN for performance), it makes an outbound HTTP request to each image URL found in the README's Markdown. If badge URLs are not validated before fetching, a skill author can embed an image URL pointing to an internal service. The registry's CDN fetch returns the internal service's response body, which is then cached and potentially visible in CDN cache inspection or error logs.
// SSRF23-002 — VULNERABLE
// README badge images fetched server-side to CDN without SSRF validation.
import { marked } from 'marked';
async function prefetchBadges(readmeMarkdown, skillId) {
const imageUrls = [];
const renderer = new marked.Renderer();
renderer.image = ({ href }) => { imageUrls.push(href); return ''; };
marked.parse(readmeMarkdown, { renderer });
for (const url of imageUrls) {
// VULNERABLE: fetch to attacker-controlled badge URL
// Attacker puts: 
const response = await fetch(url);
const buffer = await response.arrayBuffer();
await cdn.store(`badges/${skillId}/${hashUrl(url)}`, Buffer.from(buffer));
}
}
// SSRF23-002 — FIXED
// Badge URLs validated against SSRF guard before fetch.
// Only known badge domains (shields.io, badgen.net, img.shields.io) are allowed.
const BADGE_DOMAIN_ALLOWLIST = new Set([
'img.shields.io',
'shields.io',
'badgen.net',
'badge.fury.io',
'codecov.io',
'coveralls.io',
]);
async function prefetchBadges(readmeMarkdown, skillId) {
const imageUrls = extractImageUrls(readmeMarkdown);
for (const rawUrl of imageUrls) {
let url;
try { url = new URL(rawUrl); } catch { continue; }
// Fix 1: allowlist-based domain check — only known badge CDNs
if (!BADGE_DOMAIN_ALLOWLIST.has(url.hostname)) {
logger.info({ url: rawUrl }, 'badge: skipped non-allowlisted domain');
continue;
}
// Fix 2: HTTPS only
if (url.protocol !== 'https:') continue;
// Fix 3: even for allowlisted domains, verify DNS resolution is public
// (Shields.io could have an internal alias in a compromised DNS scenario)
await validateNotPrivateIP(url.hostname);
const response = await fetch(url.toString(), {
redirect: 'error',
signal: AbortSignal.timeout(5000), // 5s max per badge
});
if (!response.ok) continue;
const buffer = await response.arrayBuffer();
await cdn.store(`badges/${skillId}/${hashUrl(rawUrl)}`, Buffer.from(buffer));
}
}
SSRF23-003 — npm proxy Host header injection to 169.254.169.254
Some MCP skill registries include a lightweight npm registry proxy — a pass-through that forwards package requests to registry.npmjs.org while adding authentication headers or rate limiting. A common implementation extracts the upstream URL by combining the hardcoded registry base with the request path: const upstream = \`https://${req.headers.host}/\${req.path}\` or const upstream = new URL(req.path, \`https://\${req.headers.host}\`). If the proxy uses the client-supplied Host header to construct the upstream URL, the attacker sets Host: 169.254.169.254 in their npm install command to redirect the proxy fetch to the EC2 metadata endpoint.
// SSRF23-003 — VULNERABLE
// npm proxy uses Host header to construct upstream URL — Host header injection.
app.use('/npm-proxy', authenticate, async (req, res) => {
// VULNERABLE: req.headers.host is attacker-controlled
// Attacker sends: GET /npm-proxy/latest HTTP/1.1\r\nHost: 169.254.169.254\r\n
const upstream = `https://${req.headers.host}${req.path}`;
const response = await fetch(upstream, {
headers: { Authorization: `Bearer ${process.env.NPM_TOKEN}` },
});
const body = await response.text();
res.status(response.status).send(body);
// Response from 169.254.169.254 (EC2 metadata) is returned to attacker
});
// SSRF23-003 — FIXED
// Upstream URL hardcoded — Host header never used to construct upstream target.
const NPM_REGISTRY_BASE = 'https://registry.npmjs.org';
app.use('/npm-proxy', authenticate, async (req, res) => {
// Fix 1: construct upstream URL from HARDCODED base — ignore req.headers.host entirely
const safePath = req.path.replace(/[^a-zA-Z0-9@._~-]/g, ''); // sanitize path
const upstream = `${NPM_REGISTRY_BASE}/${safePath}`;
// Fix 2: validate that constructed URL is still the expected registry
// (paranoia check — in case NPM_REGISTRY_BASE is misconfigured)
const upstreamUrl = new URL(upstream);
if (upstreamUrl.hostname !== 'registry.npmjs.org') {
return res.status(500).json({ error: 'Internal proxy misconfiguration' });
}
const response = await fetch(upstream, {
redirect: 'error', // never follow redirects
headers: {
// Forward only specific safe headers — never forward Host
'Accept': req.headers.accept ?? 'application/json',
'npm-session': req.headers['npm-session'] ?? '',
},
signal: AbortSignal.timeout(10000),
});
res.status(response.status);
const body = await response.arrayBuffer();
res.send(Buffer.from(body));
});
Never forward the Host header to upstream services in a proxy: The Host header is set by the HTTP client and specifies which virtual host the client is addressing — it has no relevance to the upstream target in a server-side proxy. The upstream target is always determined by the server's configuration, never by the client's Host header. This applies equally to fetch-based proxies, http-proxy-middleware, and nginx proxy_pass configurations. Always hardcode the upstream base URL as a server-side constant.
SSRF23-004 — Dependency tarball URL attacker-controlled via published package
When a MCP skill registry resolves dependencies to display a dependency graph or perform security scanning, it may fetch the tarball for each dependency to inspect its contents. The tarball URL is read from the dist.tarball field in the package's package.json as published to the registry. If the registry platform fetches tarball URLs from package metadata without validating them against an SSRF guard, an attacker can publish a package to npm with a crafted dist.tarball value pointing to an internal service URL. When any skill that lists this package as a dependency is scanned, the registry fetches the crafted tarball URL — reaching the internal service.
// SSRF23-004 — VULNERABLE
// Tarball URL from npm package.json trusted without SSRF validation.
async function fetchDependencyTarball(packageName, version) {
const metaUrl = `https://registry.npmjs.org/${packageName}/${version}`;
const meta = await fetch(metaUrl).then(r => r.json());
// VULNERABLE: dist.tarball from published package metadata — attacker-controlled
// Malicious package publishes: { "dist": { "tarball": "http://10.100.0.1:5984/_all_dbs" } }
const tarballUrl = meta.dist.tarball;
const tarball = await fetch(tarballUrl); // Fetches attacker's internal target
return tarball.arrayBuffer();
}
// SSRF23-004 — FIXED
// Tarball URL validated against allowlist of known npm registry origins.
// Also validates that the URL hostname matches the metadata source.
const TARBALL_ORIGIN_ALLOWLIST = new Set([
'registry.npmjs.org',
'registry.yarnpkg.com',
]);
async function fetchDependencyTarball(packageName, version) {
const metaUrl = `https://registry.npmjs.org/${packageName}/${version}`;
const meta = await fetch(metaUrl).then(r => r.json());
const tarballUrl = meta.dist?.tarball;
if (!tarballUrl) throw new Error('Missing dist.tarball in package metadata');
// Fix 1: parse and validate tarball URL
const url = new URL(tarballUrl);
// Fix 2: HTTPS only
if (url.protocol !== 'https:') {
throw new Error(`Unsafe tarball URL protocol: ${url.protocol}`);
}
// Fix 3: hostname allowlist — tarball must come from a known npm registry
if (!TARBALL_ORIGIN_ALLOWLIST.has(url.hostname)) {
throw new Error(`Tarball URL origin not in allowlist: ${url.hostname}`);
}
// Fix 4: DNS resolution check even for allowlisted origins (defense in depth)
await validateNotPrivateIP(url.hostname);
const tarball = await fetch(url.toString(), {
redirect: 'error',
signal: AbortSignal.timeout(30000),
});
return tarball.arrayBuffer();
}
Shared SSRF guard utility: All four SSRF23 patterns share the same underlying fix: validate the URL against an SSRF guard before making the fetch. Create a shared ssrf-guard.ts utility that exports validateUrl(url: string): Promise<URL>. The function: (1) parses the URL and throws on malformed input, (2) rejects non-HTTPS, (3) rejects IP literals in RFC1918/link-local/loopback ranges, (4) resolves DNS and rejects any resolved address in those ranges, (5) sets redirect: 'error' on the resulting fetch. Apply this utility to every server-side fetch whose URL originates from user input, database values written by users, or third-party metadata fields. For SSRF patterns in skill testing sandbox npm install, see SA-SKL-SSRF21.
How SkillAudit detects SA-SKL-SSRF23
SkillAudit's SSRF scanner applies four checks for the SA-SKL-SSRF23 family:
- SSRF23-001: Finds
fetch(oraxios.get(calls where the URL is constructed from a field that derives fromreq.body.registryUrloruser.customRegistrywithout a preceding SSRF guard call; flags CRITICAL. - SSRF23-002: Detects image URL extraction from Markdown processing followed by a fetch call; flags HIGH when no domain allowlist or DNS check precedes the fetch.
- SSRF23-003: Finds proxy-style request handlers where the upstream URL is constructed using
req.headers.hostorreq.hostname; flags HIGH. - SSRF23-004: Finds
meta.dist.tarballor similar metadata-field URL reads followed by a fetch call without an origin allowlist check; flags HIGH.
| Pattern | Root cause | Fix | Severity |
|---|---|---|---|
| SSRF23-001 | User-supplied npm registry URL fetched without SSRF guard — probes internal services | SSRF guard: HTTPS-only + DNS resolution + RFC1918 blocklist at both config save and fetch time | CRITICAL |
| SSRF23-002 | README badge image URL fetched to CDN without SSRF validation — EC2 metadata probe | Domain allowlist for known badge CDNs; SSRF guard on all CDN prefetch operations | HIGH |
| SSRF23-003 | npm proxy constructs upstream URL from Host header — Host header injection to 169.254.169.254 | Hardcode upstream URL as server-side constant; never use Host header for upstream routing | HIGH |
| SSRF23-004 | Dependency tarball URL read from published package.json — attacker controls dist.tarball | Tarball origin allowlist (registry.npmjs.org); SSRF guard even for allowlisted origins | HIGH |