Summary
A path traversal flaw in @fastify/http-proxy's WebSocket routing allows crafted upgrade requests to bypass the configured rewrite prefix and reach unintended upstream endpoints.
When a non-normalizing WebSocket client or intermediary preserves dot-segment sequences in the request path, attackers may traverse out of the expected proxy scope and access internal services.
Affected context
This vulnerability appears in Node.js applications using @fastify/http-proxy versions 9.4.0 through 11.5.0 to forward WebSocket connections.
It manifests when the proxy is configured with a path rewrite prefix to constrain which upstream paths are exposed, and when upstream paths include sensitive or internal-only routes.
The issue becomes relevant in environments where WebSocket clients or intermediate proxies forward the original request target without normalizing dot-segment sequences (such as ../), potentially allowing escape from the intended rewrite prefix.
Exploit preconditions
- Attack surface: WebSocket upgrade endpoints fronted by @fastify/http-proxy.
- Required access: Ability to initiate WebSocket upgrade requests against the proxy (typically network-accessible, potentially unauthenticated).
- Trigger point: A specially crafted request path containing traversal sequences (e.g.,
..segments) sent through a client or downstream proxy that does not normalize the path before forwarding. - Why exploitation is possible: The WebSocketProxy.findUpstream logic constructs the upstream URL using the WHATWG URL API, which collapses dot segments. The proxy then fails to revalidate the resolved destination path against the configured rewrite prefix, allowing the normalized path to target upstream routes outside the allowed prefix.
Why this happens
The underlying defect is a path traversal issue where normalization and authorization checks are out of sync.
The WebSocket proxy logic relies on a rewrite prefix to constrain upstream routing, but it computes the destination using the WHATWG URL constructor, which normalizes the path by collapsing . and .. segments.
Because the code does not re-check the normalized path against the configured prefix, an attacker can embed traversal sequences in the original request, which are then resolved to a different upstream path than intended.
This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, where path-based access control is enforced on unnormalized input or is not applied after canonicalization.
Potential impact
- Attackers could reach upstream HTTP or WebSocket endpoints that were not meant to be exposed through the proxy.
- Internal-only APIs or admin routes behind the proxy could become accessible from untrusted networks.
- Security assumptions about path-based isolation and multi-tenant separation may be broken.
- Unauthorized data access or modification could occur via unintended upstream routes.
General mitigation guidance
Mitigation typically centers on tightening path handling and validation in proxy routing logic.
Useful patterns include:
- Applying path normalization (including dot-segment removal) before any authorization or prefix-matching logic, and then enforcing prefix checks on the normalized path.
- Implementing an explicit allowlist of upstream routes or path patterns that the proxy is permitted to forward, rather than relying solely on string-based rewrite prefixes.
- Treating user-supplied request targets as untrusted input and avoiding direct concatenation into upstream URLs without canonicalization and policy checks.
- Segregating sensitive upstream endpoints onto separate virtual hosts or ports that are never reachable via general-purpose proxies, reducing exposure even if routing flaws occur.
- Limiting the privileges of services exposed through the proxy so that unexpected access yields minimal impact.
How teams detect issues like this
Detection involves both code-centric and environment-focused approaches:
- Static analysis and code review can flag routing logic that performs path rewrites or prefix checks without explicitly normalizing paths first.
- Review WebSocket proxy implementations for reliance on client-side normalization assumptions, especially when using low-level HTTP upgrade handling.
- Introduce automated tests that exercise edge-case paths (e.g.,
/prefix/../admin) through WebSocket endpoints and verify they are rejected or routed safely. - Leverage reverse-proxy or gateway policies to normalize paths and deny requests containing suspicious traversal patterns before they reach application code.
- Use security scanning tools that model path traversal across proxies and WebSocket upgrades, focusing on mismatches between configured prefixes and effective upstream destinations.

