Server-Side Request Forgery via Host Header
What you'll learn: How attackers can exploit Host header injection to trigger SSRF attacks by manipulating internal routing and backend service connections.
The Core Idea
When a web application trusts the Host header to construct internal URLs or route requests to backend services, an attacker can manipulate this header to make the server send requests to unintended destinations. This combines Host header injection with SSRF—turning the vulnerable server into a proxy for attacking internal systems that would normally be unreachable from the internet.
How It Works
Many applications use the Host header value to build absolute URLs for internal API calls, microservice communication, or routing decisions. For example:
GET /api/data HTTP/1.1
Host: attacker.com
If the backend constructs an internal request like http://{Host}/internal/resource, it might actually request http://attacker.com/internal/resource instead of the intended internal service. Worse, an attacker can point to internal addresses:
Host: localhost:6379
Host: 192.168.1.50:8080
Host: internal-admin.local
Real-World Attack Scenario
Imagine an application that fetches user avatars from an internal CDN using: http://{Host}/cdn/avatar.jpg. By injecting Host: 169.254.169.254 (AWS metadata service), the attacker could force the server to fetch cloud credentials. Or using Host: internal-redis:6379, they might interact with backend databases directly.
Detection and Defense
Look for applications that:
- Build internal URLs using the Host header
- Route requests to microservices based on Host
- Make backend API calls using Host-derived values
Validate the Host header against a strict whitelist of allowed values and never trust it for constructing backend URLs.
Key Takeaway: Host header injection becomes SSRF when the server uses the attacker-controlled Host value to make internal requests, potentially exposing internal services and sensitive data to external attackers.