Nexus Void Research
SSRF, Server-Side Request Forgery, CWE-918, Cloud Metadata, IMDSv2, DNS Rebinding, OWASP Top 10, How-to
How to Prevent SSRF Attacks: Validation Code and Checklist
How to prevent SSRF: allow-list hosts, block private and metadata IPs after DNS, stop rebinding and redirects, use IMDSv2 and restrict egress.
To prevent SSRF (server-side request forgery), never let user input decide where your server sends a request. Allow-list the exact hosts and schemes you need, resolve the hostname and block private, loopback and link-local addresses (including the 169.254.169.254 cloud metadata address) before connecting, re-check every redirect, use IMDSv2 on AWS, and restrict outbound traffic at the network layer as a backstop.
SSRF happens when an application fetches a URL that an attacker controls, such as a webhook URL, an image link or a "fetch preview" feature, and the attacker points it at something only the server can reach: internal admin panels, databases, or the cloud metadata service that hands out credentials. MITRE tracks it as CWE-918, and it had its own category in the 2021 OWASP Top 10. This guide shows how to block it with code you can copy. It is not theoretical: 11 of the CVEs CISA added to its Known Exploited Vulnerabilities catalog in 2026 were SSRF (CWE-918), per our 2026 vulnerability statistics.
Where does SSRF come from?
Any feature where the server makes a request based on user input:
Feature | Example input |
|---|---|
Webhooks |
|
URL previews and unfurling | Paste a link, server fetches the title and image |
Import from URL | "Import CSV from URL", "upload avatar from link" |
PDF and screenshot generators | HTML containing |
Integrations and proxies | User-configured API base URLs |
File parsers | XML with external entities, SVG with remote references |
LLM agents with a browsing or fetch tool | A prompt that tells the agent to fetch an internal URL |
The most damaging target is the cloud metadata endpoint. On AWS, Google Cloud and Azure, a request from the server to 169.254.169.254 can return instance details and, on older configurations, temporary credentials for the server's role.
Step 1: Avoid fetching user-supplied URLs where you can
The strongest fix is design. If users only need to pick from known integrations, store the base URL on the server and let users choose an ID, not a URL. If you only need an image, accept an upload instead of a link.
Step 2: Allow-list hosts and schemes
When you must fetch a user-supplied URL, allow only what you need:
Schemes:
httpsonly (orhttpandhttps). Rejectfile:,gopher:,ftp:,dict:and anything else.Hosts: an explicit allow-list where possible, such as your customers' verified webhook domains.
Ports: 443 (and 80 if needed). Block everything else.
Parse the URL with a proper URL parser, never with string matching, because tricks like https://allowed.com@evil.com and https://allowed.com.evil.com defeat naive checks.
Step 3: Resolve the hostname and block internal addresses
A deny-list of hostnames is not enough, because an attacker can register a domain that resolves to 127.0.0.1 or 10.0.0.5. Resolve the name yourself and check every IP address it returns:
Python's ipaddress flags cover the ranges that matter:
Range | What it is |
|---|---|
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 | Private networks |
127.0.0.0/8, ::1 | Loopback |
169.254.0.0/16, fe80::/10 | Link-local, including 169.254.169.254 cloud metadata |
fc00::/7 | IPv6 unique local addresses |
0.0.0.0/8 | "This network", reaches localhost on many systems |
Step 4: Connect to the IP you checked
Checking the IP and then letting the HTTP client resolve the name again opens a gap: DNS rebinding. The attacker's DNS server answers with a public IP for your check and a private IP for the real request. Close it by connecting to the exact IP you validated, or by using an HTTP client or egress proxy that validates the resolved address at connection time. In Node.js, libraries such as ssrf-req-filter or a custom lookup function on the HTTP agent do this; in Python, a custom transport adapter can pin the validated address.
Step 5: Do not follow redirects blindly
An allowed URL can redirect to http://169.254.169.254/. Either disable redirects, or follow them manually and run the full validation from steps 2 to 4 on every hop:
Also set short timeouts and a maximum response size, so SSRF cannot be used to tie up your workers or download huge files.
Step 6: Protect the cloud metadata service
AWS: require IMDSv2 on every instance. It needs a session token obtained with a
PUTrequest, which most SSRF bugs cannot send. Set the hop limit to 1 so containers on the host cannot reach it.Google Cloud: the metadata server requires the
Metadata-Flavor: Googleheader, which blocks simple SSRF; still block the address in application code.Azure: the Instance Metadata Service requires a
Metadata: trueheader; the same advice applies.Least privilege: give the server's cloud role only the permissions it needs, so stolen credentials are worth less.
Step 7: Restrict outbound traffic at the network
Application checks can have bugs. Add a backstop: run URL-fetching features through an egress proxy or in a separate service with firewall rules that block private ranges and the metadata address, and allow only the outbound destinations it needs.
Step 8: Never return raw responses
Do not send the fetched response body or detailed error messages back to the user. Return only what the feature needs, such as a page title or a pass or fail result. Full responses turn a "blind" SSRF into one that leaks internal data directly.
SSRF prevention checklist
Check | Done when |
|---|---|
Feature redesigned where possible | Users choose IDs, not URLs |
Scheme and port allow-list | Only http(s), only expected ports |
Host allow-list | Explicit list for webhooks and integrations |
IP validation after DNS | Private, loopback, link-local and metadata ranges blocked |
Rebinding closed | Connection goes to the validated IP |
Redirects controlled | Disabled, or every hop re-validated |
Cloud metadata hardened | IMDSv2 required, hop limit 1, least-privilege roles |
Egress restricted | Network blocks internal ranges from fetchers |
Responses filtered | No raw bodies or detailed errors returned |
SSRF is one of the patterns to trace in every security code review; it is also a form of broken access control, since the server ends up reaching resources the user never should.
How does ARGUS find SSRF?
SSRF is a data-flow bug: user input travels from a request into an outbound HTTP call. ARGUS is built to follow that path.
Rule-based static analysis flags known SSRF patterns, such as request libraries called with values taken from the request.
An AI taint-analysis pass follows source-to-sink data flow across files in Python, JavaScript, TypeScript, Ruby, Go, Java and PHP, and shows the path as a file-by-file timeline, so you can see exactly where input reaches the outbound call.
An AI pass for LLM applications looks for the OWASP Top 10 for LLM risks, including excessive agency, which covers agents with fetch tools that can be pointed at internal URLs.
Every AI finding is challenged by independent verifiers and dropped if it cannot be substantiated.
Fix pull requests: Assign to Agent adds the validation, verifies it with a build and a re-scan, and opens a pull request for you to review and merge.
Limits: AI passes run when AI scanning is enabled. ARGUS analyses your code; it does not test your network egress rules or cloud metadata settings. See ARGUS SAST, or scan a repository free.
Frequently asked questions
What is SSRF?
Server-side request forgery is a vulnerability where an attacker makes your server send a request to a destination they choose, usually by supplying a URL to a feature like a webhook or link preview. Because the request comes from your server, it can reach internal services and cloud metadata the attacker cannot reach directly.
How do you prevent SSRF?
Avoid fetching user-supplied URLs where possible. Otherwise allow-list schemes, hosts and ports, resolve the hostname and block private, loopback, link-local and metadata addresses, connect only to the validated IP, re-check redirects, require IMDSv2 on AWS, restrict outbound traffic and never return raw responses.
Why is 169.254.169.254 important for SSRF?
It is the link-local address of the cloud instance metadata service on AWS, Google Cloud and Azure. A server request to it can return instance details and, on older configurations, temporary credentials for the server's cloud role, which is why SSRF in the cloud can lead to a full account compromise.
Is a hostname deny-list enough to stop SSRF?
No. Attackers can use domains that resolve to internal IPs, alternative IP encodings, IPv6 forms, redirects and DNS rebinding to bypass name-based lists. Resolve the hostname, validate every returned IP address against blocked ranges, and connect to the IP you validated.
What is DNS rebinding in SSRF?
DNS rebinding is a bypass where a domain returns a safe public IP when you validate it and a private IP moments later when your HTTP client resolves it again. Prevent it by connecting directly to the IP address you checked, or by validating the address at connection time in the client or an egress proxy.
Does IMDSv2 prevent SSRF?
It does not prevent SSRF, but it blocks the most damaging outcome on AWS. IMDSv2 requires a session token fetched with a PUT request and custom header, which most SSRF bugs cannot send, so attackers cannot easily read instance credentials. Still validate URLs in your code.
How do you test for SSRF?
Find every feature that fetches a URL, then try internal targets such as http://127.0.0.1, http://169.254.169.254/, private IPs, alternative encodings, and a URL on a domain you control that redirects internally. Use an external callback service to detect blind SSRF, where no response is returned.
Can LLM agents cause SSRF?
Yes. An agent with a web-fetch or browsing tool can be instructed, through prompt injection, to request internal URLs. Apply the same URL validation to agent tools as to any other server-side fetch, and give agents only the network access they need.
DATA SOURCES
CWE-918: https://cwe.mitre.org/data/definitions/918.html ; OWASP Top 10: https://owasp.org/Top10/ ; CISA KEV 2026 additions (Nexus Void analysis)