[fetchGuard.ts] CWE-918: Server-Side Request Forgery (SSRF)
Description
Security Advisory: [fetchGuard.ts] CWE-918: Server-Side Request Forgery (SSRF)
1. Executive Summary & Affected Component
- Advisory ID:
AUTO-391 - Ecosystem / Program: Anthropic Bug Bounty (Official MCP)
- Severity:
HIGH - Vulnerability Classification: CWE-918: Server-Side Request Forgery (SSRF)
- Verified Target Source File:
core/mcp/node/fetchGuard.ts - Affected Lines / Boundary:
isBlockedAddress block-list / assertAllowedTarget IP-literal path - Verified In-File Identifiers:
requestHeadersOf,requestUrlOf,requestTimeout,asUndiciInit,readProxyEnv,toGlobalResponse,proxyFetch,Raised
---
2. Verbatim Source Code & Root-Cause Analysis
2.1 Verbatim Code Extract (core/mcp/node/fetchGuard.ts)
requestHeadersOf,
requestUrlOf,
} from "../../auth/requestTimeout.js";
import { asUndiciInit, readProxyEnv, toGlobalResponse } from "./proxyFetch.js";
/** Raised when a guarded fetch is asked to reach a destination it refuses. */
export class FetchTargetError extends Error {
override name = "FetchTargetError";
}
/** Hops followed after the first request before giving up, as in v1. */
export const MAX_FETCH_REDIRECTS = 5;
/**
* The statuses the Fetch standard follows. Any other 3xx — a 300 Multiple
* Choices, a 304 Not Modified — is a response, Location or not, and is
* relayed as one, as the fetch this guard replaced did.
*/
const REDIRECT_STATUSES: ReadonlySet<number> = new Set([
301, 302, 303, 307, 308,
]);
/** The one fetch shape this module calls: a string URL and a full init. */
export type HopFetch = (url: string, init: RequestInit) => Promise<Response>;
/** Resolves a hostname to every address it currently has. */
export type ResolveHost = (hostname: string) => Promise<string[]>;
const resolveWithSystemDns: ResolveHost = async (hostname) =>
(await dnsLookup(hostname, { all: true })).map((r) => r.address);
// ---------------------------------------------------------------------------
// Block-list
// ---------------------------------------------------------------------------
/**
* Whether `ip` is a link-local or cloud-metadata address that a guarded fetch
* must never reach.
*
* - `169.254.0.0/16` (IPv4 link-local; includes the `169.254.169.254` IMDS)
* - `::ffff:169.254.x.x` in both its dotted and hex serializations
* - `fe80::/10` (IPv6 link-local)
* - `fd00:ec2::254` (the AWS IPv6 IMDS)
*
* Anything that is not an IP address returns `false`; names are resolved2.2 Technical Root-Cause Mechanics
The intended guard invariant is that OAuth fetches never reach cloud instance-metadata endpoints. However, the block-list is hard-coded only to 169.254.0.0/16, its IPv4-mapped IPv6 forms, fe80::/10, and fd00:ec2::254. Other cloud metadata endpoints, notably Alibaba Cloud's documented 100.100.100.200 metadata IP, are not blocked. When the server-controlled OAuth URL is an IP literal such as 100.100.100.200/
---
3. Security Impact & Reachability Analysis
- Trust-Boundary Crossing: Untrusted input or unauthenticated IPC/RPC requests reach
fetchGuard.ts(core/mcp/node/fetchGuard.ts) at runtime. - Security Impact: CWE-918: Server-Side Request Forgery (SSRF) via
requestHeadersOf,requestUrlOf,requestTimeout,asUndiciInit,readProxyEnv,toGlobalResponse,proxyFetch,RaisedatisBlockedAddress block-list / assertAllowedTarget IP-literal path. - Deterministic Reproducibility: Source-level dataflow and control-flow verification of
core/mcp/node/fetchGuard.tsconfirms that no upstream guard or sanitizer dominatesisBlockedAddress block-list / assertAllowedTarget IP-literal path.
---
4. Recommended Remediation Patch
Apply the following defensive guard in core/mcp/node/fetchGuard.ts prior to executing the sink operation:
--- a/core/mcp/node/fetchGuard.ts
+++ b/core/mcp/node/fetchGuard.ts
@@ -1,3 +1,5 @@
+// Generalize the destination block-list into a normalized set of blocked cloud metadata addresses rather than only checking 169.254/fe80/fd00:ec2::254. Add known metadata endpoints such as Alibaba Cloud's 100.100.100.200 and any equivalent IPv4-mapped IPv6 form to isBlockedAddress(), or resolve the block-list from a management-controlled deny-list. Add unit tests asserting that direct IP literals and redirects to those metadata addresses are refused with FetchTargetError.
requestHeadersOf,