Host Header Injection Vulnerabilities
You'll learn how attackers exploit applications that blindly trust the Host header to manipulate URLs, hijack password resets, and poison caches.
The Problem with Trusting the Host Header
In lesson 1124, you learned the Host header tells a web server which domain the client is requesting. Many applications trust this value implicitly and use it to generate URLs—for example, in password reset emails, redirect URLs, or cached content.
Think of it like a GPS that accepts any address someone tells it without verification. If your app builds a password reset link like https://{Host}/reset?token=abc123, an attacker controlling the Host header can inject their own domain.
How the Attack Works
Password Reset Poisoning: An attacker requests a password reset for victim@example.com but injects Host: evil.com. The application generates and emails: https://evil.com/reset?token=abc123. When the victim clicks it, their reset token goes to the attacker's server.
Cache Poisoning: If a cache uses only the URL path as a key (not the Host), an attacker can inject Host: evil.com, causing the cache to store poisoned responses that redirect all users to the malicious site.
URL Generation: Applications using the Host header to build absolute URLs for redirects, API endpoints, or scripts can be manipulated to point users elsewhere.
Common Vulnerable Patterns
# Application code (vulnerable)
reset_url = f"https://{request.headers['Host']}/reset/{token}"
send_email(user.email, reset_url)
The app never validates that Host matches its actual domain.
Key Takeaway: Never trust the Host header for security-critical operations like URL generation or password resets—always validate it against a whitelist of known-good domains or use a hardcoded base URL from configuration.