Course contentsShow
← Security
Lesson 1033 of 3,05221. Web Security - API SecurityFree lesson

API7:2023 - Server Side Request Forgery (SSRF)

Recognizing how APIs can be exploited to make unauthorized requests to internal resources or external systems.

API7:2023 - Server Side Request Forgery (SSRF)

What You'll Learn

You'll learn how attackers exploit APIs to make your server send requests on their behalf, potentially accessing internal resources or external systems you never intended to reach.

The Core Vulnerability

Server Side Request Forgery (SSRF) occurs when an API accepts user-supplied URLs or network locations and fetches them server-side without proper validation. Instead of the client making a direct request, the API server makes it—giving attackers access to resources from the server's privileged position.

Why APIs Are Vulnerable

Modern APIs often need to fetch external resources: webhooks, image downloads, URL previews, or data imports. When an API accepts a URL parameter like ?fetchUrl=https://example.com/image.jpg, attackers can substitute internal addresses the server can reach but external users cannot.

Common Attack Scenarios

Internal Resource Access: An attacker changes a URL parameter to http://localhost:6379 to probe internal Redis databases, or http://169.254.169.254/latest/meta-data/ to steal cloud provider credentials.

Port Scanning: By submitting various internal IP addresses and ports, attackers map your internal network through timing differences and error messages.

External System Abuse: APIs might be tricked into attacking third-party systems, making requests that appear to come from your legitimate server's IP address.

The Danger Zone

The server's network position is the weapon. It can access:

  • Internal APIs without authentication
  • Cloud metadata services
  • Database administration interfaces
  • File systems via file:// protocol
  • Other internal services never meant for external access

Think of it like giving someone your house keys to fetch your mail—except they can access every room you can, not just the mailbox.

Key Takeaway: SSRF exploits the trust and network access your API server has, turning it into an unwitting proxy for attackers to reach internal or restricted resources. Always validate and restrict destination URLs.