The Plain Picture#
You can't enter a company's private office. But the receptionist will fetch "any document you name". So you ask her to fetch the contents of the manager's safe. She's inside; she can reach it.
A library lets you request a book by shelf path — "Fiction/Novels/book.txt". You ask for "Fiction/../../Staff-Only/salaries.txt".
The Real Names#
SSRF (Server-Side Request Forgery) — tricking a server into making requests on your behalf to places only the server can reach: internal services, private IP ranges (Networking 1: Addresses and Routing Ch 6), and especially the cloud metadata service at
169.254.169.254, which can hand out the server's cloud credentials.Path traversal — using
../in a file name to escape the intended folder (The Linux Command Line Ch 2).
Under the Hood#
SSRF in StudyBuddy: a feature "import notes from a URL" fetches whatever URL the user gives:
POST /import {"url": "http://169.254.169.254/latest/meta-data/iam/security-credentials/"}
→ the server fetches it from INSIDE the cloud network and returns the result
→ the attacker receives temporary cloud credentials for StudyBuddy's serverThis exact pattern caused one of the largest bank data breaches in the US (Capital One, 2019).
SSRF defences:
only allow the URL schemes and hosts you need (an allow-list);
resolve the host name and block private, loopback and link-local addresses — and re-check after redirects;
in AWS, require IMDSv2 (the metadata service version that needs a session token obtained with a PUT request, which simple SSRF can't do);
run fetchers in an isolated network with no route to internal services (least privilege at the network level).
Path traversal:
GET /files?name=../../etc/passwd
server does: open("/app/uploads/" + name) → /app/uploads/../../etc/passwd → /etc/passwdDefences: never use user input directly as a path; store uploads under random generated names and keep the original name only as data; if you must use a name, resolve the full path and check it's still inside the allowed folder.
Check yourself
3 questionsWhat is SSRF, and why is 169.254.169.254 a prime target?
Show answerHide answer
Making the server send requests for the attacker to places only the server can reach; the cloud metadata service there can expose the server's credentials.
Name three SSRF defences.
Show answerHide answer
Allow-list destinations; block private/loopback/link-local IPs after resolving (and after redirects); IMDSv2; network isolation.
How does path traversal work, and how do you prevent it?
Show answerHide answer
../ sequences in a user-supplied path escape the intended directory; use generated file names, or resolve the path and verify it
stays inside the allowed folder.