Advanced·20 min read·Updated 2026-10-15

Server-Side Request Forgery (SSRF): Cloud Exploits & Complete Defense Guide

Original WeSecureX guide for authorized testing of sites you own. Linked Sources are citations for verification - not copied articles. Ads are not served on this page.

Server-Side Request Forgery (SSRF, CWE-918) occurs when a vulnerable web application receives an arbitrary URL from an untrusted client and fetches data from that URL using server-side network privileges without adequate validation. In cloud environments like AWS, GCP, and Azure, SSRF is routinely weaponized to steal temporary IAM role credentials from Instance Metadata Services (IMDS at `http://169.254.169.254`), query internal Consul or Kubernetes etcd databases, and pivot through private VPC networks. Traditional blocklists (such as filtering `127.0.0.1` or `localhost`) fail against octal encodings, IPv6 transitions, and DNS rebinding attacks. In this guide, we break down SSRF mechanics, demonstrate bulletproof network isolation, and explore automated detection using the [WeSecureX Website Vulnerability Scanner](/scanner), [Surface Reconnaissance](/surface), and [Vulnerabilities Catalog](/vulnerabilities).

Quick Answer

Defend against SSRF by enforcing strict protocol allowlists (restricting to https://), resolving DNS records *prior* to connection to verify the target IP is not within private CIDR ranges (RFC 1918, link-local, or loopback), enforcing AWS IMDSv2 with session tokens, and isolating egress traffic using a forward proxy.

Key Takeaways
  • SSRF allows remote attackers to force servers to make unauthorized requests to internal networks.
  • Cloud metadata services (169.254.169.254) are the highest-value target for SSRF exploitation.
  • String-based IP blocklists are easily bypassed via integer encoding, octal notation, and DNS rebinding.
  • IMDSv2 and pre-request IP validation provide complete defense against cloud credential extraction.
Visual Diagram · SSRF Attack Flow vs. Defense-in-Depth Architecture
1

1. Untrusted Client Payload

Attacker provides URL pointing to internal metadata: http://169.254.169.254/latest/meta-data/iam/security-credentials/.

2

2. Naive Egress Fetch

Vulnerable web application makes a server-side cURL or fetch request behind the firewall.

3

3. IMDS Credential Theft

Server receives AWS IAM session keys and echoes them back to the attacker.

4

4. WeSecureX Egress Guard

DNS resolution hook blocks non-routable IPs and enforces AWS IMDSv2 token mandates.

ShareShare on XLinkedIn

1. SSRF Attack Mechanics: From Webhook Parsers to AWS IMDS Theft

WeSecureX Website Scanner detecting SSRF and cloud metadata access vulnerabilities
WeSecureX Website Scanner detecting SSRF and cloud metadata access vulnerabilitiesWeSecureX Platform View

Applications that generate social media link previews, convert customer invoices to PDF, fetch user avatars from external URLs, or execute custom webhooks are prime targets for Server-Side Request Forgery (SSRF). The fundamental vulnerability stems from a misplaced trust model: the backend application accepts a client-provided URL and issues an outbound HTTP request using its own trusted server-side network interface.

Because the web server is positioned inside an organization's private Virtual Private Cloud (VPC) or local area network, it possesses implicit network trust that external users lack. An attacker who controls the destination URL can trick the web server into communicating with internal services that were never intended to face the public internet. In AWS environments, the most devastating attack vector targets the Instance Metadata Service (IMDS) listening on the non-routable link-local IPv4 address http://169.254.169.254.

Under legacy IMDSv1, any simple HTTP GET request without authentication headers returns the active IAM role name and temporary security credentials (AccessKeyId, SecretAccessKey, and SessionToken). Armed with these stolen keys, an attacker bypasses all perimeter firewalls, connects directly to the AWS API, and downloads proprietary S3 bucket archives, dumps RDS database backups, and escalates privileges across the cloud estate. Discover your domain's exposed API endpoints using the WeSecureX Surface Monitor and review vulnerability remediation workflows in our guide on The Anatomy of a Data Breach.

http
# Checking AWS IMDSv1 for IAM role credentials via SSRF probe
GET /api/preview?url=http://169.254.169.254/latest/meta-data/iam/security-credentials/web-server-role HTTP/1.1
Host: vulnerable-app.example.com

# Server Response Leaking Temporary Cloud Credentials
HTTP/1.1 200 OK
Content-Type: application/json

{
  "Code": "Success",
  "LastUpdated": "2026-10-15T08:00:00Z",
  "Type": "AWS-HMAC",
  "AccessKeyId": "ASIAIOSFODNN7EXAMPLE",
  "SecretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
  "Token": "IQoJb3JpZ2luX2VjEEXAMPLE...",
  "Expiration": "2026-10-15T14:30:00Z"
}

2. Common SSRF Bypass Techniques: Decimal IPs, Octals, IPv6 & DNS Rebinding

WeSecureX Vulnerabilities Catalog detailing SSRF bypass patterns and CWE-918 severity metrics
WeSecureX Vulnerabilities Catalog detailing SSRF bypass patterns and CWE-918 severity metricsWeSecureX Platform View

Securing applications against SSRF vulnerabilities requires recognizing that naive input validation routines - such as string matching for "127.0.0.1", "localhost", or "169.254.169.254"- are trivially defeated. Operating system network stacks, URL parsers, and DNS resolvers support diverse address notations, alternative numeric encodings, and protocol quirks that allow attackers to bypass regex blocklists while still resolving to internal addresses.

POSIX-compliant socket libraries (inet_aton) support integer, octal, and hexadecimal IP representations. For instance, the IPv4 loopback address 127.0.0.1 can be represented as a 32-bit dword integer http://2130706433/, in octal as http://0177.0000.0000.0001/, or in hexadecimal notation as http://0x7f.0x00.0x00.0x01/. When a web application validates the URL using a standard string check, the regex fails to match "127.0.0.1", but when the HTTP client resolves the host, the operating system kernel decodes the integer notation directly to loopback.

In dual-stack cloud environments, applications that only validate IPv4 addresses can be bypassed using IPv6 notations like http://[::1]/ or IPv4-mapped IPv6 addresses like http://[::ffff:127.0.0.1]/. Furthermore, DNS Rebinding exploits the time-of-check to time-of-use (TOCTOU) gap between URL validation and data fetching. An attacker configures an authoritative nameserver for a custom domain (e.g., rebind.attacker.com) with a Time-To-Live (TTL) of 0 seconds. On the first lookup during input validation, the nameserver responds with a harmless public IP (passing the whitelist). Milliseconds later, when the server-side HTTP client issues the actual request, the nameserver responds with 169.254.169.254, bypassing the check entirely. Explore vulnerability signatures and severity benchmarks in the WeSecureX Vulnerabilities Catalog and discover unknown perimeter assets with the Attack Surface Recon Engine.

Bypass VectorPayload ExampleDecoded Destination IPSecurity Evasion Mechanism
Decimal IP Encodinghttp://2130706433/127.0.0.1Integer IP notation bypasses naive string filters entirely
Hexadecimal IPhttp://0x7f000001/127.0.0.1Hex notation parsed natively by POSIX inet_aton resolvers
Octal IP Encodinghttp://0177.0.0.01/127.0.0.1Octal representation with leading zeros defeats regex filters
IPv6 Loopbackhttp://[::1]/ or http://[0:0:0:0:0:0:0:1]/::1 (localhost)Bypasses IPv4-only filter checks in dual-stack networks
DNS Rebinding Attackhttp://rebind.attacker.comTTL 0 swaps from public IP to 169.254.169.254Time-of-check to time-of-use (TOCTOU) race condition
Enclosed Alphanumericshttp://①⑥⑨.②⑤④.⑯⑨.②⑤④/169.254.169.254Unicode normalization exploits in modern web framework parsers
Redirect Bypasseshttps://attacker.com/302-redirectHTTP 302 -> http://169.254.169.254Client library follows HTTP redirect without re-validating target

3. Production Remediation: Safe DNS Resolution, IMDSv2 & Network Isolation

WeSecureX Security Tools Directory showing network and DNS security utilities
WeSecureX Security Tools Directory showing network and DNS security utilitiesWeSecureX Platform View

Neutralizing SSRF requires a defense-in-depth engineering architecture rather than superficial string sanitization. The definitive remediation workflow consists of three mandatory architectural controls: strict protocol allowlisting, pre-flight DNS IP resolution with non-routable CIDR validation, and cloud metadata hardening via AWS IMDSv2.

To defeat DNS rebinding and IP encoding bypasses, applications must resolve the requested hostname before establishing an HTTP connection. Every resolved IP address must be inspected against a strict denylist of private, link-local, loopback, and reserved CIDR blocks (including RFC 1918 ranges, 127.0.0.0/8, 169.254.0.0/16, and IPv6 equivalents). Once validated, the connection must be pinned directly to the verified IP address, preventing secondary DNS resolutions.

In AWS environments, transition all EC2 instances and ECS tasks to IMDSv2 by executing aws ec2 modify-instance-metadata-options --http-tokens required. IMDSv2 requires callers to initiate a PUT request with a custom header (X-aws-ec2-metadata-token-ttl-seconds) to obtain a cryptographic session token before accessing metadata. Because typical SSRF vectors only permit simple GET requests without custom headers, IMDSv2 neutralizes cloud credential theft at the infrastructure hypervisor layer. Audit your public web applications with the WeSecureX Website Scanner and test your infrastructure for exposed services using our Open Port Scanner. Continuous scanning ensures that internal VPC gateways and microservices remain completely shielded from external request forgery.

bash
# Enforcing AWS IMDSv2 across EC2 instances to neutralize SSRF metadata theft
$ aws ec2 modify-instance-metadata-options \
    --instance-id i-0123456789abcdef0 \
    --http-tokens required \
    --http-endpoint enabled \
    --http-put-response-hop-limit 1

# Verifying IMDSv2 requirement
$ aws ec2 describe-instances --instance-ids i-0123456789abcdef0 \
    --query 'Reservations[*].Instances[*].MetadataOptions.HttpTokens'
[
    "required"
]

Apply it with WeSecureX

Add a hostname you own or are allowed to test, run a scan, and open the findings for that target. A confirmed result includes the request WeSecureX sent and the response the site returned, so you can reproduce it, fix it in your own application, and rescan the same host to confirm the issue is gone. WeSecureX is automated testing, not a manual penetration test, and a clean report is not a promise that every weakness is gone.

Checks that belong with this topic

  • Enforce strict protocol allowlist (allow only https://, block file://, gopher://, dict://).
  • Perform pre-flight DNS resolution and block all private RFC 1918, loopback, and link-local CIDR ranges.
  • Enforce AWS IMDSv2 (http-tokens: required) with a hop limit of 1 on all EC2 instances.
  • Disable automatic HTTP redirect following in server-side HTTP request libraries.
  • Audit application endpoints continuously using the WeSecureX Vulnerability Scanner.

Actionable Checklist

WeSecureX Platform · Scanner Engine

Automated Vulnerability Scanner

Launch targeted or full-domain security audits to detect OWASP Top 10 vulnerabilities automatically.

Includes: OWASP Top 10 automated test suites · Real-time severity scoring (CVSS v3.1) · Instant remediation code snippets

Frequently Asked Questions

IMDSv2 requires a session-oriented flow: clients must first send an HTTP PUT request with the header `X-aws-ec2-metadata-token-ttl-seconds` to acquire an ephemeral token, then include that token in subsequent GET requests. Typical SSRF flaws do not permit arbitrary PUT requests with custom headers, neutralizing exploitation.

If an application resolves a domain to verify its IP, and then passes the domain name to `fetch()` or `curl`, the HTTP client performs a second DNS lookup. An attacker's DNS server can return a public IP for the first check, and `127.0.0.1` for the second, bypassing validation entirely.

Reflected SSRF returns the HTTP response body of the forged request back to the attacker (allowing them to read metadata or internal web pages). Blind SSRF triggers requests without displaying response data, requiring out-of-band (OAST) DNS or HTTP monitoring to confirm exploitation.

Authoritative Sources & References

  • OWASP Server-Side Request Forgery Prevention Cheat SheetOWASP (official)
    View Source
  • AWS Documentation: Configuring the instance metadata service (IMDSv2)Amazon Web Services (official)
    View Source

Continue exploring related technical architecture and defensive guides

Security Research & Engineering Articles

All articles