{"canonical_url":"https://engineer.company/glossary/ssrf/","content_markdown":"# SSRF\n\n## What it is\n\nSSRF, short for server-side request forgery, is the attack in which someone\nhands a server a URL and the server goes and fetches it on their behalf, from\nwherever the server happens to sit. The Common Weakness Enumeration catalogues\nit as CWE-918 and describes the flaw by what the code fails to do: it takes a\nURL from an upstream component, retrieves whatever the URL points at, and never\nmakes sure the request is going to the destination it was meant for. The\nattacker changes nothing in the server's code. They supply an address, and the\nserver's position in the network does the rest.\n\nThat position is the whole point. A server in a data centre or a cloud account\ncan usually reach things a visitor on the internet cannot: an admin panel bound\nto an internal address, a database port, a monitoring dashboard, a metadata\nservice. The CWE entry spells out what follows. The server becomes a proxy for\nthe attacker, it can be made to scan ports on hosts in the internal network, and\nURL schemes such as `file://`, `gopher://` and `tftp://` can read documents on\nthe machine itself or give the attacker more control over what the request\ncontains. CWE places SSRF under a broader weakness, CWE-441, the unintended\nproxy or \"confused deputy\": a component with privileges doing work for someone\nwho has none.\n\nThe feature that opens the door is usually an ordinary one. The OWASP prevention\ncheat sheet names two typical cases: an avatar image the application downloads\nfrom a URL the user typed, and webhook or callback URLs that users register so\nthe application can call them later. Link previews and import-from-URL buttons\nbelong to the same family, as does any feature in which the server follows an\naddress that someone else wrote. CWE's own title spells the term Server-Side\nRequest Forgery, with capitals, and the entry lists an older name for the same\nthing, XSPA, short for Cross Site Port Attack.\n\n## Why it matters\n\nOWASP added SSRF to its Top 10 in 2021, as A10, and not because of volume. Its\ndata showed a relatively low incidence rate, but the category was the top pick\nof the community survey, and its exploit and impact ratings were above average.\nOWASP's explanation is that fetching a URL has become a routine feature of web\napplications, and that cloud services and more complex architectures make the\nconsequences more severe. In the 2025 edition SSRF no longer has a category of\nits own: CWE-918 is named among the notable weaknesses of A01:2025, Broken\nAccess Control, the category at the top of the list. MITRE's ranking points the\nsame way, with CWE-918 on the CWE Top 25 Most Dangerous Software Weaknesses in\nevery year from 2021 to 2025.\n\nThe reason is that SSRF walks straight through the defences teams lean on most.\nOWASP's description stresses that the attack works even when the application\nsits behind a firewall, a VPN or a network access control list, because the\nrequest leaves from inside them. Its example scenarios are a tour of what sits\nbehind that perimeter: mapping internal hosts and open ports from connection\nresults or the time a connection takes, reading local files such as\n`file:///etc/passwd`, talking to internal services such as\n`http://localhost:28017/`, and abusing those services to go further, as far as\nremote code execution or denial of service.\n\nCloud metadata is the scenario that turns a nuisance into a breach. OWASP notes\nthat most cloud providers keep instance metadata at `http://169.254.169.254/`,\nan address in the 169.254.0.0/16 block that IANA's special-purpose registry\nlists as link local. On Amazon EC2, the instance metadata service at that\naddress is also where software on the instance retrieves AWS security\ncredentials for the role attached to it. A server that will fetch any URL for\nanyone can be asked to fetch those.\n\nThe pattern keeps finding new homes. The CWE entry's recent examples include an\nLLM toolkit that fetched arbitrary image URLs, a flaw that attackers were\nalready using to scan ports in April 2026 (CVE-2026-33626), and an LLM\napplication framework whose URL retriever could be steered to local addresses\nwith a crafted `Location` header (CVE-2024-3095). An agent that browses the web\nfor a user is, from the network's point of view, a server fetching URLs that\nsomeone else chose.\n\n## What it looks like in practice\n\nTake a chat application at `app.example.com` that shows a preview card when\nsomeone pastes a link. The browser sends the URL to the server, and the server\nfetches the page to read its title and image:\n\n```http\nPOST /api/link-preview HTTP/1.1\nHost: app.example.com\nContent-Type: application/json\n\n{\"url\": \"https://news.example.org/2026/10/harbour-reopens\"}\n```\n\nThat is the feature working. Now the same request with another URL, the one the\nAWS documentation uses to list instance metadata:\n\n```http\nPOST /api/link-preview HTTP/1.1\nHost: app.example.com\nContent-Type: application/json\n\n{\"url\": \"http://169.254.169.254/latest/meta-data/\"}\n```\n\nIf the server runs on EC2 with the older IMDSv1 still allowed, it sends that\nrequest from inside the instance, the metadata service answers, and whatever the\npreview code passes back lands with the attacker. Nothing was injected and\nnothing crashed. The server did exactly what it was built to do, for the wrong\naddress.\n\nA destination check starts with where the request would actually go, after the\nname has been resolved, rather than at the text of the URL. In Python, the\nstandard library's `ipaddress` module uses IANA's special-purpose registries to\nclassify whether an address is global, excluding direct loopback, private,\nlink-local, shared and documentation addresses. The following helper illustrates\nthat classification, not a complete SSRF defence. A deployment must also limit\nrequests to eligible unicast destinations and account for address translation\nsuch as NAT64: on a network with a translating gateway, an address classified\nas global may still reach a blocked embedded IPv4 destination. The helper's\nclassification test is:\n\n```python\nimport ipaddress\nimport socket\nfrom urllib.parse import urlsplit\n\nALLOWED_SCHEMES = {\"http\", \"https\"}\n\n\ndef resolve_public(url: str) -\u003e tuple[str, int, list[str]]:\n    parts = urlsplit(url)\n    if parts.scheme not in ALLOWED_SCHEMES or not parts.hostname:\n        raise ValueError(\"scheme or host not allowed\")\n    port = parts.port or (443 if parts.scheme == \"https\" else 80)\n    infos = socket.getaddrinfo(parts.hostname, port, type=socket.SOCK_STREAM)\n    addresses = sorted({info[4][0] for info in infos})\n    for address in addresses:\n        if not ipaddress.ip_address(address).is_global:\n            raise ValueError(f\"{address} is not a public address\")\n    return parts.hostname, port, addresses\n```\n\nEvery address the name resolves to has to pass, not just the first. The fetch\nthen connects to one of those validated addresses, while still sending the\noriginal host name in the `Host` header and using it for TLS certificate checks,\nwith redirects switched off. Letting the HTTP client resolve the name a second\ntime would undo the check. That is the shape the OWASP cheat sheet describes for\nthe hard case, webhooks, where users choose the destinations and no allow list\ncan name them in advance. Where the destinations are known, an allow list of\nexact host names narrows things further, though the cheat sheet is clear that\nthe resolved addresses still need the same test.\n\nApplication checks are one layer. Our write-up on\n[building email with failover and delivery logging](/portfolio/built-email-with-failover-and-delivery-logging/)\nnotes that the send path goes through an SSRF-protected client with a 30-second\ntimeout. Behind the application, OWASP's network-layer advice still applies: put\nthe code that fetches remote resources in its own network segment and give it\nfirewall rules that deny by default, so a missed check meets a closed door.\n\n## Where it goes wrong\n\n**Deny lists and pattern matching.** A filter that rejects URLs containing\n`127.0.0.1`, `localhost` or `169.254.169.254` has already lost. POSIX\n`inet_addr()` accepts an IPv4 address in one to four parts, each in decimal,\noctal or hexadecimal, so to any parser that follows those rules `2852039166` and\n`0xa9.0xfe.0xa9.0xfe` are both the metadata address. The CWE entry lists a CVE\nin which octal and hexadecimal forms slipped past a check written for decimal\nand defeated an SSRF protection (CVE-2016-4029). OWASP's Top 10 entry is blunt\nabout it: \"Do not mitigate SSRF via the use of a deny list or regular\nexpression.\" Decide on the resolved address, as above, and allow rather than\ndeny.\n\n**Checking once and connecting later.** Validating the host name and then\nletting the HTTP client look it up again leaves a gap. With DNS rebinding, the\nattacker's name answers with a public address for the check and an internal one\nfor the connection. Connect to the exact address you validated, and apply the\nsame policy to retries and fallback connections, which the OWASP cheat sheet\ncalls out by name.\n\n**Following redirects.** The validated URL answers with a redirect to\n`http://169.254.169.254/` or to a `file://` URL, and the client follows it\nwithout asking. The CWE entry's examples include a URL-downloading library that\nfollowed redirects to `file://` and `scp://` URLs (CVE-2009-0037). Turn\nredirects off, or treat every hop as a new URL that goes through the whole check\nagain.\n\n**Allowing every scheme.** A client that also speaks `file`, `gopher` or `dict`\nhands an attacker local files, or far more control over what reaches an internal\nservice than an HTTP request allows. The OWASP cheat sheet lists those schemes\namong the ones a second request can use. Allow `http` and `https` only, on the\nports the feature needs.\n\n**Two parsers, two hosts.** The OWASP cheat sheet shows how one string can name\ntwo different hosts. In `http://good.example\\@bad.example`, a parser that\nfollows the WHATWG URL Standard handles the backslash like a forward slash, so\nthe path starts there and the host is `good.example`, while Python's `urlsplit`\ntakes everything before the last `@` as user information and returns\n`bad.example`. When one component validates and another fetches, they can\ndisagree about where the request goes. Parse once, and reject any URL whose host\nis not read the same way by every parser it passes through.\n\n**Returning the raw response.** A preview endpoint that passes the fetched body\nback to the caller turns an attack that could only infer what sits inside, from\nerrors and timings, into one that reads it. Return only what the feature needs,\nsuch as a title and an image reference, never the raw response, as OWASP's list\nadvises.\n\n**Leaving IMDSv1 on.** The AWS documentation says that by default both versions\nof the instance metadata service can be used. IMDSv2 first requires a session\ntoken, requested with a `PUT` to `/latest/api/token` and then sent in the\n`X-aws-ec2-metadata-token` header, and once IMDSv2 is required\n(`httpTokens=required`), IMDSv1 stops working. The OWASP cheat sheet calls\nIMDSv2 a defence-in-depth mechanism that mitigates some instances of SSRF, not\nall of them. Require IMDSv2 on every instance, and fix the application anyway.\n\n**A flat network.** When the fetching service can reach the database, the admin\npanel and the metadata service, every missed check is total. Apply OWASP's\nnetwork-layer controls: segmentation, \"deny by default\" firewall rules for\ninternal traffic, and logs of accepted and blocked flows so a probe shows up.\n\n## Further reading\n\n- [CWE-918: Server-Side Request Forgery (SSRF)](https://cwe.mitre.org/data/definitions/918.html)\n  — the weakness entry: consequences, the confused-deputy parent and observed\n  CVEs.\n- [OWASP Top 10:2021: A10 Server Side Request Forgery (SSRF)](https://owasp.org/Top10/2021/A10_2021-Server-Side_Request_Forgery_%28SSRF%29/)\n  — why the category was added, network and application controls, and four\n  attack scenarios.\n- [OWASP Cheat Sheet Series: Server Side Request Forgery Prevention](https://cheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html)\n  — allow lists, connecting only to validated addresses, parser disagreement and\n  the webhook case.\n- [OWASP Top 10:2025: A01 Broken Access Control](https://owasp.org/Top10/2025/A01_2025-Broken_Access_Control/)\n  — where CWE-918 sits in the 2025 edition.\n- [Amazon EC2: Access instance metadata for an EC2 instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html)\n  — IMDSv1 and IMDSv2, the token request and how to tell whether IMDSv2 is\n  required.\n- [Python documentation: ipaddress](https://docs.python.org/3/library/ipaddress.html)\n  — `is_global` and the IANA registries it follows.\n\n\u003chttps://engineer.company/glossary/ssrf/\u003e\n","date_modified":"2026-11-09T21:50:25Z","description":"How server-side request forgery turns a server's own URL fetching against the network behind it, why cloud metadata raises the stakes, and the checks that hold.","formats":{"gemtext":"https://engineer.company/glossary/ssrf/index.gmi","gopher":"https://engineer.company/glossary/ssrf/gophermap","html":"https://engineer.company/glossary/ssrf/","json":"https://engineer.company/glossary/ssrf/index.json","markdown":"https://engineer.company/glossary/ssrf/index.md","pdf":"https://engineer.company/glossary/ssrf/index.pdf"},"kind":"page","language":"en","title":"What is SSRF?","url":"https://engineer.company/glossary/ssrf/","version":1}