Claude skill SSRF via PDF generation and headless browser rendering — SA-SKL-SSRF9
MCP skills that generate PDFs, screenshots, or HTML exports using puppeteer, wkhtmltopdf, html-pdf, or Playwright are SSRF entry points when user-controlled URLs or HTML content reach the headless browser. SA-SKL-SSRF9 covers four patterns: page.goto() on a user URL reads AWS IMDS credentials; --header-html with a user-settable value fetches internal services; PhantomJS resolves file:// URIs from user HTML bodies; and an exposed Chromium DevTools Protocol port gives any network peer full remote control over the browser session.
Why headless browsers are high-impact SSRF vectors
A headless browser is not just an HTTP client. It is a full browser engine that follows redirects (including meta-refresh), executes JavaScript, reads cookies, resolves multiple URI schemes (https://, file://, data://), and returns rich output — screenshots, DOM snapshots, PDF binary — that can embed the full response body of any URL it navigates to. When an MCP skill passes user-controlled input to a headless browser, the entire internal network becomes readable through the render output.
The AWS Instance Metadata Service at http://169.254.169.254/latest/meta-data/iam/security-credentials/<role> is accessible from any AWS EC2 or ECS container without authentication. A successful navigation to that URL returns a JSON object with live AccessKeyId, SecretAccessKey, and Token — credentials that grant full IAM role permissions. Because the credentials rotate every few hours, there is no way to revoke an already-exfiltrated set before the attacker uses them.
page.goto(userUrl) without request interception and IP validation; IMDS credential exfiltration via screenshot--header-html set from user-controlled config; fetches internal services on every PDF page renderfile:///etc/passwd or file:///proc/self/environ src attributes0.0.0.0:9222; any network peer can call Page.navigate and read internal servicesSSRF9-001 — puppeteer page.goto() on user-supplied URL
An MCP skill passes a user-supplied URL directly to page.goto() with no IP-range validation and no request interception. The attacker calls the skill with url = "http://169.254.169.254/latest/meta-data/iam/security-credentials/". The headless Chromium navigates to the IMDS endpoint, the JSON credential response is rendered in the viewport, and the PDF or screenshot returned to the caller contains the live AWS credentials. The same technique works against http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token on GCP and against any RFC 1918 service endpoint reachable from the container's network interface.
// VULNERABLE — user URL reaches page.goto() without interception
import puppeteer from 'puppeteer';
export async function screenshotUrl(url: string): Promise<Buffer> {
const browser = await puppeteer.launch({ args: ['--no-sandbox'] });
const page = await browser.newPage();
await page.goto(url, { waitUntil: 'networkidle2' }); // ← user URL, no validation
const shot = await page.screenshot({ type: 'png', fullPage: true });
await browser.close();
return shot as Buffer;
}
// FIXED — DNS-based IP validation + request interception
import puppeteer from 'puppeteer';
import dns from 'dns/promises';
import { isIP } from 'net';
function ipToInt(ip: string): number {
return ip.split('.').reduce((a, o) => (a << 8) | parseInt(o, 10), 0) >>> 0;
}
const BLOCKED = [
['10.0.0.0','10.255.255.255'],['172.16.0.0','172.31.255.255'],
['192.168.0.0','192.168.255.255'],['127.0.0.0','127.255.255.255'],
['169.254.0.0','169.254.255.255'],['100.100.100.0','100.100.100.255'],
].map(([s,e]) => [ipToInt(s), ipToInt(e)]);
function isBlockedIp(ip: string): boolean {
if (ip.includes(':')) return ip === '::1';
const n = ipToInt(ip);
return BLOCKED.some(([s,e]) => n >= s && n <= e);
}
async function safeGoto(page: puppeteer.Page, url: string): Promise<void> {
const parsed = new URL(url);
if (!['https:','http:'].includes(parsed.protocol)) throw new Error('Scheme not allowed');
if (isIP(parsed.hostname) && isBlockedIp(parsed.hostname)) throw new Error('Blocked IP');
if (!isIP(parsed.hostname)) {
const ips = [...await dns.resolve4(parsed.hostname).catch(()=>[]),
...await dns.resolve6(parsed.hostname).catch(()=>[])];
if (ips.some(isBlockedIp)) throw new Error('Resolves to blocked IP range');
}
await page.setRequestInterception(true);
page.on('request', async req => {
try {
const h = new URL(req.url()).hostname;
const rips = isIP(h) ? [h] : await dns.resolve4(h).catch(()=>[]);
if (rips.some(isBlockedIp)) { req.abort('blockedbyclient'); return; }
} catch { req.abort('blockedbyclient'); return; }
req.continue();
});
await page.goto(url, { waitUntil: 'networkidle2', timeout: 15000 });
}
export async function screenshotUrl(url: string): Promise<Buffer> {
const browser = await puppeteer.launch({ args: ['--no-sandbox'] });
const page = await browser.newPage();
await safeGoto(page, url);
const shot = await page.screenshot({ type: 'png', fullPage: true });
await browser.close();
return shot as Buffer;
}
SSRF9-002 — wkhtmltopdf --header-html set from user config
wkhtmltopdf accepts a --header-html argument that must be a URL or file path. The tool fetches that URL using its built-in WebKit engine before rendering each page. If the URL originates from user-controlled account settings — for example, a custom letterhead URL the user is allowed to configure — the attacker sets it to an internal service URL. Every PDF generated for that account then fetches the internal endpoint and potentially embeds the response in the rendered header.
// VULNERABLE — header URL from user account settings
import { execFile } from 'child_process';
import { promisify } from 'util';
const execFileAsync = promisify(execFile);
async function renderPdf(headerUrl: string, bodyUrl: string, out: string): Promise<void> {
// headerUrl from user settings — attacker sets to http://internal-db:5432/
await execFileAsync('wkhtmltopdf', ['--header-html', headerUrl, bodyUrl, out]);
}
// FIXED — header written from static template to local tmp file; --no-external-links
import { execFile } from 'child_process';
import { promisify } from 'util';
import fs from 'fs/promises';
import os from 'os';
import path from 'path';
const execFileAsync = promisify(execFile);
async function renderPdf(orgName: string, bodyHtmlPath: string, out: string): Promise<void> {
const safe = orgName.replace(/[<>&"]/g, c => ({'<':'<','>':'>','&':'&','"':'"'}[c]!));
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'pdf-'));
const hPath = path.join(tmpDir, 'header.html');
try {
await fs.writeFile(hPath, `<html><body style="font-size:11px">${safe}</body></html>`, 'utf8');
await execFileAsync('wkhtmltopdf', [
'--header-html', hPath, // ← local file, not user URL
'--no-external-links',
'--disable-javascript',
bodyHtmlPath, out
]);
} finally {
await fs.rm(tmpDir, { recursive: true, force: true });
}
}
SSRF9-003 — html-pdf PhantomJS resolves file:// URI from user HTML
The html-pdf npm package uses PhantomJS as its rendering engine. PhantomJS unconditionally resolves file:// URIs in all HTML attributes. When an MCP skill accepts user HTML and passes it to pdf.create() without sanitization, an attacker embeds <iframe src="file:///proc/self/environ"></iframe> in the HTML body. PhantomJS renders the contents of /proc/self/environ — which includes AWS_SECRET_ACCESS_KEY, DATABASE_URL, and any other environment variables — as text in the PDF page, delivering all secrets to the attacker in the returned document.
// VULNERABLE — user HTML passed to html-pdf without sanitization
import pdf from 'html-pdf';
export function createReportPdf(userHtml: string): Promise<Buffer> {
return new Promise((resolve, reject) => {
pdf.create(userHtml, { format: 'A4' }).toBuffer((err, buf) => {
// attacker userHtml = '<iframe src="file:///proc/self/environ">'
// buf contains env vars including DB credentials
if (err) reject(err); else resolve(buf);
});
});
}
// FIXED — DOMPurify strips src/href + migrate to puppeteer with request interception
import { JSDOM } from 'jsdom';
import createDOMPurify from 'dompurify';
import puppeteer from 'puppeteer';
const DOMPurify = createDOMPurify(new JSDOM('').window as unknown as Window);
function sanitize(html: string): string {
return DOMPurify.sanitize(html, {
FORBID_TAGS: ['script','iframe','object','embed','base','link','meta'],
FORBID_ATTR: ['src','href','action','formaction','xlink:href'],
ALLOW_DATA_ATTR: false,
});
}
export async function createReportPdf(userHtml: string): Promise<Buffer> {
const clean = sanitize(userHtml);
const browser = await puppeteer.launch({ args: ['--no-sandbox'] });
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', req => {
if (req.url().startsWith('data:') || req.url().startsWith('about:')) { req.continue(); return; }
req.abort('blockedbyclient');
});
await page.setContent(clean, { waitUntil: 'domcontentloaded' });
const buf = await page.pdf({ format: 'A4' });
await browser.close();
return buf;
}
SSRF9-004 — Chromium DevTools Protocol exposed on :9222
Chromium launched with --remote-debugging-port=9222 without a corresponding --remote-debugging-address=127.0.0.1 binds the CDP WebSocket server on all network interfaces. Any host in the same VPC, Kubernetes namespace, or Docker network can connect to ws://container-ip:9222/ without authentication and call any CDP method. Page.navigate + Runtime.evaluate(() => document.body.innerText) returns the full text content of any URL the browser navigates to — including IMDS, internal dashboards, and service mesh endpoints.
// VULNERABLE — DEVTOOLS_PORT env var binds CDP to 0.0.0.0
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch({
args: [
'--no-sandbox',
`--remote-debugging-port=${process.env.DEVTOOLS_PORT || 9222}`,
// No --remote-debugging-address — defaults to 0.0.0.0
]
});
// FIXED — no CDP in production; loopback-only in dev
import puppeteer from 'puppeteer';
const args = ['--no-sandbox','--disable-setuid-sandbox','--disable-dev-shm-usage','--disable-gpu'];
if (process.env.NODE_ENV === 'development' && process.env.DEVTOOLS_PORT) {
args.push(`--remote-debugging-port=${process.env.DEVTOOLS_PORT}`);
args.push('--remote-debugging-address=127.0.0.1'); // loopback only
}
// No remote-debugging-port in production
const browser = await puppeteer.launch({ args });
Related patterns: For SSRF via fetch-based markdown rendering — where user-controlled markdown image URLs trigger server-side HTTP requests — see SA-SKL-SSRF8: markdown and HTML render SSRF. For the foundational MCP server SSRF checklist covering fetch(), axios, and got(), see the MCP server SSRF security guide. For more context on the headless browser SSRF class with extended code examples, see the SSRF via PDF generation and headless browser blog post.
| Finding | Severity | Vulnerable pattern | Fix |
|---|---|---|---|
SSRF9-001 | Critical 9.1 | page.goto(req.body.url) | DNS IP validation + setRequestInterception(true) default-deny RFC1918 |
SSRF9-002 | High 8.2 | ['--header-html', userValue] | Write header from static template to tmp file; --no-external-links --disable-javascript |
SSRF9-003 | Critical 9.3 | pdf.create(userHtml) | DOMPurify FORBID_ATTR src/href + migrate to puppeteer |
SSRF9-004 | Critical 9.8 | --remote-debugging-port=9222 no address | Remove in prod; dev: add --remote-debugging-address=127.0.0.1 |