white plane releasing cargo
Thu Jun 22

HTTP Request Smuggling: A Complete Guide

HTTP request smuggling is a web security vulnerability that exploits the way web servers process sequences of HTTP requests. It can allow an attacker to bypass security controls, access sensitive data, and compromise other users of a web application. In this article, we will explain what HTTP request smuggling is, how it works, what are the risks, and how to prevent it.

What is HTTP request smuggling?

HTTP request smuggling is a technique that interferes with the way a web site processes sequences of HTTP requests that are received from one or more users. It takes advantage of an inconsistency between the interpretation of Content- Length and Transfer-Encoding headers between different HTTP servers in a proxy chain.

A proxy chain is a common architecture in modern web applications, where a front-end server (such as a load balancer or a reverse proxy) forwards requests to one or more back-end servers (such as web servers or application servers). The front-end server typically sends several requests over the same back-end network connection, for efficiency and performance reasons.

However, if the front-end and back-end servers disagree on where one request ends and the next one begins, an attacker can send an ambiguous request that gets interpreted differently by the front-end and back-end servers. This can cause part of the attacker’s request to be prepended to the next request, and interfere with the way the application processes that request. This is a request smuggling attack, and it can have devastating results.

How does HTTP request smuggling work?

Most HTTP request smuggling vulnerabilities arise because the HTTP specification provides two different ways to specify where a request ends: the Content-Length header and the Transfer-Encoding header.

The Content-Length header is straightforward: it specifies the length of the message body in bytes. For example:

POST /search HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 11

q=smuggling

The Transfer-Encoding header can be used to specify that the message body uses chunked encoding. This means that the message body contains one or more chunks of data, each preceded by its size in hexadecimal digits, and followed by a newline character. The last chunk has a size of zero, indicating the end of the message body. For example:

POST /search HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
Transfer-Encoding: chunked

b q=smuggling 0

The problem arises when an attacker sends both headers in a single request. This can cause either the front-end or the back-end server to incorrectly interpret the request, passing through a malicious HTTP query. For example:

POST /search HTTP/1.1
Host: example.com
Content-Type:
application/x-www-form-urlencoded
Content-Length: 4
Transfer-Encoding: chunked

0
GET /admin HTTP/1.1 X-Forwarded-For: 127.0.0.1
0

If the front-end server ignores the Transfer-Encoding header and uses the Content-Length header to determine the end of the request, it will forward only the first four bytes of the message body (0\r\n\r) to the back-end server, along with the next legitimate request from another user. However, if the back-end server ignores the Content-Length header and uses the Transfer- Encoding header to determine the end of the request, it will parse the message body as chunked encoding, and interpret GET /admin HTTP/1.1 as part of a new request that is smuggled into the back-end connection. This can allow the attacker to access an unauthorized resource or perform other malicious actions.

HTTP Request Smuggling security implications

HTTP request smuggling can have serious security implications for web applications and their users. Depending on the configuration of the proxy chain and the application logic, an attacker can leverage HTTP request smuggling to:

  • Bypass web application firewalls (WAFs) and other security controls that are applied at the front-end server but not at the back-end server.
  • Access restricted resources or perform unauthorized actions by smuggling requests that appear to come from a trusted source, such as the front-end server or another user.
  • Steal sensitive data or hijack sessions by smuggling requests that trigger a response from the back-end server that is appended to the response of another user’s request, causing a response splitting attack.
  • Perform denial-of-service (DoS) attacks by smuggling requests that cause the back-end server to hang or crash, or consume excessive resources.

How to prevent HTTP request smuggling?

HTTP request smuggling is a complex and insidious vulnerability that exploits the vagaries of server configurations and protocol interpretations. However, there are some best practices and mitigation strategies that can help protect web environments from these attacks:

  • Understand how the infrastructure components interpret HTTP headers. Use the same interpretation engine on both the front-end and the back-end servers, if possible, or ensure that they handle HTTP headers consistently.
  • Configure the front-end server to reject requests that contain both Content-Length and Transfer-Encoding headers, or normalize them to use only one of them.
  • Configure the back-end server to reject requests that contain ambiguous or invalid headers, such as multiple Content-Length headers, or mismatched chunk sizes.
  • Use HTTPS for both front-end and back-end connections, and enable HTTP Strict Transport Security (HSTS) to prevent downgrade attacks.
  • Monitor the web traffic for signs of HTTP request smuggling attempts, such as malformed headers, unexpected requests, or anomalous responses.

HTTP request smuggling is a serious web security threat that can compromise web applications and their users. By understanding how it works, what are the risks, and how to prevent it, web developers and administrators can improve the security and resilience of their web environments.

Conclusion

HTTP request smuggling is a web security vulnerability that exploits the inconsistency between the interpretation of Content-Length and Transfer- Encoding headers between different HTTP servers in a proxy chain. It can allow an attacker to bypass security controls, access sensitive data, and compromise other users of a web application. In this article, we have explained what HTTP request smuggling is, how it works, what are the risks, and how to prevent it.

HTTP request smuggling is a complex and insidious vulnerability that requires careful attention and awareness from web developers and administrators. By following the recommendations in this article, they can improve the security and resilience of their web environments and prevent potential attacks that could compromise their applications and users.