Claude MCP skill SSRF via server-side image rendering and thumbnail generation — SA-SKL-SSRF12
Image processing libraries used in MCP skills — sharp, node-canvas, jimp, and social preview scrapers — frequently fetch URLs supplied directly by the caller. Each fetch is a server-side HTTP request originating from the skill's backend, with access to cloud instance metadata services, internal VPC networks, and local filesystem paths. An attacker who controls the URL parameter can reach resources that are reachable from the server but not from the browser, turning a thumbnail generator into a full SSRF oracle. The four SA-SKL-SSRF12 patterns cover the most common library-level SSRF sinks found in MCP skill image pipelines.
Why image libraries create SSRF sinks in MCP skills
MCP skills commonly accept a URL parameter so that users can process images hosted externally — resize a product photo, generate a thumbnail from a social link, extract dimensions before display. The developer calls sharp(url), canvas.loadImage(url), or jimp.read(url) without realising that these calls perform an HTTP GET from the server, not from the client. The resulting request inherits the server's network identity and credentials: IAM instance role credentials reachable at 169.254.169.254, private RDS or Elasticsearch endpoints on the VPC, Redis or Memcached on localhost, and any other service not exposed to the public internet.
Unlike direct fetch() or axios.get() calls — which developers sometimes remember to validate — image library calls are perceived as "just reading an image" and rarely receive IP-range checks. The SSRF is also harder to detect statically because the network call is buried inside the library rather than explicit in the calling code. SkillAudit's SA-SKL-SSRF12 ruleset uses data-flow analysis to trace user-controlled input through image library APIs to underlying HTTP fetches, surfacing these implicit sinks alongside the more obvious ones.
sharp.metadata(userUrl) fetches the URL server-side to read image metadata; attacker passes http://169.254.169.254/latest/meta-data/iam/security-credentials/role to exfiltrate IMDS IAM credentialscanvas.loadImage(userUrl) in node-canvas fires HTTP GET to attacker-controlled URL; internal service returning JSON (not an image) still responds; HTTP request made even when canvas render failsjimp.read(userUrl) follows HTTP redirects by default; redirect chain leads from public host to 192.168.1.1 internal router; fix: jimp custom got options with followRedirect: false and DNS IP checkog:image from attacker-controlled page; og:image set to file:///etc/passwd; scraper reads local filesystem path; fix: https:// only scheme + DNS IP validation on all fetched URLsSSRF12-001 — sharp.metadata() fetches user URL to exfiltrate IMDS credentials
The sharp library is the most popular Node.js image processing library. When called with a URL string instead of a local file path or Buffer, sharp(url) and sharp.metadata(url) perform an HTTP GET to that URL to retrieve the image data. This is documented behaviour — sharp uses libvips under the hood, which supports remote URL fetches. An attacker who can supply a URL to a skill endpoint that calls sharp(userUrl).metadata() can point it at the AWS IMDS endpoint (http://169.254.169.254/latest/meta-data/iam/security-credentials/role-name), which returns a JSON object containing AccessKeyId, SecretAccessKey, and Token. The JSON response is not a valid image, so sharp throws an error — but the HTTP request was already made and the response body is available in the error object or via the error handler's data.
The fix is to never pass a user-supplied URL directly to sharp. Instead, download the image to a temporary file using a fetch call that includes IP-range validation, then pass the temp file path to sharp. This decouples the network fetch (which you control and can validate) from the image processing (which sharp handles locally).
// VULNERABLE — sharp.metadata() fetches user URL server-side
import sharp from 'sharp';
export async function getImageDimensions(userUrl: string) {
// VULNERABLE: sharp fetches userUrl directly using libvips HTTP transport
// attacker passes: http://169.254.169.254/latest/meta-data/iam/security-credentials/role
// sharp throws "unsupported image format" but the HTTP GET already fired
// error.message may include partial response body from IMDS
const metadata = await sharp(userUrl).metadata();
return { width: metadata.width, height: metadata.height };
}
// FIXED — download with IP-range validation; pass temp file to sharp
import sharp from 'sharp';
import { fetch } from 'undici';
import { createWriteStream } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
import { randomBytes } from 'crypto';
import dns from 'dns/promises';
const RFC1918 = [
/^10\./,
/^172\.(1[6-9]|2\d|3[01])\./,
/^192\.168\./,
/^127\./,
/^169\.254\./, // IMDS
/^0\./, // 0.0.0.0
/^::1$/, // IPv6 loopback
/^fc00:/, // IPv6 ULA
];
async function isSafeUrl(urlStr: string): Promise {
let parsed: URL;
try { parsed = new URL(urlStr); } catch { return false; }
// https:// only — no file://, ftp://, or gopher://
if (parsed.protocol !== 'https:') return false;
// Resolve the hostname to IP and validate
const { address } = await dns.lookup(parsed.hostname);
if (RFC1918.some(re => re.test(address))) return false;
return true;
}
export async function getImageDimensions(userUrl: string) {
if (!await isSafeUrl(userUrl)) {
throw Object.assign(new Error('Invalid image URL'), { code: 'SSRF_BLOCKED' });
}
// Download to temp file — sharp never sees the URL
const tmpPath = join(tmpdir(), `img-${randomBytes(8).toString('hex')}`);
const res = await fetch(userUrl, { redirect: 'error' }); // no redirects
if (!res.ok) throw new Error(`Image fetch failed: ${res.status}`);
const body = await res.arrayBuffer();
await Bun.write(tmpPath, body); // or fs.writeFile
try {
const metadata = await sharp(tmpPath).metadata();
return { width: metadata.width, height: metadata.height };
} finally {
await fs.unlink(tmpPath).catch(() => {});
}
}
SSRF12-002 — canvas.loadImage() fetches internal services even when render fails
The node-canvas library's loadImage(url) function downloads a URL using Node.js's built-in https module to load an image for 2D canvas rendering. The critical behaviour developers miss is that the HTTP request is initiated synchronously with the call — before canvas attempts to decode the response as an image. If the URL points to an internal service that returns JSON (like http://internal-redis:6379/ or an Elasticsearch node at http://10.0.1.5:9200/_cat/indices), the HTTP GET is still sent and the response arrives on the server before canvas rejects it as an invalid image format. The error thrown by loadImage does not contain the response body, but the network request has been made, and in some configurations the response can be inferred from timing or error code differences.
The same fix applies: validate the URL using DNS IP-range checking before passing it to any image library. Because loadImage does not expose a custom HTTP agent option in older node-canvas versions, the only reliable mitigation is to pre-download the image with a validated fetch and pass the resulting Buffer to loadImage(buffer).
// VULNERABLE — canvas.loadImage() fetches any URL including internal services
import { createCanvas, loadImage } from 'canvas';
export async function renderThumbnail(backgroundUrl: string, text: string) {
const canvas = createCanvas(1200, 630);
const ctx = canvas.getContext('2d');
// VULNERABLE: loadImage() fires HTTP GET to backgroundUrl before image decode attempt
// internal services at http://10.0.1.5:9200/ still receive the request
// attacker probes internal network topology via error timing differences
const img = await loadImage(backgroundUrl);
ctx.drawImage(img, 0, 0, 1200, 630);
ctx.fillText(text, 60, 315);
return canvas.toBuffer('image/png');
}
// FIXED — pre-download with DNS validation; pass Buffer to loadImage
import { createCanvas, loadImage } from 'canvas';
import { fetch } from 'undici';
async function fetchSafeImage(url: string): Promise {
if (!await isSafeUrl(url)) { // isSafeUrl from SSRF12-001 fix
throw Object.assign(new Error('Blocked URL'), { code: 'SSRF_BLOCKED' });
}
const res = await fetch(url, {
redirect: 'error', // block redirect chains
signal: AbortSignal.timeout(5000), // 5 second timeout
});
if (!res.ok) throw new Error(`Fetch failed: ${res.status}`);
const contentType = res.headers.get('content-type') ?? '';
if (!contentType.startsWith('image/')) {
throw new Error(`Unexpected content-type: ${contentType}`);
}
const arrayBuffer = await res.arrayBuffer();
return Buffer.from(arrayBuffer);
}
export async function renderThumbnail(backgroundUrl: string, text: string) {
const imgBuffer = await fetchSafeImage(backgroundUrl);
// loadImage() receives a Buffer — no network access, no SSRF
const img = await loadImage(imgBuffer);
const canvas = createCanvas(1200, 630);
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0, 1200, 630);
ctx.fillText(text, 60, 315);
return canvas.toBuffer('image/png');
}
SSRF12-003 — jimp.read() follows redirect chains to RFC1918 addresses
jimp.read(url) internally uses the got HTTP client with redirects enabled by default. An attacker can serve a URL that returns an HTTP 301 redirect to an RFC1918 address: the initial DNS lookup for the public hostname passes the IP-range check (it resolves to a legitimate public IP), but after the redirect, jimp follows the Location header to http://192.168.1.1/admin without re-validating the new destination. This is a standard DNS-or-redirect SSRF bypass. The fix requires setting followRedirect: false in the jimp got options (available via Jimp.read(url, { got: { followRedirect: false } }) in Jimp 0.22+) combined with a DNS IP-range check on the original URL before the read.
// VULNERABLE — jimp.read() follows redirects including to RFC1918 destinations
import Jimp from 'jimp';
export async function resizeImage(userUrl: string, width: number, height: number) {
// VULNERABLE: jimp uses got with followRedirect:true by default
// attacker controls a URL at attacker.com/redirect that returns 301 → http://192.168.1.1/admin
// jimp follows the redirect; RFC1918 address never checked by any validation code
const image = await Jimp.read(userUrl);
const resized = await image.resize(width, height).getBufferAsync(Jimp.MIME_PNG);
return resized;
}
// FIXED — block redirects; validate origin URL with DNS IP check
import Jimp from 'jimp';
export async function resizeImage(userUrl: string, width: number, height: number) {
if (!await isSafeUrl(userUrl)) { // isSafeUrl from SSRF12-001 fix
throw Object.assign(new Error('Blocked URL'), { code: 'SSRF_BLOCKED' });
}
// Jimp 0.22+ supports custom got options via second parameter
// followRedirect: false — any redirect throws an error rather than following
// This prevents the redirect-chain bypass even if the DNS check on the
// original hostname passes
const image = await Jimp.read(userUrl, {
got: {
followRedirect: false,
timeout: { request: 5000 },
retry: { limit: 0 }, // no retries — prevents timing-based probing
},
});
const resized = await image.resize(width, height).getBufferAsync(Jimp.MIME_PNG);
return resized;
}
SSRF12-004 — og:image social preview scraper follows file:// URIs
Social preview scrapers in MCP skills fetch a user-supplied webpage URL and extract the <meta property="og:image"> tag to display a preview thumbnail. The scraper then fetches the value of the og:image attribute to download the image. An attacker who controls the target page (or hosts a page on a compromised domain) sets og:image to file:///etc/passwd or file:///proc/1/environ. If the scraper's underlying HTTP client supports the file:// scheme (Node.js's undici does not by default, but many link-preview libraries use older node-fetch or custom parsers that do), the server reads the local filesystem path and returns it in the preview response. Even if the scraper's HTTP client blocks file://, attacker-controlled og:image URLs pointing to http://169.254.169.254/ achieve cloud credential exfiltration without any filesystem involvement.
The fix requires two defences: (1) validate the scheme of the og:image URL — https:// only, no http://, no file://; (2) run the DNS IP-range check on the resolved hostname before fetching.
// VULNERABLE — og:image URL fetched without scheme or IP validation
import * as cheerio from 'cheerio';
import { fetch } from 'undici';
export async function getSocialPreview(pageUrl: string) {
const res = await fetch(pageUrl); // VULNERABLE: pageUrl itself also needs validation
const html = await res.text();
const $ = cheerio.load(html);
const ogImage = $('meta[property="og:image"]').attr('content');
if (ogImage) {
// VULNERABLE: ogImage value comes from attacker-controlled HTML
// attacker sets og:image = "file:///etc/passwd"
// or og:image = "http://169.254.169.254/latest/meta-data/iam/security-credentials/role"
const imgRes = await fetch(ogImage);
const imgBuffer = Buffer.from(await imgRes.arrayBuffer());
return { imageBuffer: imgBuffer, url: pageUrl };
}
return null;
}
// FIXED — validate pageUrl and og:image URL before any fetch
import * as cheerio from 'cheerio';
import { fetch } from 'undici';
export async function getSocialPreview(pageUrl: string) {
// Validate the page URL itself first
if (!await isSafeUrl(pageUrl)) { // isSafeUrl from SSRF12-001 fix
throw Object.assign(new Error('Blocked page URL'), { code: 'SSRF_BLOCKED' });
}
const res = await fetch(pageUrl, {
redirect: 'manual', // validate redirect target before following
signal: AbortSignal.timeout(5000),
});
const html = await res.text();
const $ = cheerio.load(html);
const ogImage = $('meta[property="og:image"]').attr('content');
if (!ogImage) return null;
// Resolve relative og:image URLs against the page origin
const resolvedOgImage = new URL(ogImage, pageUrl).toString();
// Validate og:image URL — https:// only + DNS IP check
if (!await isSafeUrl(resolvedOgImage)) {
// Log but don't throw — just omit the image from the preview
return { imageBuffer: null, url: pageUrl };
}
const imgRes = await fetch(resolvedOgImage, {
redirect: 'error',
signal: AbortSignal.timeout(5000),
});
const contentType = imgRes.headers.get('content-type') ?? '';
if (!contentType.startsWith('image/')) return { imageBuffer: null, url: pageUrl };
const imgBuffer = Buffer.from(await imgRes.arrayBuffer());
return { imageBuffer: imgBuffer, url: pageUrl };
}
Detection with SkillAudit
SkillAudit's SA-SKL-SSRF12 rule set detects image-library SSRF through data-flow analysis tracing user-supplied URL parameters through sharp(), sharp.metadata(), canvas.loadImage(), Jimp.read(), and common link-preview library calls. The static pass flags any call where the URL argument has a taint source from request parameters, request body fields, or query string without an intervening IP-range validation function. The active probe submits a skill with a known-safe image URL and a known-internal URL and measures whether the internal URL triggers an HTTP request from the sandbox's server IP — confirming exploitability beyond what static analysis can prove. See also SA-SKL-SSRF11 for DNS rebinding bypass patterns that defeat simple IP-range checks.
Run SA-SKL-SSRF12 on your skill: Paste your MCP skill's GitHub URL at skillaudit.dev to get a full scan. The free tier covers public repositories and returns a shareable security badge.
| Finding | Severity | Vulnerable pattern | Fix |
|---|---|---|---|
SSRF12-001 | Critical | sharp(userUrl).metadata() — libvips fetches URL; targets IMDS at 169.254.169.254 for IAM key exfil | Download with validated fetch() + DNS IP check; pass temp file path to sharp — never the URL |
SSRF12-002 | Critical | canvas.loadImage(userUrl) — HTTP GET fires even when canvas render fails; probes internal services | Pre-download with DNS validation; pass Buffer to loadImage(buffer) — no URL reaches node-canvas |
SSRF12-003 | High | Jimp.read(userUrl) — follows 301 redirects to RFC1918 targets; initial DNS check bypassed | got: { followRedirect: false } in jimp options + DNS IP check on origin URL before read |
SSRF12-004 | High | og:image scraper fetches file:///etc/passwd or IMDS URL from attacker-controlled page metadata | Validate og:image URL: https:// only + DNS IP check before fetch; omit image on validation failure |