Summary
A path traversal guard bypass in @fastify/static up to 10.1.0 allows crafted dot-dot segments in request paths to slip past route-level protections.
An unauthenticated attacker can use this to reach files under the configured static root that should be shielded by route-scoped middleware, though they cannot escape the static root itself.
Affected context
This vulnerability appears in Node.js applications using @fastify/static (through 10.1.0) to serve files from a static root, particularly when route-scoped middleware or guards are applied to specific URL prefixes.
It arises when the application relies on URL path checks or middleware ordering to restrict which static files are reachable, while still allowing relative path segments in incoming requests.
Environments that depend on middleware-based filtering for sensitive or semi-private assets underneath the static root are the most exposed.
Exploit preconditions
- Attack surface: HTTP(S) endpoints served via @fastify/static.
- Required access: No authentication is required; any remote client able to issue HTTP requests to the affected routes can attempt exploitation.
- Trigger point: Requests that include dot-dot path segments (e.g.,
..) in the pathname targeting URLs guarded by route-scoped middleware or filters. - Why exploitation is possible: The Fastify layer fails to reject
..segments before delegating to the underlying send library.
The send library normalizes dot segments prior to enforcing its own path traversal protection, allowing the request to bypass middleware checks tied to specific URL prefixes while remaining inside the static root.
Why this happens
The underlying bug class is improper restriction of path traversal (CWE-22), specifically in the ordering and layering of path normalization and validation.
@fastify/static performed routing and guard decisions based on a raw or partially processed URL path that could still contain dot-dot segments, while the lower-level send library later normalized those segments and enforced its own traversal guard.
Because the framework did not canonicalize and validate the effective path before applying route-scoped protections, an attacker could craft paths that appear to fall under a guarded prefix but are later resolved to different files inside the static root, effectively bypassing middleware checks.
Potential impact
- Unauthenticated clients may read files under the static root that were intended to be shielded by route-scoped middleware.
- Attackers could access configuration or metadata files placed under guarded URL prefixes inside the static root.
- Sensitive static assets (such as internal documentation, hidden admin resources, or pre-built bundles) could be exposed if they rely solely on route-prefix guards.
- Information disclosure within the application's static directory structure may aid further attacks.
General mitigation guidance
Effective mitigation centers on enforcing canonical path validation before applying any routing or authorization logic.
Common defensive patterns include:
- Normalizing and resolving request paths to a canonical form before checking prefixes, applying middleware decisions, or passing them to lower-level file-serving libraries.
- Treating relative path indicators (such as
..and.) as invalid in externally supplied request paths and rejecting such requests early. - Avoiding reliance on route-scoped middleware alone to protect sensitive content within a shared static root; instead, segregate sensitive assets into separate roots or serve them via authenticated handlers.
- Designing static-serving configurations to default to least privilege, only exposing explicitly intended paths and disallowing ambiguous or derived path mappings.
How teams detect issues like this
Detection can leverage both static and dynamic approaches:
- Static analysis: Search for use of @fastify/static combined with route-scoped middleware that assumes path-prefix checks are sufficient protection for sensitive assets.
- Code review: Flag patterns where static content is gated only by middleware applied to URL prefixes, without explicit checks on resolved filesystem paths.
- Configuration review: Inspect static root layouts to identify sensitive files co-located with public assets and protected solely via routing configuration.
- Dynamic testing: Use security testing or fuzzing tools to send requests with dot-dot segments and verify whether guarded assets become accessible.
Automated review tools and CI checks can be configured to highlight high-risk static-serving configurations and route-guard patterns.

