Claude skill SSRF via cloud metadata endpoints and internal service discovery — SA-SKL-SSRF4
Server-Side Request Forgery in cloud-hosted MCP skills is not just about reading arbitrary URLs — it is about reaching the cloud provider's metadata endpoint and exfiltrating the IAM credentials or OAuth tokens that govern your entire cloud infrastructure. SA-SKL-SSRF4 covers four cloud-specific SSRF patterns: AWS IMDSv1 credential theft, GCP metadata token exfiltration, internal VPC service discovery, and SSRF through PDF and image rendering services.
Why SSRF in cloud environments is a full infrastructure compromise, not just an information leak
On-premises SSRF typically lets an attacker reach internal services that are not exposed to the internet. Cloud SSRF adds a qualitatively different target: the instance metadata service. Every major cloud provider runs a metadata endpoint reachable only from within the instance — 169.254.169.254 on AWS and GCP, 169.254.169.254 on Azure — that returns the instance's IAM role credentials or service account OAuth tokens. These credentials are rotated automatically by the cloud provider, but until rotation they grant the same permissions as the instance's IAM role. For a production skill running with an IAM role that has S3 read access, RDS access, or cross-account trust, a single SSRF that reaches the metadata endpoint returns temporary credentials that can be used outside the instance with aws configure --profile stolen.
MCP skills that accept URLs as tool call arguments — for fetching pages, generating PDFs, rendering previews, or importing content — have the metadata endpoint reachable from their HTTP client and must validate every user-supplied URL against a strict blocklist before making the outbound request.
SA-SKL-SSRF4 in scope: SSRF4-001 (AWS IMDSv1 at 169.254.169.254), SSRF4-002 (GCP metadata at metadata.google.internal), SSRF4-003 (internal VPC service discovery via DNS), SSRF4-004 (SSRF via headless browser or wkhtmltopdf renderer). Each pattern includes SkillAudit detection rules and correct fixes.
SSRF4-001 — AWS IMDSv1 access returns IAM role credentials
AWS EC2 instances and ECS tasks expose the Instance Metadata Service (IMDS) at 169.254.169.254. IMDSv1 — the original version — requires no authentication beyond network reachability: any process on the instance that can make an HTTP GET request can read IAM role credentials from http://169.254.169.254/latest/meta-data/iam/security-credentials/<role-name>. A skill's HTTP client that follows attacker-supplied URLs and returns the response body will exfiltrate AccessKeyId, SecretAccessKey, and SessionToken in the first successful SSRF request. The fix requires two layers: enforce IMDSv2 (which requires a PUT token request before GET — a step the skill's simple SSRF HTTP call will not perform), and add a URL blocklist in the skill that rejects all requests to 169.254.0.0/16 (link-local) before making any outbound HTTP call.
// VULNERABLE — skill fetches user-supplied URL without SSRF protection
import fetch from 'node-fetch';
export async function fetchPageContent(url: string): Promise<string> {
// Attacker supplies:
// "http://169.254.169.254/latest/meta-data/iam/security-credentials/skillaudit-prod-role"
// Returns: {"AccessKeyId":"ASIA...","SecretAccessKey":"...","SessionToken":"...","Expiration":"..."}
const response = await fetch(url);
if (!response.ok) throw new Error(`Fetch failed: ${response.status}`);
return await response.text();
}
// FIXED — resolve hostname, block private/link-local ranges, then fetch
import fetch from 'node-fetch';
import dns from 'dns/promises';
import { isIP } from 'net';
import ipRangeCheck from 'ip-range-check';
const BLOCKED_RANGES = [
'169.254.0.0/16', // Link-local — AWS/GCP/Azure IMDS
'10.0.0.0/8', // RFC 1918 private
'172.16.0.0/12', // RFC 1918 private
'192.168.0.0/16', // RFC 1918 private
'127.0.0.0/8', // Loopback
'::1/128', // IPv6 loopback
'fc00::/7', // IPv6 unique local
'fe80::/10', // IPv6 link-local
];
async function validateUrlForSsrf(url: string): Promise<URL> {
let parsed: URL;
try {
parsed = new URL(url);
} catch {
throw new Error('Invalid URL');
}
// Only allow http and https — block file://, ftp://, gopher://, dict://
if (!['http:', 'https:'].includes(parsed.protocol)) {
throw new Error('URL protocol not allowed');
}
// Resolve hostname to IP — catches DNS rebinding and internal hostnames
const hostname = parsed.hostname;
let resolvedIp: string;
if (isIP(hostname)) {
resolvedIp = hostname;
} else {
try {
const { address } = await dns.lookup(hostname);
resolvedIp = address;
} catch {
throw new Error('DNS resolution failed');
}
}
// Block all private, link-local, and loopback ranges
if (ipRangeCheck(resolvedIp, BLOCKED_RANGES)) {
throw new Error(`Request to internal IP address not allowed: ${resolvedIp}`);
}
return parsed;
}
export async function fetchPageContent(url: string): Promise<string> {
const validatedUrl = await validateUrlForSsrf(url);
const response = await fetch(validatedUrl.toString(), {
// Disable automatic redirect following — re-validate redirect targets
redirect: 'manual',
});
if (response.status >= 300 && response.status < 400) {
throw new Error('Redirects not followed — re-validate redirect target');
}
if (!response.ok) throw new Error(`Fetch failed: ${response.status}`);
return await response.text();
}
169.254.0.0/16 are vulnerable to IMDSv1 credential exfiltration — a single SSRF returns a valid AWS access key with the instance's IAM role permissions; fix by resolving hostnames to IPs before fetching and blocking all RFC 1918, link-local, and loopback ranges, and by enforcing IMDSv2 (hop limit 1, PUT token required) at the AWS account level. Detection: SkillAudit flags skill tool handler functions that call fetch(), axios.get(), or http.request() with a URL sourced from tool call arguments without an intervening SSRF blocklist check.SSRF4-002 — GCP metadata server returns OAuth2 access token
Google Cloud instances expose the metadata server at http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token. Unlike IMDSv1, the GCP metadata server requires the Metadata-Flavor: Google request header — requests without it are rejected. This creates a false sense of security: developers assume that since arbitrary HTTP clients won't send this header, the endpoint is not reachable via SSRF. However, the check is trivially bypassed if the skill's HTTP client adds custom headers from user input, or if the attacker can influence the headers sent. More importantly, it is not an IP-level protection — the metadata server is still at a link-local address that must be blocked at the SSRF validation layer. The fix is the same as SSRF4-001: resolve the hostname metadata.google.internal (which resolves to 169.254.169.254) and block all link-local ranges before making any HTTP request.
// VULNERABLE — SSRF to GCP metadata server via hostname resolution
export async function fetchExternalContent(url: string, headers: Record<string, string> = {}) {
// Attacker supplies:
// url = "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token"
// headers = {"Metadata-Flavor": "Google"}
// Returns: {"access_token":"ya29.xxx","expires_in":3599,"token_type":"Bearer"}
// No hostname resolution or blocklist — metadata.google.internal resolves to 169.254.169.254
const response = await fetch(url, { headers });
return await response.json();
}
// FIXED — resolve metadata.google.internal to 169.254.169.254, then block link-local
// (The validateUrlForSsrf function from SSRF4-001 handles this correctly)
export async function fetchExternalContent(url: string): Promise<unknown> {
// Note: user-controlled headers are NOT passed through — attacker cannot
// supply Metadata-Flavor header even if the IP check were bypassed
const validatedUrl = await validateUrlForSsrf(url);
const response = await fetch(validatedUrl.toString(), {
headers: {
'User-Agent': 'SkillAudit/1.0',
// No header passthrough from user input
},
redirect: 'manual',
});
if (response.status >= 300 && response.status < 400) {
throw new Error('Redirects not followed');
}
return await response.json();
}
// Also enforce at the cloud network level:
// GCP: add org policy constraints/compute.requireOsLogin
// Block outbound traffic to 169.254.169.254 at VPC firewall level
// GCP: enforce Workload Identity instead of service account key files on instances
metadata.google.internal resolves to 169.254.169.254 and returns a valid OAuth2 service account token to any request with the Metadata-Flavor: Google header; skills that allow user-controlled headers or that fail to block link-local addresses are vulnerable; fix by blocking 169.254.0.0/16 at DNS resolution time and by never passing user-controlled headers to outbound HTTP requests. Detection: SkillAudit flags outbound HTTP calls where any part of the headers object is derived from tool call arguments or HTTP request parameters.SSRF4-003 — Internal VPC service discovery via SSRF HTTP client
Beyond the metadata endpoint, cloud-hosted skills run inside a VPC where internal services are reachable by DNS name: redis.internal, postgres.internal, prometheus.skillaudit.svc, Kubernetes service endpoints, and health check endpoints on :8080 that are not exposed to the public internet. A skill's HTTP client that resolves attacker-controlled hostnames can reach any of these services. While most database protocols are not HTTP (and an HTTP client will not successfully authenticate to PostgreSQL), Redis in particular has a text-based protocol that can be driven over raw TCP — and some microservices expose unauthenticated REST endpoints on internal ports. The fix is to perform DNS resolution before the HTTP call and to block all RFC 1918 ranges in addition to link-local, combined with an optional DNS rebinding protection that re-validates the resolved IP immediately before the TCP connection is established.
// VULNERABLE — skill resolves attacker-controlled hostname to internal VPC IP
export async function importFromUrl(importUrl: string) {
// Attacker supplies: "http://redis.internal:6379"
// HTTP client connects to internal Redis — sends HTTP headers, may read memory
// Or: "http://prometheus.skillaudit.svc:9090/api/v1/query?query=up"
// Returns internal metrics data
const response = await fetch(importUrl);
const data = await response.json();
return processImport(data);
}
// FIXED — block all private ranges at DNS resolution; apply to all HTTP clients
// (validateUrlForSsrf from SSRF4-001 covers RFC 1918 blocking)
// Additional DNS rebinding protection — re-check IP at connection time
// Use an HTTP library that supports socket-level IP verification:
import { Agent } from 'node:https';
import ipRangeCheck from 'ip-range-check';
const safeHttpsAgent = new Agent({
lookup: (hostname, options, callback) => {
dns.lookup(hostname, options).then(({ address, family }) => {
if (ipRangeCheck(address, BLOCKED_RANGES)) {
callback(new Error(`Blocked internal IP: ${address}`), '', 0);
} else {
callback(null, address, family);
}
}).catch(err => callback(err, '', 0));
},
});
export async function importFromUrl(importUrl: string): Promise<unknown> {
// First-pass validation (URL structure + initial DNS check)
const validatedUrl = await validateUrlForSsrf(importUrl);
// Second-pass protection via custom DNS lookup in HTTP agent
const response = await fetch(validatedUrl.toString(), {
agent: validatedUrl.protocol === 'https:' ? safeHttpsAgent : undefined,
redirect: 'manual',
});
return await response.json();
}
SSRF4-004 — SSRF via PDF or image rendering service
MCP skills that generate audit reports, screenshots, or document exports often delegate rendering to a headless Chrome instance (via Puppeteer or Playwright) or to a tool like wkhtmltopdf. These renderers are themselves HTTP clients: they receive a URL, load the page, and return a rendered output. If the skill passes a user-supplied URL to the renderer, the renderer's HTTP client makes the request — and that client is typically running with higher privileges than the skill's own HTTP client, may not share the same SSRF blocklist middleware, and often runs with no network egress restrictions at all. The fix is to never pass user-supplied URLs directly to a renderer. Instead, proxy all renderer requests through the same SSRF-validated HTTP client, or implement a renderer-side URL allowlist at the network firewall level using a dedicated egress proxy for rendering traffic.
// VULNERABLE — user URL passed directly to Puppeteer headless renderer
import puppeteer from 'puppeteer';
export async function generateAuditReport(reportUrl: string): Promise<Buffer> {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// Attacker supplies: "http://169.254.169.254/latest/meta-data/iam/security-credentials/prod-role"
// Puppeteer loads the URL — its HTTP client bypasses all skill-level SSRF checks
// The rendered PDF contains the IAM credentials in plain text
await page.goto(reportUrl);
const pdf = await page.pdf({ format: 'A4' });
await browser.close();
return pdf;
}
// FIXED — validate URL before renderer; use allowlist-only mode; restrict renderer network
import puppeteer from 'puppeteer';
export async function generateAuditReport(reportUrl: string): Promise<Buffer> {
// Option A: validate URL with the same SSRF blocklist before passing to Puppeteer
await validateUrlForSsrf(reportUrl); // Throws if URL targets private/link-local range
// Option B: enforce a URL allowlist — only allow report URLs that match your own domain
const parsed = new URL(reportUrl);
const ALLOWED_REPORT_DOMAINS = new Set(['app.skillaudit.dev', 'reports.skillaudit.dev']);
if (!ALLOWED_REPORT_DOMAINS.has(parsed.hostname)) {
throw new Error('Report URL must be from an allowed domain');
}
const browser = await puppeteer.launch({
args: [
'--no-sandbox',
// Restrict renderer to only fetch from the allowlisted domain
`--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE ${parsed.hostname}`,
],
});
const page = await browser.newPage();
// Block requests inside Puppeteer as a secondary defence
await page.setRequestInterception(true);
page.on('request', async (request) => {
const reqUrl = new URL(request.url());
if (!ALLOWED_REPORT_DOMAINS.has(reqUrl.hostname)) {
request.abort();
return;
}
request.continue();
});
await page.goto(reportUrl, { waitUntil: 'networkidle0' });
const pdf = await page.pdf({ format: 'A4' });
await browser.close();
return pdf;
}
// Infrastructure fix: run the renderer in a dedicated subnet with egress restricted
// to your report domain IPs only — block 169.254.0.0/16 and RFC 1918 at the VPC
// firewall level so even a bypassed Puppeteer cannot reach the metadata endpoint
page.goto(), page.navigate(), or wkhtmltopdf() where the URL argument traces directly to a tool call argument without passing through a URL validation and blocklist function.