Claude MCP skill SSRF via skill preview rendering and documentation fetching — SA-SKL-SSRF20
Skill registries that auto-fetch README files, generate OpenGraph previews, cache package icons, and provide webhook testing endpoints all require server-side HTTP fetches to attacker-controlled URLs. SA-SKL-SSRF20 covers four SSRF patterns that arise in preview rendering and documentation pipelines: redirect-following from GitHub to internal metadata endpoints, OpenGraph fetching to link-local addresses, icon caching to internal service APIs, and webhook test endpoints that probe internal infrastructure.
169.254.169.254 IAM credentials endpointogUrl from manifest — attacker manifest points to EC2 metadata; response body reflected in skill listing pagelocalhost:6379 Redis admin HTTP interfaceSSRF20-001 — README URL redirect to internal metadata endpoint
When a skill is submitted via GitHub URL, many registries fetch the README directly from raw.githubusercontent.com for rendering in the skill listing. The vulnerability arises when the fetch is performed with redirect-following enabled: the attacker submits a GitHub repository whose README URL redirects to an internal endpoint. Even if the registry validates the initial URL as a GitHub domain, the redirect target is not validated. On cloud infrastructure, the most dangerous redirect target is the IMDS metadata endpoint at 169.254.169.254, which returns IAM credentials in the response body.
// VULNERABLE — SSRF20-001
// fetch() with default redirect:'follow' — redirects to any URL including internal ones
async function fetchSkillReadme(githubRawUrl) {
// Validates the starting URL is GitHub — but follows redirects without re-validating
const url = new URL(githubRawUrl);
if (!['github.com', 'raw.githubusercontent.com'].includes(url.hostname)) {
throw new Error('URL must be a GitHub URL');
}
// VULNERABLE: redirect:'follow' (default) means attacker can serve a 302 to
// http://169.254.169.254/latest/meta-data/iam/security-credentials/app-role
const response = await fetch(githubRawUrl);
return response.text();
}
// FIXED — SSRF20-001
// Use redirect:'error' to reject any redirects.
// Attacker cannot redirect the registry server to internal endpoints.
async function fetchSkillReadme(githubRawUrl) {
const url = new URL(githubRawUrl);
if (!['github.com', 'raw.githubusercontent.com'].includes(url.hostname)) {
throw new Error('URL must be a GitHub URL');
}
// FIX: redirect:'error' causes fetch() to throw on any 3xx response
const response = await fetch(githubRawUrl, { redirect: 'error' });
if (!response.ok) throw new Error('Failed to fetch README');
const text = await response.text();
if (text.length > 500_000) throw new Error('README too large');
return text;
}
SSRF20-002 — OpenGraph preview fetch to link-local metadata address
MCP skill registries often generate rich link previews using Open Graph tags. If the registry fetches the og:url value from a skill's manifest or package.json homepage field without IP validation, an attacker can set ogUrl to http://169.254.169.254/latest/meta-data/iam/security-credentials/app-role. The registry worker fetches this URL server-side, the response body (containing IAM access key, secret, and session token) is returned, and if any part of the response is included in the generated skill preview page, the attacker can read it in the browser.
// VULNERABLE — SSRF20-002
// OpenGraph preview generation fetches ogUrl without DNS/IP validation
const cheerio = require('cheerio');
async function generateSkillPreview(manifest) {
const ogUrl = manifest.homepage; // attacker controls this field
// VULNERABLE: no IP address check — ogUrl may point to 169.254.169.254
const response = await fetch(ogUrl, { redirect: 'follow' });
const html = await response.text();
const $ = cheerio.load(html);
return {
title: $('meta[property="og:title"]').attr('content') || manifest.name,
description: $('meta[property="og:description"]').attr('content') || '',
image: $('meta[property="og:image"]').attr('content') || null,
};
}
// FIXED — SSRF20-002
// Resolve DNS before fetching; reject RFC1918, link-local, and loopback addresses.
const dns = require('dns/promises');
const net = require('net');
const BLOCKED_RANGES = [
/^10\./,
/^192\.168\./,
/^172\.(1[6-9]|2\d|3[01])\./,
/^127\./,
/^169\.254\./, // link-local (IMDS)
/^::1$/,
/^fc00:/,
];
async function isSafeUrl(urlString) {
const url = new URL(urlString);
if (!['http:', 'https:'].includes(url.protocol)) return false;
const addresses = await dns.resolve4(url.hostname).catch(() => []);
if (addresses.length === 0) return false;
return !addresses.some(ip => BLOCKED_RANGES.some(re => re.test(ip)));
}
async function generateSkillPreview(manifest) {
if (!manifest.homepage) return { title: manifest.name, description: '', image: null };
if (!(await isSafeUrl(manifest.homepage))) {
return { title: manifest.name, description: '', image: null };
}
// FIX: validated URL with redirect:'error' — SSRF mitigated
const response = await fetch(manifest.homepage, { redirect: 'error' });
const html = await response.text();
const $ = cheerio.load(html);
return {
title: $('meta[property="og:title"]').attr('content') || manifest.name,
description: $('meta[property="og:description"]').attr('content') || '',
image: null, // never serve attacker-controlled image URLs in preview
};
}
SSRF20-003 — Skill package icon URL fetched to CDN cache
When a skill package declares an icon in its manifest, the registry may fetch and cache the icon locally to serve it from its own CDN rather than hot-linking to external URLs. If the icon URL is not validated against an IP blocklist before the fetch, the registry worker makes an HTTP request to whatever URL the attacker specified. Many internal services expose HTTP admin interfaces on non-standard ports: Redis at :6379 (HTTP-parseable RESP protocol), Elasticsearch at :9200, internal dashboards at :8080. The attacker's icon URL targets one of these, and the binary response is stored as the skill's cached icon — but the more dangerous outcome is that the attacker can observe the HTTP status code and response time to map the internal network.
// VULNERABLE — SSRF20-003
// Icon URL fetched without IP validation — targets internal services
async function cacheSkillIcon(skillId, iconUrl) {
// VULNERABLE: no DNS/IP check — attacker sets iconUrl to http://10.0.0.5:6379/
const response = await fetch(iconUrl, { redirect: 'follow' });
const buffer = Buffer.from(await response.arrayBuffer());
await s3.putObject({ Key: `icons/${skillId}`, Body: buffer, ContentType: 'image/png' });
}
// FIXED — SSRF20-003
// Allowlist-based approach: only fetch icons from known CDN hostnames.
// DNS/IP check as secondary defence.
const ALLOWED_ICON_HOSTNAMES = new Set([
'cdn.jsdelivr.net',
'raw.githubusercontent.com',
'avatars.githubusercontent.com',
'unpkg.com',
]);
async function cacheSkillIcon(skillId, iconUrl) {
const url = new URL(iconUrl);
// FIX 1: allowlist of known CDN hostnames
if (!ALLOWED_ICON_HOSTNAMES.has(url.hostname)) {
throw new Error('Icon URL must be from an approved CDN');
}
// FIX 2: DNS/IP check as defence-in-depth (CDN might CNAME to internal)
if (!(await isSafeUrl(iconUrl))) {
throw new Error('Icon URL resolves to a blocked IP range');
}
const response = await fetch(iconUrl, { redirect: 'error' });
// FIX 3: validate content-type is an image before caching
const ct = response.headers.get('content-type') || '';
if (!ct.startsWith('image/')) throw new Error('Icon URL did not return an image');
const buffer = Buffer.from(await response.arrayBuffer());
if (buffer.length > 2_097_152) throw new Error('Icon exceeds 2 MB limit');
await s3.putObject({ Key: `icons/${skillId}`, Body: buffer, ContentType: ct.split(';')[0] });
}
SSRF20-004 — Webhook test endpoint probes internal infrastructure
Developer portals often include a "Test Webhook" button that lets a developer verify that their skill's webhook URL is reachable. The endpoint sends a test POST to the developer-supplied URL. Even if the URL was validated at registration time, the validation may check only format (must be https://) rather than the resolved IP address — and DNS can be changed between registration and the test trigger. More commonly, the IP check is simply absent entirely, leaving the test endpoint as an open SSRF probe.
// VULNERABLE — SSRF20-004
// Webhook test endpoint sends POST to developer-supplied URL with no IP check
app.post('/api/webhooks/:id/test', requireAuth, async (req, res) => {
const webhook = await db.webhooks.findById(req.params.id, req.user.orgId);
if (!webhook) return res.status(404).json({ error: 'not found' });
// VULNERABLE: no SSRF check — attacker sets endpointUrl to internal service
// e.g. http://10.0.0.1:2379/v3/kv/range (etcd)
const response = await fetch(webhook.endpointUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ event: 'test', skillId: webhook.skillId }),
});
res.json({ status: response.status, ok: response.ok });
});
// FIXED — SSRF20-004
// DNS/IP check at test time — not just at registration time.
// Redirect disabled; response body not reflected in test result.
app.post('/api/webhooks/:id/test', requireAuth, async (req, res) => {
const webhook = await db.webhooks.findById(req.params.id, req.user.orgId);
if (!webhook) return res.status(404).json({ error: 'not found' });
// FIX 1: validate at trigger time (DNS can change since registration)
if (!(await isSafeUrl(webhook.endpointUrl))) {
return res.status(400).json({ error: 'webhook URL resolves to a blocked address' });
}
let statusCode;
try {
const response = await fetch(webhook.endpointUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ event: 'test', skillId: webhook.skillId }),
// FIX 2: no redirects — attacker cannot redirect to internal URL
redirect: 'error',
signal: AbortSignal.timeout(5000),
});
statusCode = response.status;
} catch {
return res.json({ ok: false, status: null, message: 'unreachable' });
}
// FIX 3: return only the status code — do not reflect response body
res.json({ ok: statusCode >= 200 && statusCode < 300, status: statusCode });
});
DNS rebinding defeats registration-time checks: Even if you validate the IP address when the webhook URL is first registered, an attacker who controls their domain can change the DNS record after validation to point to an internal address. The TTL-0 DNS rebinding technique exploits this directly. Always re-validate the resolved IP at request time, not just at registration time, and set a minimum TTL floor in your DNS resolver cache (many HTTP client libraries respect CURLOPT_DNS_CACHE_TIMEOUT). Check both at registration and at each trigger.
Summary — SA-SKL-SSRF20 at a glance
| Pattern | Root cause | Fix | Severity |
|---|---|---|---|
| SSRF20-001 | README fetch follows redirects from allowlisted GitHub hostname to internal metadata | redirect:'error'; validate only the final URL | CRITICAL |
| SSRF20-002 | OG preview fetch to attacker-controlled homepage URL without DNS/IP check | DNS resolution + RFC1918/link-local blocklist before any fetch | CRITICAL |
| SSRF20-003 | Icon URL fetched to cache without CDN hostname allowlist or IP validation | Allowlist of CDN hostnames + content-type validation + size limit | HIGH |
| SSRF20-004 | Webhook test sends POST to developer URL without SSRF check at trigger time | DNS/IP check at trigger time; no-redirect; response body not reflected | CRITICAL |
See also SA-SKL-SSRF19 (health check and monitoring SSRF) and SA-SKL-SSRF18 (manifest import and webhook SSRF) for related server-side request forgery patterns in MCP skill registries.