Detecting Host Header Injection & Open Redirects

Detection Host header injection
Detection Host header injection
By HOC Team  |  Updated: September 2026  |Read time: ~16 min

While Cross-Site Scripting (XSS) and SQL Injection often dominate security headlines, subtle logical flaws like Host Header Injection (HHI) and Open Redirects remain pervasive and highly exploitable. These vulnerabilities stem from a fundamental sin in web development: trusting user-controlled input to dictate server-side routing and URL generation.

Also See: Host Header Injection-Based Open Redirect

This guide provides a deep dive into the mechanics of these flaws, how they intersect, and the exact methodology security engineers and bug hunters use to find them. We will explore the deadly combination of host header injection open redirect attacks, how to test for them using Burp Suite and cURL, and how to permanently remediate them in your codebase.

📊 The Business Impact of Routing Flaws Open Redirects are the #1 enabler of credential phishing, while Host Header Injection can lead to Web Cache Poisoning and account takeovers via password reset poisoning. In bug bounty programs, a verified host header injection that leads to cache poisoning or an open redirect bypass consistently commands medium to high severity payouts due to their real-world exploitability.
1. The Mechanics: Host Headers & Redirects

To understand the vulnerabilities, we must first understand the HTTP mechanisms they abuse.

The HTTP Host Header

When a client makes an HTTP/1.1 request, it must include a Host header. This tells the web server (like Nginx or Apache) which virtual host should handle the request, especially when multiple domains share the same IP address.

GET /dashboard HTTP/1.1
Host: www.example.com

HTTP Redirects

Servers use 301 (Moved Permanently) or 302 (Found) status codes, accompanied by a Location header, to tell the browser to navigate to a different URL. If the application dynamically constructs this Location URL using unvalidated user input, an Open Redirect is born.

2. Host Header Injection (HHI) Deep Dive

Host Header Injection occurs when an application takes the user-supplied Host header and trusts it to generate absolute URLs, construct emails, or route traffic internally.

⚠
Common HHI Attack Vectors
  • Password Reset Poisoning: The app generates a reset link using the Host header. Attacker changes Host to evil.com. The victim receives an email with a link to evil.com/reset?token=xyz. The attacker captures the token and resets the victim's password.
  • Web Cache Poisoning: If a CDN or reverse proxy caches responses based on the Host header, an attacker can inject a malicious Host, poison the cache, and serve XSS payloads to all subsequent users.
  • Internal Routing Manipulation: The application uses the Host header to route requests to internal microservices. Injecting an internal hostname can lead to Server-Side Request Forgery (SSRF).
3. Open Redirects: Beyond the Basics

Open Redirects happen when an application includes a user-controllable URL in a redirect response without validating that the destination belongs to the application's own domain.

# Vulnerable Python (Flask) Example from flask import request, redirect @app.route('/login') def login(): # VULNERABLE: Directly trusting the 'next' parameter next_url = request.args.get('next') return redirect(next_url)

While parameter-based open redirects (?next=https://evil.com) are well known and often blocked by basic WAFs, advanced attackers look for header-based and path-based bypasses.

4. The Intersection: Host Header Injection Open Redirect

The most critical and often overlooked vulnerability occurs at the intersection of these two flaws: the host header injection open redirect chain. This happens when an application attempts to secure a redirect by checking if the URL is "relative" (starts with a /), but fails to account for the fact that the Host header can be manipulated to turn a relative URL into an absolute external redirect.

# Vulnerable Node.js (Express) Example const express = require('express'); const app = express(); app.get('/logout', (req, res) => { // DEVELOPER INTENT: Only allow relative redirects let redirectUrl = req.query.url || '/'; // WEAK CHECK: Only checks if it starts with a slash if (!redirectUrl.startsWith('/')) { redirectUrl = '/'; } // VULNERABILITY: req.protocol + req.get('host') is user-controlled! const fullUrl = req.protocol + '://' + req.get('host') + redirectUrl; res.redirect(fullUrl); });
⚠ The Exploit Scenario The developer thinks they are safe because redirectUrl must start with /. However, the attacker sends this request:

GET /logout?url=/ HTTP/1.1
Host: evil.com

The application constructs: http://evil.com/ and issues a 302 redirect. The host header injection open redirect chain is complete, bypassing the developer's allowlist logic entirely.
5. Detection & Testing Methodology

Detecting these flaws requires a mix of automated scanning and manual, logic-driven testing. Here is the standard operating procedure for penetration testers.

Step 1: Identifying Injection Points

Use Burp Suite's "Param Miner" or "Host Header" extension to automatically inject alternative Host headers into every request. Look for reflections of the injected host in the HTTP response body (e.g., in password reset emails, canonical URLs, or footer links).

Step 2: Testing Redirect Endpoints

Map all endpoints that issue 301/302 redirects. Look for parameters like next, url, redirect, return_to, and continue. Test the following bypass payloads:

# Standard Open Redirect Payloads ?next=https://evil.com ?next=//evil.com # Protocol-relative bypass ?next=\/\evil.com # Backslash bypass (Windows/IIS) ?next=https://target.com@evil.com # URL parsing confusion ?next=evil.com # Missing scheme # Testing for Host Header Injection Open Redirect # Send this via Burp Repeater or cURL: curl -v -H "Host: evil.com" "https://target.com/logout?next=/"
Step 3: Verifying Cache Poisoning (HHI)

If you find an HHI, check if the response is cached. Send a request with a malicious X-Forwarded-Host or Host header containing an XSS payload. If subsequent normal requests (without the malicious header) return the XSS payload, you have successfully poisoned the web cache.

6. Remediation & Secure Coding

Fixing these vulnerabilities requires shifting from a "trust but verify" model to a strict "deny by default" model for all routing inputs.

✅
Secure Remediation Checklist
  • Never trust the Host header for URL generation: Hardcode the base URL in your application configuration (e.g., APP_BASE_URL=https://target.com) and use it for generating emails, canonical tags, and redirects.
  • Validate Host at the Reverse Proxy: Configure Nginx/AWS ALB/Cloudflare to drop requests where the Host header does not match an explicit allowlist of your domains.
  • Use Mapped IDs for Redirects: Instead of passing URLs in parameters (?next=/dashboard), pass mapped identifiers (?next=dashboard) and resolve them server-side against a strict allowlist.
  • Use Framework Built-ins: If you must use relative redirects, use your framework's secure URL validation. In Django, use url_has_allowed_host_and_scheme(). In Spring, use UriComponentsBuilder with strict validation.
Secure Code Example (Python / Django)
# SECURE: Using Django's built-in validation from django.utils.http import url_has_allowed_host_and_scheme from django.shortcuts import redirect from django.conf import settings def safe_login_view(request): next_url = request.POST.get('next', '/') # SECURE: Validates both the scheme AND the host against ALLOWED_HOSTS if not url_has_allowed_host_and_scheme( next_url, allowed_hosts={request.get_host()}, require_https=request.is_secure() ): next_url = '/' # Fallback to safe default return redirect(next_url)
Frequently Asked Questions
Is an Open Redirect really a security vulnerability, or just a low-severity bug?

Historically, Open Redirects were considered low-severity (P4/P5) in bug bounty programs. However, in 2026, they are recognized as critical enablers for phishing. If an attacker can redirect a user from a trusted domain (e.g., bank.com/login?next=evil.com) to a malicious site, the user is highly likely to trust the phishing page. Furthermore, Open Redirects can be chained with OAuth flows to steal authorization codes, elevating them to High or Critical severity.

What is the difference between X-Forwarded-Host and the Host header?

The Host header is a standard HTTP/1.1 header required for routing. The X-Forwarded-Host (XFH) is a non-standard header used by reverse proxies (like load balancers) to indicate the original host requested by the client. Applications often mistakenly trust XFH to reconstruct URLs. Attackers can inject malicious XFH headers directly. Secure applications must strip or strictly validate all proxy-related headers (X-Forwarded-Host, X-Forwarded-For, X-Forwarded-Proto) at the edge proxy level.

How do I prevent Web Cache Poisoning via Host Header Injection?

Cache poisoning via HHI occurs when the cache key includes the Host header, but the application reflects it unsanitized. To prevent this: 1) Configure your CDN/WAF to only cache responses for a strict allowlist of valid Host headers. 2) Ensure your application never reflects the raw Host header in the HTML body without context-aware encoding. 3) Use the Vary: Host header carefully, or better yet, rely on the CDN's native host-based cache partitioning.

Can I just use a WAF to block Host Header Injection and Open Redirects?

A WAF is a good safety net, but it is not a replacement for secure coding. WAF rules for HHI typically involve validating the Host header against a regex allowlist. For Open Redirects, WAFs can block known malicious domains in redirect parameters. However, WAFs can be bypassed using encoding tricks, protocol-relative URLs, or obscure parameters. The root cause must be fixed in the application code by never trusting user input for routing or URL generation.

About the author Written by the HOC Team at Hackers Online Club -- a cybersecurity community trusted by penetration testers, bug bounty hunters, and application security engineers since 2010. 15+ years of practical web security guides, vulnerability research, and secure coding tutorials. Learn more about HOC

Join Our Club

Enter your Email address to receive notifications | Join over Million Followers

Previous Article
Pentagon Confirms Breached

Pentagon Confirms Breached 3 Million DMDC Personnel Database

Related Posts