Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(mcp-host): pin SSRF prefix boundaries in tests

Alfredo Lopezb8bb0a499134
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index 7f183a0de..6dff9be3d 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.477",
+ "version": "0.1.478",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.477",
+ "version": "0.1.478",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index fc186a3e8..df246a7d9 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.477",
+ "version": "0.1.478",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/agent/__tests__/taskExecutorCatalogBootstrap.integration.test.ts b/mcp-host/src/agent/__tests__/taskExecutorCatalogBootstrap.integration.test.ts
index 339017b65..893c3f84e 100644
--- a/mcp-host/src/agent/__tests__/taskExecutorCatalogBootstrap.integration.test.ts
+++ b/mcp-host/src/agent/__tests__/taskExecutorCatalogBootstrap.integration.test.ts
@@ -53,7 +53,7 @@ vi.mock('@modelcontextprotocol/sdk/client/sse.js', async () => {
// The SDK is mocked, so no real transport fetch runs; keep the SSRF guard off DNS.
vi.mock('../../core/net/ssrf', () => ({
SsrfBlockedError: class SsrfBlockedError extends Error {},
- resolvePinnedPublicIp: vi.fn(async () => '203.0.113.10'),
+ resolvePinnedPublicIp: vi.fn(async () => '93.184.216.34'),
}))
function remoteOauthUserServer(name = 'calendar'): McpServerInfo {
diff --git a/mcp-host/src/core/net/__tests__/ssrf.test.ts b/mcp-host/src/core/net/__tests__/ssrf.test.ts
index b0a77abad..f75e01908 100644
--- a/mcp-host/src/core/net/__tests__/ssrf.test.ts
+++ b/mcp-host/src/core/net/__tests__/ssrf.test.ts
@@ -23,6 +23,10 @@ function literalUrl(ip: string): URL {
return ip.includes(':') ? new URL(`http://[${ip}]/`) : new URL(`http://${ip}/`)
}
+function normalizedLiteralHost(ip: string): string {
+ return literalUrl(ip).hostname.replace(/^\[|\]$/g, '')
+}
+
const BLOCKED_SPECIAL_PURPOSE_ADDRESSES: readonly (readonly [string, string])[] = [
['100.64.0.1', 'CGNAT (RFC 6598)'],
['198.18.0.1', 'benchmarking (RFC 2544)'],
@@ -94,7 +98,7 @@ describe('resolvePinnedPublicIp', () => {
async (ip: string) => {
const outcome = resolvePinnedPublicIp(literalUrl(ip))
await expect(outcome).rejects.toBeInstanceOf(SsrfBlockedError)
- await expect(outcome).rejects.toThrow(`Target is a private IP (${ip})`)
+ await expect(outcome).rejects.toThrow(`Target is a private IP (${normalizedLiteralHost(ip)})`)
expect(resolve4).not.toHaveBeenCalled()
expect(resolve6).not.toHaveBeenCalled()
}
@@ -120,7 +124,7 @@ describe('resolvePinnedPublicIp', () => {
async (ip: string) => {
const outcome = resolvePinnedPublicIp(literalUrl(ip))
await expect(outcome).rejects.toBeInstanceOf(SsrfBlockedError)
- await expect(outcome).rejects.toThrow(`Target is a private IP (${ip})`)
+ await expect(outcome).rejects.toThrow(`Target is a private IP (${normalizedLiteralHost(ip)})`)
expect(resolve4).not.toHaveBeenCalled()
expect(resolve6).not.toHaveBeenCalled()
}
diff --git a/mcp-host/src/core/net/ssrf.ts b/mcp-host/src/core/net/ssrf.ts
index 19d44e02a..ca68a48e4 100644
--- a/mcp-host/src/core/net/ssrf.ts
+++ b/mcp-host/src/core/net/ssrf.ts
@@ -128,19 +128,16 @@ function formatIpv6Bytes(bytes: Uint8Array): string {
return groups.join(':')
}
-function isPrivateIpv4Octets(octets: readonly number[]): boolean {
- if (octets.length !== 4) return false
- return nonPublicAddresses.check(`${octets[0]}.${octets[1]}.${octets[2]}.${octets[3]}`, 'ipv4')
-}
-
/**
- * Non-public IPv4 prefixes required by the SSRF hardening scope. This is the
- * issue-required subset of the IPv4 exclusions in
- * deploy/base/public-egress-exceptions.yaml and the IANA range list used by
- * mcp-servers/web-search's fetch destination validator. Those policies also
- * exclude 192.31.196/24, 192.52.193/24, 192.88.99/24, and 192.175.48/24,
- * which are deliberately out of scope here; the three policies keep
- * distinct ranges by design.
+ * Non-public IPv4 prefixes in scope for the outbound HTTP guard: the legacy
+ * private/loopback/link-local ranges plus special-purpose ranges that must
+ * not be treated as public SSRF destinations. This is a deliberate subset
+ * of the IPv4 exclusions in deploy/base/public-egress-exceptions.yaml and
+ * the IANA range list used by mcp-servers/web-search's fetch destination
+ * validator. Those policies also exclude 192.31.196/24, 192.52.193/24,
+ * 192.88.99/24, and 192.175.48/24, which stay public here by design: they
+ * are relay/service blocks handled by egress policy rather than ranges this
+ * model-facing guard needs to classify as non-public.
*/
const NON_PUBLIC_IPV4_PREFIXES: readonly (readonly [address: string, prefix: number])[] = [
['0.0.0.0', 8], // "This network"
@@ -160,8 +157,11 @@ const NON_PUBLIC_IPV4_PREFIXES: readonly (readonly [address: string, prefix: num
]
/**
- * Canonical non-public IPv6 prefixes. ::/128 and ::1/128 are covered by the
- * IPv4-compatible delegation (their tails fall inside 0.0.0.0/8).
+ * Non-public IPv6 prefixes in scope for this change; this is not a complete
+ * IANA special-purpose list. Notably still public: 100::/64 (discard-only),
+ * 2001:1::/128, 2001:2::/48, 3fff::/20 (documentation), 5f00::/16, and
+ * ISATAP embeddings inside global prefixes. ::/128 and ::1/128 are covered
+ * by the IPv4-compatible delegation (their tails fall inside 0.0.0.0/8).
*/
const NON_PUBLIC_IPV6_PREFIXES: readonly (readonly [address: string, prefix: number])[] = [
['64:ff9b::', 96], // NAT64 (RFC 6052)
@@ -183,6 +183,11 @@ for (const [address, prefix] of NON_PUBLIC_IPV6_PREFIXES) {
nonPublicAddresses.addSubnet(address, prefix, 'ipv6')
}
+function isPrivateIpv4Octets(octets: readonly number[]): boolean {
+ if (octets.length !== 4) return false
+ return nonPublicAddresses.check(`${octets[0]}.${octets[1]}.${octets[2]}.${octets[3]}`, 'ipv4')
+}
+
/**
* Block private, metadata, multicast, reserved, and other special-purpose
* non-public IP ranges (SSRF defense).
diff --git a/mcp-host/src/core/safety/__tests__/safety.test.ts b/mcp-host/src/core/safety/__tests__/safety.test.ts
index 6109e5969..fecfd954b 100644
--- a/mcp-host/src/core/safety/__tests__/safety.test.ts
+++ b/mcp-host/src/core/safety/__tests__/safety.test.ts
@@ -26,6 +26,15 @@ describe('BasicSafety', () => {
expect(result.errors.join(' ')).toMatch(/kubernetes|cluster/i)
})
+ it('blocks special-purpose non-public http_request targets before execution', () => {
+ const result = safety.validateToolParams('http_request', {
+ url: 'http://100.64.0.1/',
+ })
+
+ expect(result.is_valid).toBe(false)
+ expect(result.errors).toContain('Non-public target "100.64.0.1" is blocked')
+ })
+
it('blocks shell_exec attempts to read service account tokens', () => {
const result = safety.validateToolParams('shell_exec', {
command: 'cat /var/run/secrets/kubernetes.io/serviceaccount/token',
@@ -122,10 +131,7 @@ describe('BasicSafety', () => {
const s = new BasicSafety(() => [
{ name: 'OPENAI_API_KEY', value: 'totally-not-a-pattern-match-12345' },
])
- const result = s.sanitizeOutput(
- 'shell_exec',
- 'echoed key totally-not-a-pattern-match-12345'
- )
+ const result = s.sanitizeOutput('shell_exec', 'echoed key totally-not-a-pattern-match-12345')
expect(result.content).toContain('[REDACTED:OPENAI_API_KEY]')
expect(result.content).not.toContain('totally-not-a-pattern-match-12345')
@@ -162,9 +168,7 @@ describe('BasicSafety', () => {
})
it('reads from the provider on every call (hot reload)', () => {
- let entries: Array<{ name: string; value: string }> = [
- { name: 'TOK', value: 'rev-1-secret' },
- ]
+ let entries: Array<{ name: string; value: string }> = [{ name: 'TOK', value: 'rev-1-secret' }]
const s = new BasicSafety(() => entries)
const r1 = s.sanitizeOutput('shell_exec', 'echo rev-1-secret here')
diff --git a/mcp-host/src/core/safety/safety.ts b/mcp-host/src/core/safety/safety.ts
index 6322914e3..8870dee24 100644
--- a/mcp-host/src/core/safety/safety.ts
+++ b/mcp-host/src/core/safety/safety.ts
@@ -190,7 +190,7 @@ export class BasicSafety implements Safety {
}
if (hostname && isPrivateIp(hostname)) {
- errors.push(`Private or link-local target "${hostname}" is blocked`)
+ errors.push(`Non-public target "${hostname}" is blocked`)
}
for (const rule of BasicSafety.HTTP_BLOCKED_HOST_PATTERNS) {
diff --git a/mcp-host/src/core/tools/__tests__/shellAndHttp.test.ts b/mcp-host/src/core/tools/__tests__/shellAndHttp.test.ts
index 67a8b08e4..6bd717df9 100644
--- a/mcp-host/src/core/tools/__tests__/shellAndHttp.test.ts
+++ b/mcp-host/src/core/tools/__tests__/shellAndHttp.test.ts
@@ -242,6 +242,57 @@ describe('HttpRequestTool', () => {
expect(isPrivateIp('2002:808:808::')).toBe(true) // 6to4 form of 8.8.8.8
})
+ it('should pin exact prefix boundaries against over-blocking regressions', () => {
+ // Each group asserts an in-range boundary and the adjacent public
+ // neighbor for one prefix table entry. Widening a prefix or dropping a
+ // row must fail here, not merely survive review.
+ // fc00::/7
+ expect(isPrivateIp('fbff:ffff:ffff:ffff:ffff:ffff:ffff:ffff')).toBe(false)
+ expect(isPrivateIp('fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff')).toBe(true)
+ // fe80::/10
+ expect(isPrivateIp('fe7f:ffff:ffff:ffff:ffff:ffff:ffff:ffff')).toBe(false)
+ expect(isPrivateIp('febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff')).toBe(true)
+ // fec0::/10
+ expect(isPrivateIp('fe00::1')).toBe(false)
+ expect(isPrivateIp('fec0::1')).toBe(true)
+ expect(isPrivateIp('feff:ffff:ffff:ffff:ffff:ffff:ffff:ffff')).toBe(true)
+ // 2001::/32 (Teredo)
+ expect(isPrivateIp('2001:0:ffff:ffff:ffff:ffff:ffff:ffff')).toBe(true)
+ expect(isPrivateIp('2001:1::1')).toBe(false)
+ expect(isPrivateIp('2001:4860:4860::8888')).toBe(false)
+ // 2001:db8::/32 (documentation)
+ expect(isPrivateIp('2001:db7:ffff::1')).toBe(false)
+ expect(isPrivateIp('2001:db9::1')).toBe(false)
+ // 2002::/16 (6to4)
+ expect(isPrivateIp('2002:ffff:ffff:ffff:ffff:ffff:ffff:ffff')).toBe(true)
+ expect(isPrivateIp('2003::1')).toBe(false)
+ expect(isPrivateIp('2001:ffff::1')).toBe(false)
+ // 64:ff9b::/96 and 64:ff9b:1::/48 (NAT64 and local-use NAT64)
+ expect(isPrivateIp('64:ff9a:ffff::1')).toBe(false)
+ expect(isPrivateIp('64:ff9b:0:1::1')).toBe(false)
+ expect(isPrivateIp('64:ff9b:2::1')).toBe(false)
+ expect(isPrivateIp('64:ff9b:1:ffff:ffff:ffff:ffff:ffff')).toBe(true)
+ // ff00::/8
+ expect(isPrivateIp('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff')).toBe(true)
+ // IANA /24 boundaries and public neighbors.
+ expect(isPrivateIp('192.0.0.255')).toBe(true)
+ expect(isPrivateIp('192.0.1.1')).toBe(false)
+ expect(isPrivateIp('192.0.2.255')).toBe(true)
+ expect(isPrivateIp('192.0.3.1')).toBe(false)
+ expect(isPrivateIp('198.51.100.255')).toBe(true)
+ expect(isPrivateIp('198.51.101.1')).toBe(false)
+ expect(isPrivateIp('203.0.113.255')).toBe(true)
+ expect(isPrivateIp('203.0.114.1')).toBe(false)
+ expect(isPrivateIp('223.255.255.255')).toBe(false)
+ // Relay/service /24s deliberately remain public in this classifier;
+ // egress policy owns their handling. Pin that contract so any future
+ // divergence has to be an explicit decision.
+ expect(isPrivateIp('192.31.196.1')).toBe(false)
+ expect(isPrivateIp('192.52.193.1')).toBe(false)
+ expect(isPrivateIp('192.88.99.1')).toBe(false)
+ expect(isPrivateIp('192.175.48.1')).toBe(false)
+ })
+
const NEW_SPECIAL_PURPOSE_IPV4: readonly (readonly [string, string])[] = [
['100.64.0.1', '6440:1'],
['198.18.0.1', 'c612:1'],
@@ -274,5 +325,7 @@ describe('HttpRequestTool', () => {
expect(isPrivateIp('example.com')).toBe(false)
expect(isPrivateIp('sub.domain.example.com')).toBe(false)
expect(isPrivateIp('not-an-ip')).toBe(false)
+ expect(isPrivateIp('')).toBe(false)
+ expect(isPrivateIp(undefined as unknown as string)).toBe(false)
})
})
diff --git a/mcp-host/src/mcp/__tests__/managerCatalogBootstrap.test.ts b/mcp-host/src/mcp/__tests__/managerCatalogBootstrap.test.ts
index 4da6dd89e..cdd64890c 100644
--- a/mcp-host/src/mcp/__tests__/managerCatalogBootstrap.test.ts
+++ b/mcp-host/src/mcp/__tests__/managerCatalogBootstrap.test.ts
@@ -49,7 +49,7 @@ vi.mock('@modelcontextprotocol/sdk/client/sse.js', async () => {
// resolver is stubbed so these tests never touch DNS.
vi.mock('../../core/net/ssrf', () => ({
SsrfBlockedError: class SsrfBlockedError extends Error {},
- resolvePinnedPublicIp: vi.fn(async () => '203.0.113.10'),
+ resolvePinnedPublicIp: vi.fn(async () => '93.184.216.34'),
}))
function remoteOauthUserServer(name = 'gh'): McpServerInfo {
diff --git a/mcp-host/src/mcp/__tests__/managerConnectRequired.test.ts b/mcp-host/src/mcp/__tests__/managerConnectRequired.test.ts
index ff3bade1f..bacb4e611 100644
--- a/mcp-host/src/mcp/__tests__/managerConnectRequired.test.ts
+++ b/mcp-host/src/mcp/__tests__/managerConnectRequired.test.ts
@@ -89,7 +89,7 @@ vi.mock('@modelcontextprotocol/sdk/client/sse.js', () => ({
// only keeps import-time resolution offline.
vi.mock('../../core/net/ssrf', () => ({
SsrfBlockedError: class SsrfBlockedError extends Error {},
- resolvePinnedPublicIp: vi.fn(async () => '203.0.113.10'),
+ resolvePinnedPublicIp: vi.fn(async () => '93.184.216.34'),
}))
function httpError(status: number): () => Promise<never> {
diff --git a/mcp-host/src/mcp/__tests__/managerSharedGrantGate.test.ts b/mcp-host/src/mcp/__tests__/managerSharedGrantGate.test.ts
index 369ffd3b1..5a4e107ec 100644
--- a/mcp-host/src/mcp/__tests__/managerSharedGrantGate.test.ts
+++ b/mcp-host/src/mcp/__tests__/managerSharedGrantGate.test.ts
@@ -48,7 +48,7 @@ vi.mock('@modelcontextprotocol/sdk/client/sse.js', async () => {
// never touch DNS (the SDK is mocked, so its returned fetch is never invoked).
vi.mock('../../core/net/ssrf', () => ({
SsrfBlockedError: class SsrfBlockedError extends Error {},
- resolvePinnedPublicIp: vi.fn(async () => '203.0.113.10'),
+ resolvePinnedPublicIp: vi.fn(async () => '93.184.216.34'),
}))
function remoteOauthContextServer(name = 'remote-ctx'): McpServerInfo {