Summary
@fastify/middie versions prior to 9.2.0 contain an input validation flaw where path-scoped middleware (for example, app.use('/secret', auth)) can be bypassed under certain router normalization settings.
When Fastify routing options like ignoreDuplicateSlashes, useSemicolonDelimiter, or related trailing-slash behaviors are enabled, specially crafted request paths may skip authentication/authorization middleware while still reaching handlers that are assumed to be protected.
Affected context
The issue affects Node.js applications that:
- Use
@fastify/middiefor Express-style middleware in Fastify - Attach security-sensitive middleware using path prefixes (e.g.,
app.use('/admin', auth)) - Enable Fastify router normalization options such as:
ignoreDuplicateSlashesuseSemicolonDelimiter- Trailing slash normalization and related behaviors
In these setups, the routing layer and the middleware path matching can disagree on what constitutes the same URL path, creating a gap where some requests reach protected routes without passing through the intended middleware.
Exploit preconditions
- Attack surface: HTTP(S) endpoints served by Fastify using
@fastify/middie - Required access: Network access to the affected routes; no prior authentication is required if the bypass targets initial auth checks
- Trigger point: A request path crafted to be normalized by Fastify routing into a protected path (e.g.,
/secret) while not matching the middleware's path-scoped configuration (e.g.,app.use('/secret', auth)) - Why exploitation is possible: Middleware path matching and Fastify router normalization apply different interpretations of equivalent paths. This mismatch allows requests to bypass path-scoped middleware while still being routed to handlers that assume middleware has already run.
Why this happens
The vulnerability stems from inconsistent input handling between the Fastify router's path normalization logic and @fastify/middie's path-based middleware matching.
When options like ignoreDuplicateSlashes, useSemicolonDelimiter, or trailing slash normalization are enabled, the router may treat multiple syntactic variants of a URL as the same logical route. However, @fastify/middie evaluates middleware scope against the raw or differently processed path. This discrepancy is an example of CWE-20: Improper Input Validation, where the system fails to apply a consistent, canonical representation of inputs across components, leading to security checks being applied in one interpretation but not another.
Potential impact
- Requests may bypass authentication middleware and reach endpoints that assume users are logged in.
- Authorization checks implemented as path-scoped middleware can be skipped, exposing restricted operations or data.
- Security logging, rate limiting, or CSRF protection implemented via middleware may not run for certain crafted paths.
- Attackers can potentially access administrative panels, privileged APIs, or sensitive resources without proper credentials.
General mitigation guidance
Mitigation should focus on ensuring that security checks are not dependent on ambiguous or inconsistent path processing.
Recommended defensive patterns include:
- Prefer route-level guards (e.g., Fastify hooks like
onRequestorpreHandler) or explicit per-route checks rather than relying solely on path-scoped middleware prefixes for critical authentication and authorization. - Normalize or canonicalize request paths once, early in the request lifecycle, and base all security decisions on this canonical form.
- Align router and middleware configurations so that both use the same normalization semantics and constraints.
- Centralize authentication/authorization logic in a single, well-defined layer that cannot be bypassed by path variations.
- Use a deny-by-default approach for sensitive routes, requiring explicit checks for every access rather than relying on implicit middleware coverage.
How teams detect issues like this
Potential detection and validation approaches include:
- Static analysis / code review:
- Look for critical auth/authorization logic placed in
@fastify/middiepath-scoped middleware (e.g.,app.use('/secret', auth)). - Flag combinations of
@fastify/middiewith Fastify router options likeignoreDuplicateSlashes,useSemicolonDelimiter, or custom trailing slash handling. - Review any assumptions that "everything under
/admingoes through this middleware" and verify they hold under all path variants. - Dynamic testing / fuzzing:
- Automatically generate path variations (duplicate slashes, semicolons, added trailing slashes, encoded separators) for protected routes and confirm middleware is invoked consistently.
- Use integration tests that assert both route handler execution and associated middleware execution for sensitive endpoints.
- Policy enforcement:
- CI/CD checks that warn when path-scoped middleware is used for core security functions instead of route hooks or global guards.
- Optional use of automated review tools configured to highlight routing and middleware configuration mismatches.

