Skip to main content
Menu
Advisories

Server-Side Request Forgery (SSRF) in sparql_query / fetch-based request paths via unvalidated redirects and DNS rebinding

GHSA-38F8-M897-JM7WPublished Updated GitHub

Description

The project implements a strong SSRF defense for its primary CKAN request path: the Node branch of makeCkanRequest builds an http/https Agent from createSsrfSafeLookup, which re-resolves the hostname, rejects when any resolved address is private/internal, and pins the socket to the validated IP — correctly defeating DNS rebinding.

The sparql_query tool does not use that path. querySparqlEndpoint uses the global fetch() and guards it with a single up-front check, assertHostnameResolvesSafe(url.hostname). That check:

  1. validates only the original hostname, while fetch follows HTTP redirects by default (redirect: "follow") and never re-validates redirect targets; and
  2. resolves the name once, independently of the resolution fetch performs when it actually connects (a time-of-check/time-of-use gap enabling DNS rebinding).

As a result, a caller-supplied endpoint_url can be used to reach internal-only services and cloud metadata endpoints (e.g. http://169.254.169.254/), exfiltrating their responses back through the tool output.

Affected code

src/tools/sparql.ts:

export async function querySparqlEndpoint(endpointUrl, query) {
  validateServerUrl(endpointUrl);
  const url = new URL(endpointUrl);
  if (url.protocol !== "https:") throw new Error("Only HTTPS endpoints are allowed");
  // SSRF: block hostnames that resolve to private/internal addresses (DNS-name bypass)
  await assertHostnameResolvesSafe(url.hostname);   // <-- checks ORIGINAL host only, once
  ...
  response = await fetch(endpointUrl, { method: "POST", ... });  // <-- follows redirects, re-resolves DNS

src/utils/http.ts — the guard fails open on any resolution error:

export async function assertHostnameResolvesSafe(hostname) {
  let addresses;
  try { addresses = await dnsMod.promises.lookup(hostname, { all: true }); }
  catch { return; }                    // <-- DNS error => no check performed
  for (const a of addresses) if (isBlockedIp(a.address)) throw ...;
}

The same fetch-without-pinning pattern is used by the Workers branch of makeCkanRequest and by the MQA fetch in src/tools/quality.ts.

Impact

On Node deployments an attacker who can supply tool arguments (directly, or by influencing an LLM/agent that drives the MCP server — and, in the network-exposed Express transport that advertises no authentication, any unauthenticated client) can:

  • reach internal network services not otherwise reachable from outside;
  • read cloud instance metadata (e.g. AWS IMDS 169.254.169.254), which can expose IAM credentials;
  • use the server as a request proxy against internal HTTP endpoints, with the response body returned in the tool result.

The CKAN_ALLOWED_DOMAINS allowlist does not mitigate this: it is enforced in validateServerUrl on the CKAN path, and even there only against the initial hostname — querySparqlEndpoint accepts arbitrary HTTPS endpoints by design.

Scope note (CVSS): scored with S:C because the vulnerable server is used to pivot to a different security authority (internal/metadata services). On Cloudflare Workers the platform blocks internal egress, so that deployment is not exploitable via this path.

Proof of concept

See poc/redirect-ssrf-poc.mjs and REPRODUCE.md. The PoC reproduces the exact guard sequence of querySparqlEndpoint; for a genuine public attacker host all three guards pass, and the redirect is followed to a simulated internal metadata service whose secret body is returned to the caller.

$ node poc/redirect-ssrf-poc.mjs
Response body returned to the MCP tool:
  SECRET-IAM-CREDENTIALS-aws-metadata-body

RESULT: VULNERABLE — redirect followed to the internal target;
        its response was exfiltrated back through the SPARQL tool.

Remediation

Route the fetch-based paths through the same protection already used by the axios path. Concretely, any of:

  1. Disable automatic redirects on these fetch calls (redirect: "manual") and, for each 3xx, re-run validateServerUrl + assertHostnameResolvesSafe on the Location before following it (bounded hop count).
  2. Pin to a validated IP. Resolve the host, verify every address with isBlockedIp, then connect to the literal IP (custom undici dispatcher / lookup) so the socket cannot be rebound — mirroring createSsrfSafeLookup.
  3. For sparql_query specifically, following redirects is unnecessary; redirect: "error" closes the redirect vector outright, and pinning closes the rebinding vector.

Additionally, assertHostnameResolvesSafe should fail closed (reject) when DNS resolution errors, rather than returning and letting the request proceed.

Affected versions

References

GitHub · ondata/ckan-mcp-server