Server-Side Request Forgery (SSRF)
Server-Side Request Forgery (SSRF)
CWE-918 · High severity · Updated November 6, 2026
What it is
CWE-918 exists when an application fetches a URL supplied (directly or indirectly) by an attacker, without sufficient validation of the destination. An attacker uses this to probe internal services, exfiltrate cloud-metadata credentials (AWS IMDS, GCP metadata), reach databases or admin panels not exposed to the internet, or proxy traffic through the application.
Why it matters
SSRF was the root cause of the 2019 Capital One breach (100 million customer records exfiltrated via AWS IMDS abuse). It debuted on the OWASP Top 10 as A10:2021 and was consolidated under A01:2025 Broken Access Control in the current edition. Modern cloud environments make SSRF especially dangerous because instance-metadata services can return temporary IAM credentials to a simple local request unless IMDSv2 is enforced.
Common patterns
- User-supplied URLs passed to fetch, axios, requests.get, urllib.urlopen, http.Get.
- Image, document, or video preview features that fetch a URL the user provides.
- Webhook delivery to user-configured destinations without allowlist validation.
- Server-side OAuth or OpenID-Connect redirect_uri handling that fetches the discovery document.
- PDF generation or screenshot services where the user supplies the URL to render.
Languages affected
Python, JavaScript, TypeScript, Java, Go, Ruby
What Deva detects
Deva flags fetch, axios.get/post/request, requests.get, urllib.request.urlopen, http.Get, http.NewRequest, java.net.URL.openConnection, RestTemplate.exchange, and similar calls when the URL argument traces to a user-controlled source.
Example
Vulnerable
app.get('/preview', async (req, res) => {
const response = await fetch(req.query.url)
res.send(await response.text())
})Fixed
import { URL } from 'url'
import dns from 'dns/promises'
const ALLOWED_HOSTS = new Set(['example.com', 'images.example.com'])
// Private, shared, loopback, link-local, documentation, benchmark and multicast ranges.
const BLOCKED_RANGES = [
['0.0.0.0', 8], ['10.0.0.0', 8], ['100.64.0.0', 10], ['127.0.0.0', 8],
['169.254.0.0', 16], ['172.16.0.0', 12], ['192.0.0.0', 24], ['192.0.2.0', 24],
['192.168.0.0', 16], ['198.18.0.0', 15], ['198.51.100.0', 24], ['203.0.113.0', 24],
['224.0.0.0', 3],
]
const toInt = (ip) => ip.split('.').reduce((n, part) => n * 256 + Number(part), 0)
const inRange = (ip, [base, bits]) => {
const size = 2 ** (32 - bits)
return Math.floor(toInt(ip) / size) === Math.floor(toInt(base) / size)
}
async function isPublicAddress(hostname) {
// IPv4 only: this sample does not validate IPv6 ranges.
const records = await dns.lookup(hostname, { all: true, family: 4 })
return records.every(({ address }) => !BLOCKED_RANGES.some((r) => inRange(address, r)))
}
app.get('/preview', async (req, res) => {
let target
try { target = new URL(req.query.url) } catch { return res.status(400).send('Bad URL') }
if (!['http:', 'https:'].includes(target.protocol)) return res.status(400).send('Bad protocol')
if (target.username || target.password || target.port) return res.status(400).send('Bad URL')
if (!ALLOWED_HOSTS.has(target.hostname)) return res.status(403).send('Host not allowed')
try {
if (!(await isPublicAddress(target.hostname))) return res.status(403).send('Private IP')
// Redirects could otherwise send the request to an internal address.
const response = await fetch(target.toString(), { redirect: 'error' })
res.type('text/plain').send(await response.text())
} catch {
res.status(502).send('Fetch failed')
}
})The vulnerable version fetches whatever URL the user supplies. On an instance that allows IMDSv1, an attacker pointing it at http://169.254.169.254/latest/meta-data/iam/security-credentials/ exfiltrates AWS IAM credentials. The fix combines a protocol allowlist, a hostname allowlist, a DNS check against private and reserved IPv4 ranges, and a refusal to accept credentials, custom ports, or redirects. It also returns the response as plain text, so fetched HTML cannot run on your origin. The hostname allowlist does the main work. The DNS check is only a second layer: fetch resolves the name again, so it does not stop DNS rebinding. If you must accept arbitrary hosts, pin the validated IP in the connection or use a dedicated egress proxy with explicit allow-rules.
Where this fits in OWASP Top 10
- A01 Broken Access ControlAuthorization that fails to enforce who can do what.
Compliance framework references
These references explain how the weakness relates to control topics. They do not mean Deva offers evaluation for every framework listed. CMMC evaluation and SPRS scoring are currently unavailable. See the FAQ for offered frameworks and preview status. Deva provides code-level evidence for your assessment, without certifying compliance.
| Framework | Controls |
|---|---|
| OWASP Top 10:2025 | A01:2025 Broken Access Control |
| NIST 800-53 Rev 5 | SC-7 Boundary Protection, SI-10 Information Input Validation |
| CMMC L2 | SC.L2-3.13.1 Boundary protection |