@fastify/reply-from vulnerable to path traversal via scheme-prefixed encoded dot-segments
Description
Impact
@fastify/reply-from's buildURL() validated the attacker-supplied source string for . and .. segments, but when source begins with the same special scheme as the base (http: or https:), the WHATWG URL parser drops the scheme and resolves the rest as a relative path. A payload such as http:%2e%2e%2fsecret.txt therefore passed the check (the segment glued to the scheme read as http:.., not ..) while the proxy forwarded %2e%2e%2fsecret.txt. An upstream that percent-decodes the request path before resolving dot-segments then serves a path outside the configured prefix. An application that scopes proxying to an upstream prefix (reply.from('/v1/public/' + req.params['*'])), or relies on Fastify route guards in front of reply.from(), can have an unauthenticated request escape the intended prefix and reach sibling or parent upstream endpoints. Releases 12.8.1 through 12.8.3 are affected: the per-segment check introduced in 12.8.1 is what the scheme prefix bypasses, and up to 12.8.0 any decoded ../ was rejected.
Patches
Upgrade to @fastify/reply-from 12.8.4. buildURL() now also checks for dot-segments on the decoded path of the parsed URL, which is the path actually sent upstream, so a scheme prefix can no longer change what gets validated.
Workarounds
None.
Out of scope
An upstream that decodes the request path more than once (for example unquote(unquote(path))) can still resolve a double-encoded payload such as %252e%252e%252f to a traversal, independent of any proxy in front of it. That is an upstream path-traversal issue (CWE-174) and should be fixed there.