The vulnerability is a form of HTTP request smuggling that occurs in Next.js's proxy layer when handling rewrites. The root cause lies within the vendored http-proxy library, specifically in the deleteLength function located in lib/http-proxy/passes/web-incoming.js.
When a DELETE or OPTIONS request containing a Transfer-Encoding: chunked header but no Content-Length header is sent to a rewritten route, the deleteLength function would incorrectly modify the request. It would add a Content-Length: 0 header and then delete the Transfer-Encoding header. This inconsistent handling created a desynchronization between the Next.js proxy and the backend server. The proxy would process a request with Content-Length: 0, but the backend could still see a chunked request, allowing an attacker to smuggle a second, malicious request in the body of the first one.
The patch addresses this in two ways:
- It modifies
deleteLength to only add Content-Length: 0 if both Content-Length and Transfer-Encoding headers are absent. It also stops deleting the Transfer-Encoding header. This is the primary fix.
- It modifies the
setupOutgoing function in lib/http-proxy/common.js to proactively set the Connection header to close for any request that uses Transfer-Encoding. This is a secondary mitigation to prevent connection reuse, which is necessary for this type of request smuggling attack.
Therefore, the primary vulnerable function that would appear in a runtime profile during exploitation is deleteLength. The setupOutgoing function is also relevant as it was modified to harden the proxy against this attack vector.