HIGH Authentication & Authorization

Ssrf in APIs

What is SSRF?

Server-Side Request Forgery (SSRF) is a web security vulnerability that allows an attacker to induce a server to make HTTP requests to arbitrary destinations of the attacker's choosing. Unlike client-side attacks where the victim's browser makes the request, SSRF occurs when the server itself initiates outbound requests based on user-supplied input.

The vulnerability typically arises when an API or web application accepts a URL or hostname as input and uses it to fetch data without proper validation. The server then makes a request to the supplied destination, potentially exposing internal services, cloud metadata endpoints, or other sensitive resources that aren't directly accessible from the public internet.

Common SSRF vectors include:

  • Image processing APIs that fetch remote images
  • Webhook integrations that call user-supplied URLs
  • API endpoints that proxy requests to third-party services
  • Documentation or preview features that render external content

The severity of SSRF depends on what the server can access. If the server can reach internal network resources, the impact can be devastating, including data exfiltration, internal service enumeration, and even cloud account compromise through metadata service access.

How SSRF Affects APIs

APIs are particularly vulnerable to SSRF because they often need to interact with external services as part of their normal operation. When an API accepts URLs or domain names as parameters for legitimate functionality, it creates an attack surface that malicious actors can exploit.

Attackers can leverage SSRF to:

  • Access internal APIs and services behind the firewall
  • Reach cloud metadata services (like AWS EC2 metadata at 169.254.169.254)
  • Enumerate internal network structure and services
  • Exfiltrate data through DNS queries or HTTP requests
  • Abuse the server's trust relationships with internal services

Consider a payment processing API that accepts a callback URL. An attacker could supply an internal network address like http://192.168.1.100:8080, causing the server to make a request to an internal service. If that service is unauthenticated or uses weak authentication, the attacker gains unauthorized access.

Cloud environments introduce additional risks. Many cloud providers expose metadata services at predictable IP addresses that contain sensitive information like IAM roles, API keys, and instance credentials. A successful SSRF attack against a cloud-hosted API could lead to complete account compromise.

SSRF can also be used for reconnaissance. By observing response times and error messages, attackers can map internal network structures and identify running services, even when direct access is blocked.

How to Detect SSRF

Detecting SSRF vulnerabilities requires both static analysis and dynamic testing. From a code review perspective, look for patterns where user input is used to construct outbound requests without proper validation.

Key indicators in code include:

// Vulnerable patterns to search for:fetch(url)
http.get(userSuppliedUrl)
axios.get(request.query.url)
// Any function that makes HTTP requests using untrusted input

Dynamic testing involves attempting to make the server request various destinations:

  • Public IP addresses that you control to verify requests are being made
  • Internal IP ranges (10.x, 172.16-31.x, 192.168.x)
  • Localhost and loopback addresses
  • Cloud metadata service endpoints
  • Protocol smuggling attempts (file://, gopher://, ftp://)

middleBrick automatically scans for SSRF vulnerabilities by testing unauthenticated API endpoints with a comprehensive set of payloads designed to trigger outbound requests to restricted destinations. The scanner attempts requests to internal IP ranges, localhost, and cloud metadata endpoints while monitoring for signs of successful exploitation such as response content or timing differences.

The tool also checks for inadequate URL validation, missing protocol restrictions, and improper handling of special characters that could bypass basic filters. middleBrick's black-box approach means it can identify SSRF vulnerabilities without requiring access to source code or internal network details.

Prevention & Remediation

Preventing SSRF requires a defense-in-depth approach with multiple validation layers. The most effective strategy combines input validation, network controls, and architectural considerations.

Input Validation: Implement strict allowlists for acceptable destinations. Rather than trying to block known-bad inputs, define what's explicitly allowed:

function validateUrl(url, allowedDomains) {
const urlObj = new URL(url);
if (!allowedDomains.includes(urlObj.hostname)) {
throw new Error('Domain not allowed');
}
if (urlObj.protocol !== 'https:') {
throw new Error('Only HTTPS allowed');
}
// Block private IP ranges
const privateRanges = [
/^127\./,
/^10\./,
/^172\.(1[6-9]|2[0-9]|3[0-1])\./,
/^192\.168\./,
/^169\.254\./,
/^0\.0\.0\.0/,
/^255\.255\.255\.255/
];
if (privateRanges.some(regex => regex.test(urlObj.hostname))) {
throw new Error('Private IP address not allowed');
}
return true;
}

Network Controls: Implement outbound firewall rules to restrict the server's ability to reach internal networks. Use a proxy or API gateway that enforces destination policies.

Architectural Mitigations: Consider using a separate microservice with limited network access for external requests. This isolates the impact if that service is compromised.

Cloud-Specific Measures: In cloud environments, use VPC endpoints or interface endpoints instead of direct internet access for cloud services. Implement IAM roles with minimal permissions and use instance metadata access controls.

Response Handling: Ensure the application handles errors consistently and doesn't leak information about whether a request succeeded or failed based on the destination.

For APIs that must accept arbitrary URLs, consider using a headless browser in a sandboxed environment with network restrictions, or implement a request signing mechanism where the client must prove knowledge of a secret before the server will make external requests.

Real-World Impact

SSRF vulnerabilities have led to some of the most severe security breaches in recent years. In 2019, a critical SSRF vulnerability in Venmo's API allowed attackers to access internal network services and potentially compromise user data. The flaw existed in an endpoint that accepted URLs for preview generation.

Cloud metadata service SSRF attacks have been particularly impactful. Attackers have used SSRF to access AWS metadata services and extract temporary credentials, leading to complete account takeovers. The 2020 Capital One breach involved SSRF as one component of a multi-step attack that exposed data from over 100 million customers.

Social media platforms have repeatedly suffered SSRF issues. Twitter (now X) had an SSRF vulnerability that allowed attackers to access Direct Messages and user data through a vulnerable analytics endpoint. Facebook has also experienced SSRF issues that could have been used to access internal systems.

The financial impact is significant. Beyond data breaches, SSRF can be used for cryptocurrency mining by making the server access mining pools, or for spam distribution by abusing the server's IP reputation. The 2021 Uber breach involved SSRF combined with social engineering to access internal tools and data.

SSRF remains in the OWASP API Top 10 (as API2:2019) because it's both common and severe. The combination of widespread API adoption, increasing cloud usage, and the difficulty of perfect input validation makes SSRF a persistent threat that requires ongoing vigilance.

Frequently Asked Questions

What's the difference between SSRF and open redirect vulnerabilities?
While both involve untrusted URLs, they have different targets and impacts. Open redirects affect the client (browser) by sending users to malicious sites, while SSRF affects the server by making it request arbitrary destinations. SSRF is generally more severe because servers often have access to internal resources that browsers cannot reach, and SSRF can lead to data exfiltration, internal service compromise, and cloud account takeover.
Can SSRF be completely prevented with input validation?
Input validation is necessary but not sufficient. Attackers can use various encoding tricks, DNS rebinding, and IDN homograph attacks to bypass basic filters. A comprehensive SSRF prevention strategy should combine input validation with network-level controls (firewalls, VPC restrictions), architectural isolation (separate services for external requests), and cloud-specific protections (metadata service access controls). Defense in depth is essential.
How does middleBrick detect SSRF vulnerabilities?
middleBrick uses black-box scanning to test API endpoints for SSRF vulnerabilities without requiring credentials or source code access. The scanner attempts requests to internal IP ranges, localhost, cloud metadata endpoints, and other restricted destinations while monitoring for signs of successful exploitation. It also checks for inadequate URL validation and missing protocol restrictions. The tool provides a security risk score and actionable findings with severity levels and remediation guidance.