Summary
A path prefix rewriting flaw in @fastify/http-proxy allows attackers to bypass intended request path restrictions when parts of the prefix are URL-encoded.
Under certain encoded-path conditions, upstream services receive raw paths that were meant to be hidden, potentially exposing internal or administrative endpoints behind the proxy.
Affected context
This vulnerability occurs in Fastify applications that:
- Use @fastify/http-proxy up to and including version 11.5.0
- Rely on
rewritePrefixto hide or remap upstream paths - Accept user-controlled request paths over HTTP(S)
The issue manifests when:
- Fastify's router matches a route using a URL-decoded path segment
- One or more characters in the configured prefix are URL-encoded in the request
- The proxy forwards the original (still-encoded) request.url to the upstream without properly rewriting the prefix.
Exploit preconditions
- Attack surface: Public or internal HTTP endpoints that sit in front of upstream services using @fastify/http-proxy.
- Required access: Ability to send crafted HTTP requests to the Fastify server (no prior authentication necessarily required if the proxy is public).
- Trigger point: Requests whose path includes a URL-encoded version of one or more characters in the configured
rewritePrefixsegment. - Why exploitation is possible: Fastify decodes the path for routing but keeps the original encoded
request.url; the prefix-rewrite logic compares a decoded prefix against an encoded path using simple string replacement, so encoded prefixes can match the route but skip rewriting, leaving the upstream to decode and serve a path that should have been hidden.
Why this happens
The core issue is inconsistent handling and normalization of URL paths between routing and prefix rewriting logic.
Fastify's router operates on a URL-decoded path, while @fastify/http-proxy relies on the raw, encoded request.url string during rewritePrefix. The rewrite step uses literal string replacement based on a decoded prefix, which fails when parts of the prefix are percent-encoded in the request.
This misalignment in trust and normalization of input paths maps to CWE-20: Improper Input Validation, as the code assumes that the encoded and decoded representations are equivalent for security-sensitive path rewriting, allowing attackers to craft inputs that bypass intended restrictions.
Potential impact
- Attackers may reach upstream paths that were intended to be hidden by the proxy.
- Internal or administrative endpoints can be exposed to untrusted clients.
- Access control policies implemented via path-based routing or rewriting could be bypassed.
- Sensitive management or debug APIs behind the proxy may be called directly.
- Further compromise of upstream services is possible if exposed endpoints support dangerous operations.
General mitigation guidance
Effective mitigation focuses on consistent path normalization and defense-in-depth around upstream access control.
Common defensive patterns include:
- Ensuring that all security-critical path checks and rewriting operate on a normalized representation (e.g., consistently decoded paths) rather than mixed encoded/decoded forms.
- Avoiding reliance on prefix rewriting alone as an access control mechanism; implement explicit authorization checks in upstream services for sensitive endpoints.
- Designing proxy configurations so that hidden internal endpoints are also bound to separate interfaces or networks, not just obscured by path manipulation.
- Applying strict route definitions and validation of incoming paths to reject malformed or suspicious encodings that deviate from expected patterns.
- Using least-privilege principles on upstream services, limiting what endpoints are exposed through the proxy and what actions anonymous users can perform.
How teams detect issues like this
Detection typically involves a mix of code-centric and traffic-centric approaches:
- Static analysis or code review to identify proxy configurations that rely on
rewritePrefixfor security, especially where encoded paths might interact with rewriting logic. - Examination of routing and proxy middleware to ensure that path normalization is performed before security decisions or forwarding.
- Logging and monitoring of upstream requests, including decoded paths, to spot unexpected access to internal or administrative endpoints originating from a proxy.
- Security tests and fuzzing that send variants of encoded paths (e.g., partial percent-encoding of prefix segments) to verify that rewrite rules and access controls behave as expected.
- Integration of automated review tools that flag mismatches between decoded routing paths and raw forwarded URLs in HTTP proxy implementations.

