A10: Server-Side Request Forgery (SSRF)
You'll learn how attackers exploit server-initiated requests to access resources they shouldn't reach.
What Is SSRF?
Server-Side Request Forgery occurs when an attacker manipulates your server into making HTTP requests to unintended destinations. Instead of attacking your application directly, the attacker uses your server as a proxy to reach targets that would normally be inaccessible—like internal services, cloud metadata endpoints, or protected resources.
Think of it like tricking a hotel concierge into retrieving items from staff-only areas. You can't go back there yourself, but if you can convince the concierge to fetch something on your behalf, you've bypassed the restriction.
How SSRF Works
Many applications legitimately fetch external resources based on user input—downloading images from URLs, validating webhooks, or integrating with third-party APIs. Attackers exploit this by providing malicious URLs:
- Internal network access:
http://localhost:6379/might hit your Redis server - Cloud metadata endpoints:
http://169.254.169.254/latest/meta-data/exposes AWS credentials - Port scanning: Testing
http://internal-host:22reveals open services - File system access:
file:///etc/passwdon some implementations
The server makes these requests with its own network privileges, bypassing firewalls and access controls that would block external attackers.
Prevention Strategies
Following the principle of least privilege and minimize attack surface:
- Validate and sanitize all user-provided URLs
- Use allowlists for permitted domains/protocols
- Block requests to private IP ranges and localhost
- Disable unnecessary URL schemes (
file://,gopher://) - Implement network segmentation
- Never trust user input when initiating server-side requests
Key Takeaway: SSRF turns your server into an unwitting accomplice—always validate URLs and restrict what your server can fetch, treating internal networks as potential attack targets rather than trusted zones.