Claude MCP skill SSRF — skill preview and documentation rendering pipeline
previewUrl for OG thumbnail generation — attacker sets to 169.254.169.254; IAM credentials in thumbnail generation error log surfaced in audit reportdocsUrl for inline preview — attacker sets to internal Confluence Wiki; Confluence REST API JSON parsed as documentation HTML and stored in public skill listing--disable-web-security and args: ['--allow-file-access-from-files'] — attacker sets to gopher://redis:6379/ sending arbitrary Redis commands via Puppeteer protocol handlersSSRF31-001 — Preview URL OG thumbnail generation leaks IMDSv1 credentials
When a skill author submits a skill to the registry, they can supply a previewUrl field for the OG social thumbnail. The thumbnail generation worker fetches this URL server-side using node-fetch without any SSRF guard. The response body and any error details are logged to the worker's structured log, which is later aggregated into the audit report for the skill. An attacker who submits a skill with previewUrl: "http://169.254.169.254/latest/meta-data/iam/security-credentials/worker-role" causes the worker to fetch the IMDSv1 endpoint, which returns the worker instance's IAM access key, secret key, and session token. These credentials appear in the error log entry when the fetched content cannot be parsed as an image, and the error log is included verbatim in the audit report surfaced to the attacker.
// SSRF31-001 — VULNERABLE
// No SSRF guard on previewUrl fetch — attacker targets 169.254.169.254 (IMDSv1)
// Error response body logged verbatim — IAM credentials appear in audit report
const fetch = require('node-fetch');
async function generateSkillThumbnail(skill) {
let imageBuffer;
try {
// No URL validation — attacker sets previewUrl to http://169.254.169.254/...
const response = await fetch(skill.previewUrl, { timeout: 5000 });
imageBuffer = await response.buffer();
} catch (err) {
// Error body logged — may contain IAM credential JSON from IMDS response
logger.error('thumbnail_fetch_failed', {
skillId: skill.id,
url: skill.previewUrl,
error: err.message,
responseBody: err.responseBody, // IAM credentials end up here
});
return null;
}
return resizeImage(imageBuffer);
}
IMDSv1 is accessible from any process on EC2 without authentication: The Instance Metadata Service v1 endpoint at 169.254.169.254 responds to any HTTP GET from within the instance — no authentication required. Any server-side URL fetch without an SSRF guard can retrieve IAM role credentials. The fix requires two layers: (1) an allowlist that rejects private and link-local IP ranges before the DNS resolution step, and (2) a DNS-resolution step that re-checks the resolved IP against the same private IP blocklist to prevent DNS rebinding. Additionally, never log response bodies from user-supplied URL fetches, even in error paths.
// SSRF31-001 — FIXED
// SSRF guard: allowlist https-only public hostnames + DNS private IP block
// 2MB response size limit + content-type must be image/*
// Never log response body from user-supplied URLs
const dns = require('dns').promises;
const ipRangeCheck = require('ip-range-check');
const PRIVATE_IP_RANGES = [
'10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16',
'169.254.0.0/16', // link-local (IMDS)
'127.0.0.0/8', '::1/128', 'fc00::/7',
];
async function validatePublicUrl(urlStr) {
let parsed;
try { parsed = new URL(urlStr); } catch { throw new Error('invalid URL'); }
if (parsed.protocol !== 'https:') throw new Error('https only');
// Resolve hostname and check resolved IPs against private ranges
const addresses = await dns.resolve4(parsed.hostname).catch(() => []);
for (const addr of addresses) {
if (ipRangeCheck(addr, PRIVATE_IP_RANGES)) {
throw new Error(`private IP blocked: ${addr}`);
}
}
}
async function generateSkillThumbnail(skill) {
await validatePublicUrl(skill.previewUrl); // throws if private/invalid
const response = await fetch(skill.previewUrl, {
timeout: 5000,
size: 2 * 1024 * 1024, // 2MB limit
redirect: 'error', // no redirects — prevents redirect-chain bypass
});
const contentType = response.headers.get('content-type') || '';
if (!contentType.startsWith('image/')) {
// Log only safe metadata — never log response body
logger.warn('thumbnail_not_image', { skillId: skill.id, contentType });
return null;
}
return resizeImage(await response.buffer());
}
SSRF31-002 — Documentation URL renders internal Confluence Wiki as public skill documentation
Skill authors can supply a docsUrl that the registry fetches server-side to generate an inline documentation preview in the skill listing. The fetched content is parsed as HTML and stored in the registry database as the skill's rendered documentation. If an attacker registers an internal Confluence Wiki URL (e.g., http://confluence.internal/rest/api/content/12345?expand=body.storage), the documentation renderer fetches the Confluence REST API response (JSON containing the page's storage-format HTML), strips HTML tags, and stores the resulting text as the skill's public documentation. Because Confluence Wiki pages in many organizations contain internal architecture decisions, security findings, oncall runbooks, and infrastructure IP addresses, this exposes sensitive internal documentation as a public skill listing on the registry.
// SSRF31-002 — VULNERABLE
// docsUrl fetched server-side without SSRF guard
// Response rendered as HTML — attacker's internal Confluence JSON parsed as doc content
// No hostname allowlist — any internal hostname reachable from the worker network
async function fetchAndRenderDocs(skill) {
const response = await fetch(skill.docsUrl, { timeout: 10000 });
const rawContent = await response.text();
// Parses attacker-controlled response as HTML documentation
const rendered = sanitizeHtml(rawContent, { allowedTags: ['p', 'h2', 'h3', 'code', 'pre'] });
await db.skills.update({ id: skill.id }, { renderedDocs: rendered });
}
// SSRF31-002 — FIXED
// Allowlist of known public documentation hosting providers
// Content-type must be text/html or text/plain — no JSON parsed as documentation
// Never render raw response — sanitize and size-limit
const ALLOWED_DOCS_HOSTNAMES = new Set([
'raw.githubusercontent.com',
'github.com',
'gitlab.com',
'readthedocs.io',
'docs.readthedocs.io',
// Subdomain patterns handled below
]);
function isAllowedDocsHost(hostname) {
if (ALLOWED_DOCS_HOSTNAMES.has(hostname)) return true;
// Allow *.readthedocs.io and *.github.io
if (hostname.endsWith('.readthedocs.io')) return true;
if (hostname.endsWith('.github.io')) return true;
return false;
}
async function fetchAndRenderDocs(skill) {
const parsed = new URL(skill.docsUrl);
if (parsed.protocol !== 'https:') throw new Error('https only');
if (!isAllowedDocsHost(parsed.hostname)) throw new Error('docs host not allowed');
const response = await fetch(skill.docsUrl, {
timeout: 10000,
size: 500 * 1024, // 500KB limit
redirect: 'manual', // no redirects to private hosts
});
const contentType = response.headers.get('content-type') || '';
if (!contentType.includes('text/html') && !contentType.includes('text/plain') && !contentType.includes('text/markdown')) {
throw new Error(`unexpected content-type: ${contentType}`);
}
const rawContent = await response.text();
const rendered = sanitizeHtml(rawContent, { allowedTags: ['p', 'h1', 'h2', 'h3', 'code', 'pre', 'ul', 'li', 'a'] });
await db.skills.update({ id: skill.id }, { renderedDocs: rendered });
}
SSRF31-003 — Changelog URL fetch embeds internal Grafana dashboard in public audit report
When generating an audit report, the registry fetches the skill's changelogUrl server-side to embed the changelog in the report. The response is stored verbatim as the changelog section of the report. If an attacker supplies changelogUrl: "http://grafana.internal:3000/api/dashboards/uid/prod-overview", the registry worker fetches the Grafana REST API response (a JSON object containing panel configurations, metric queries, and datasource credentials) and stores the entire JSON blob as the "changelog" section of the public audit report. Organizations running Grafana internally often have dashboards that query production databases directly, with datasource credentials embedded in the dashboard JSON. These credentials are exposed in the public report.
// SSRF31-003 — VULNERABLE
// changelogUrl fetched server-side, stored verbatim in public report
// No SSRF guard — attacker targets internal Grafana, Prometheus, or config endpoints
async function embedChangelog(skill, reportBuilder) {
if (!skill.changelogUrl) return;
const response = await fetch(skill.changelogUrl, { timeout: 5000 });
const content = await response.text();
// content may be Grafana JSON with datasource credentials — stored in public report
reportBuilder.setChangelog(content);
}
// SSRF31-003 — FIXED
// Allowlist: only raw GitHub/GitLab file URLs (changelog must be a plain text file)
// Content-type must be text/plain or text/markdown
// Size limit + DNS private IP block
const CHANGELOG_HOSTNAME_PATTERNS = [
/^raw\.githubusercontent\.com$/,
/^raw\.gitlab\.com$/,
/^gist\.githubusercontent\.com$/,
];
function isAllowedChangelogHost(hostname) {
return CHANGELOG_HOSTNAME_PATTERNS.some(re => re.test(hostname));
}
async function embedChangelog(skill, reportBuilder) {
if (!skill.changelogUrl) return;
const parsed = new URL(skill.changelogUrl);
if (parsed.protocol !== 'https:') {
logger.warn('changelog_non_https', { skillId: skill.id });
return;
}
if (!isAllowedChangelogHost(parsed.hostname)) {
logger.warn('changelog_host_not_allowed', { skillId: skill.id, hostname: parsed.hostname });
return;
}
const response = await fetch(skill.changelogUrl, {
timeout: 5000,
size: 64 * 1024, // 64KB max — changelogs should be small text files
redirect: 'error',
});
const contentType = response.headers.get('content-type') || '';
if (!contentType.includes('text/plain') && !contentType.includes('text/markdown')) {
logger.warn('changelog_unexpected_content_type', { skillId: skill.id, contentType });
return;
}
const content = await response.text();
// Store as plain text — never render as HTML in public report
reportBuilder.setChangelog(content.substring(0, 8192));
}
Allowlist documentation providers as explicit hostname patterns, not blocklists: SSRF protections based on blocklists (block 10.x, 172.16.x, 192.168.x, 169.254.x) are bypassed by DNS rebinding, IPv6 mapping, and uncommon private ranges (100.64.0.0/10 for CGNAT, 198.18.0.0/15 for benchmarking). Allowlists — explicit sets of trusted documentation hosting provider hostnames — are the right control. Any hostname not on the allowlist is rejected regardless of its IP address. Combine with redirect: 'error' to prevent redirect chains that bypass the hostname check by redirecting to a private IP.
SSRF31-004 — Puppeteer screenshot visits gopher:// URL with web security disabled
The skill screenshot generator uses Puppeteer to visit a user-supplied skill demo URL and capture a screenshot. Puppeteer is launched with --disable-web-security and --allow-file-access-from-files flags (a common pattern copied from testing configurations). No URL scheme restriction is applied before passing the URL to page.goto(). An attacker who submits demoUrl: "gopher://redis:6379/_*1\r\n$8\r\nFLUSHALL\r\n" causes Puppeteer to open a gopher protocol connection to the internal Redis instance and send the encoded Redis command. Because Puppeteer with --disable-web-security does not enforce same-origin restrictions on protocol handlers, and because Chromium's gopher protocol support (or the OS's curl-based fallback) will execute the raw TCP connection to the target, the attacker achieves Redis command execution from the screenshot worker's network context.
// SSRF31-004 — VULNERABLE
// Puppeteer launched with --disable-web-security (copied from test config)
// No URL scheme check before page.goto() — attacker uses gopher:// for Redis commands
const puppeteer = require('puppeteer');
async function captureSkillScreenshot(demoUrl) {
const browser = await puppeteer.launch({
args: [
'--disable-web-security', // disables scheme and origin restrictions
'--allow-file-access-from-files', // allows file:// access
'--no-sandbox',
],
});
const page = await browser.newPage();
// No URL validation — attacker supplies gopher://redis:6379/... or file:///etc/passwd
await page.goto(demoUrl, { waitUntil: 'networkidle2', timeout: 15000 });
const screenshot = await page.screenshot({ type: 'png' });
await browser.close();
return screenshot;
}
// SSRF31-004 — FIXED
// Strict https-only URL validation before page.goto()
// Puppeteer request interception blocks non-https requests (even after redirects)
// No --disable-web-security — security flags kept at production defaults
// DNS private IP check before Puppeteer opens connection
async function captureSkillScreenshot(demoUrl) {
// Validate URL scheme before anything else
let parsed;
try { parsed = new URL(demoUrl); } catch { throw new Error('invalid URL'); }
if (parsed.protocol !== 'https:') throw new Error('https only');
// DNS private IP check — resolve hostname and block private ranges
await validatePublicUrl(demoUrl); // same helper from SSRF31-001
const browser = await puppeteer.launch({
args: [
'--no-sandbox',
'--disable-dev-shm-usage',
// No --disable-web-security, no --allow-file-access-from-files
],
});
const page = await browser.newPage();
// Request interception: block any request that is not https to a public host
await page.setRequestInterception(true);
page.on('request', async interceptedReq => {
const reqUrl = interceptedReq.url();
try {
await validatePublicUrl(reqUrl); // validates scheme + DNS again for every sub-request
interceptedReq.continue();
} catch {
interceptedReq.abort('blockedbyclient');
}
});
await page.goto(demoUrl, { waitUntil: 'networkidle2', timeout: 15000 });
const screenshot = await page.screenshot({ type: 'png', clip: { x: 0, y: 0, width: 1280, height: 800 } });
await browser.close();
return screenshot;
}
Hardening summary
| Finding | Pattern | Fix |
|---|---|---|
| SSRF31-001 | Unfettered previewUrl fetch; IMDSv1 IAM creds in error log included in audit report | Hostname allowlist + DNS private-IP block; 2MB size limit; no response body in logs |
| SSRF31-002 | Unfettered docsUrl fetch renders internal Confluence REST API JSON as public documentation | Allowlist of documentation hosting providers; content-type must be text/html or text/plain |
| SSRF31-003 | Changelog URL fetched and stored verbatim in public report; exposes Grafana dashboard with datasource credentials | Allowlist of raw GitHub/GitLab hostname patterns; content-type text only; 64KB limit |
| SSRF31-004 | Puppeteer with --disable-web-security + no URL scheme check; gopher://redis executes Redis commands | HTTPS-only URL validation; Puppeteer request interception; remove --disable-web-security |
Related: SA-SKL-SSRF30, SA-SKL-SSRF29. Run SkillAudit to surface all SSRF31 patterns in your MCP skill registry.