Fastify Proxy Header Stripping Vulnerability
The `@fastify/reply-from` and `@fastify/http-proxy` libraries process the client's `Connection` header after adding headers, allowing attackers to strip proxy-added headers via the `Connection` header, leading to potential bypass of security controls.
The @fastify/reply-from and @fastify/http-proxy libraries are vulnerable to a header stripping attack. This vulnerability stems from the incorrect processing order of the Connection header. The client’s Connection header is processed after the proxy has added custom headers via the rewriteRequestHeaders function. This allows an attacker to retroactively remove headers added by the proxy by simply listing them in the Connection header. This affects any application leveraging these plugins where custom headers are injected for routing, access control, or other security purposes. All versions of both @fastify/reply-from and @fastify/http-proxy are affected. The vulnerability can be exploited without any special configuration. This undermines the intended function of a proxy as a trusted intermediary.
Attack Chain
- A client crafts a request containing a
Connectionheader. - The client sends the crafted request to a Fastify proxy server using
@fastify/reply-fromor@fastify/http-proxy. - The proxy receives the request and copies all client headers, including the
Connectionheader. - The proxy, using
rewriteRequestHeaders, adds custom headers (e.g.,x-forwarded-by) to the request. - The proxy’s transport handler processes the
Connectionheader from the client. - Headers listed in the client’s
Connectionheader, including proxy-added headers, are stripped from the upstream request. - The modified request, with stripped headers, is forwarded to the upstream server.
- The upstream server receives the request with missing headers, potentially bypassing security checks.
Impact
Successful exploitation allows attackers to bypass security controls implemented by the proxy. This includes bypassing proxy identification, circumventing access control mechanisms, and removing arbitrary headers. For example, an attacker can strip headers like x-forwarded-by to avoid detection, or remove authentication headers like authorization or custom access control headers like x-internal-auth to gain unauthorized access to resources. The number of victims depends on the prevalence of vulnerable Fastify deployments.
Recommendation
- Upgrade to patched versions of
@fastify/reply-fromand@fastify/http-proxywhen available. - As a workaround, avoid using
rewriteRequestHeadersto inject security-critical headers into requests. - Implement input validation to sanitize or reject requests containing a
Connectionheader that attempts to remove security-sensitive headers. - Monitor web server logs for requests containing
Connectionheaders listing custom or security-related headers as a sign of potential exploitation (see Sigma rule below).
Detection coverage 2
Detect Fastify Proxy Header Stripping Attempt
highDetects requests with a 'Connection' header attempting to strip common proxy-added headers.
Detect Fastify Proxy Header Stripping - Connection: close
lowDetects requests with a 'Connection' header set to 'close', which, while legitimate, could be used in conjunction with other header manipulation techniques.
Detection queries are kept inside the platform. Get full rules →