Summary
A path traversal flaw in @fastify/reply-from can let a client send requests outside the upstream path prefix configured for the proxy. It becomes risky when the upstream server decodes percent-encoded paths before resolving dot segments, potentially allowing access to sibling or parent endpoints.
Affected context
The issue affects @fastify/reply-from versions 12.8.1 through 12.8.3, where buildURL checks attacker-controlled source paths for parent-directory segments. A scheme prefix can evade that per-segment check while the encoded traversal remains in the forwarded path. Exposure depends on the upstream server's path-decoding and dot-segment handling.
Exploit preconditions
- Attack surface: An HTTP route that proxies client-controlled request paths through
@fastify/reply-from - Required access: An unauthenticated client may be sufficient if the proxy endpoint is publicly reachable
- Trigger point: URL construction and forwarding of the client-supplied source path
- Upstream condition: The upstream server percent-decodes the path before resolving dot segments
- Why exploitation is possible: A scheme-prefixed path can bypass the segment check, while the encoded traversal is forwarded for the upstream to interpret
Why this happens
The URL-building logic checks path segments for traversal, but URL parsing can treat a source beginning with the same special scheme as the base URL as a relative path and remove the scheme. This means the checked segment may not appear to be a bare parent-directory token, even though the encoded traversal remains in the forwarded path.
This is a path traversal weakness mapped to CWE-22: Improper Limitation of a Pathname to a Restricted Directory. The underlying insecure pattern is validating a parsed representation that differs from the representation later interpreted by the upstream server.
Potential impact
- A client may reach sibling or parent upstream endpoints outside the configured prefix
- Fastify route guards or proxy-level path scoping could be bypassed
- Protected upstream data or functionality could be exposed
- Requests could reach endpoints with unintended side effects
General mitigation guidance
Defensive patterns focus on validating the exact path representation that will be forwarded and interpreted downstream.
- Use a canonicalization strategy consistent with the upstream server's decoding and path-resolution behavior
- Reject traversal after decoding, and avoid forwarding ambiguous or multiply encoded paths
- Prefer allowlisting permitted upstream paths over relying only on denylisting traversal tokens
- Keep proxy routing and upstream authorization checks independent of client-controlled path prefixes
- Apply least privilege to upstream credentials and restrict access to sensitive endpoints
How teams detect issues like this
- Review URL construction and validation code for differences between parsed, decoded, and forwarded path representations
- Use static analysis or code review checks to flag traversal checks that run before canonicalization
- Test proxy behavior against upstreams that decode percent-encoded paths before resolving dot segments
- Enforce policies that require upstream authorization and prevent proxy routes from granting broader access than intended

