Server-Side Request Forgery turns your own API into an attacker's proxy. Any endpoint that takes a URL or hostname and fetches it, to import an image, render a webhook, preview a link, or pull a remote document, can be tricked into requesting a resource the attacker chooses. Because the request originates from your server, it arrives with your server's network position and trust, reaching places the attacker never could directly.

The premise is a feature almost every API has: "give me a URL and I'll fetch it." Profile-picture import, document conversion, webhook delivery, URL preview, all take a location and retrieve it server-side. SSRF is the attacker supplying a location that points inward: at internal services, at localhost, or at the cloud metadata endpoint. The server, trusting the input, makes the call and often hands the response straight back.

The cloud metadata prize

SSRF: Making the API Attack Its Own NetworkDiagram with these labels, in reading order: ATTACKER; API FETCHER; INTERNAL; inward URL; server-side fetch; requests; Attacker; URL-taking endpoint; webhook / import; Destination allow-list; Server fetches; with its trust; 169.254.169.254; metadata / internal; No destination; allow-list; Returns IAM; credentials.ATTACKERAPI FETCHERINTERNALinward URLserver-side fetchrequestsAttackerURL-taking endpointwebhook / importDestination allow-listServer fetcheswith its trust169.254.169.254metadata / internalNo destinationallow-listReturns IAMcredentials
Give the API a URL and it fetches inward, straight at the credential endpoint.

In cloud environments SSRF is especially dangerous because of the instance metadata service, reachable at a fixed link-local address from inside the workload. Left unprotected, it can return temporary credentials for the instance's role. An SSRF that reaches it can exfiltrate keys that grant access to storage, databases, and more, escalating a single fetch feature into a full cloud compromise. OWASP's own example for this risk is a webhook test request aimed at a cloud metadata service that exposes credentials.

A webhook URL aimed at the metadata servicePOST /api/webhooks { "callback_url": "http://169.254.169.254/latest/meta-data/iam/security-credentials/" }

Modern SSRF is rarely a naive open fetch. Attackers defeat weak filters with redirects (a permitted URL that 302s to an internal one), DNS rebinding (a hostname that resolves to a safe address on validation and an internal one on fetch), alternate IP encodings, and blind variants where the response never returns but timing or out-of-band callbacks confirm the request landed.

Why it's API7: APIs are connectors by nature: they fetch, integrate, and call out constantly. That makes URL-taking endpoints ubiquitous, and every one is a potential pivot from the public internet into your internal network.

Containing the fetch

  • Allow-list destinations, don't block-list them. Permit only the specific schemes, hosts, and ports the feature legitimately needs; deny everything else. Block-lists of internal ranges are easy to bypass.
  • Validate after DNS resolution, and pin it. Resolve the hostname, check the resulting IP against the allow-list, and fetch that same address, closing the rebinding and redirect gaps between check and use.
  • Disable redirects, or re-validate each hop. A safe first URL must not be allowed to bounce the request to an internal target.
  • Protect cloud metadata. Require the hardened, token-based metadata mode (IMDSv2 on AWS) and give the workload the least IAM privilege it can function with, so a leaked credential is worth as little as possible.
  • Isolate the fetcher and don't reflect raw responses. Run outbound fetches from a segmented network with no route to sensitive internal services, and avoid returning fetched content verbatim to the caller.

An API's trust boundary covers both who calls it and what it calls in turn. Every outbound request an API can be steered to make is part of its attack surface, and the ones that matter are easy to lose track of, buried in an integration a previous team wired up. You cannot lock down the fetches you don't know your API is capable of making.

Primary source. API7:2023 Server Side Request Forgery, OWASP API Security Project.

Back to the knowledge baseRequest an assessment