@fastify/express vulnerable to middleware bypass via empty route parameters and wildcards
Description
Impact
@fastify/express matches path-scoped Express middleware with path-to-regexp, which requires a non-empty value for a dynamic segment, while Fastify's router (find-my-way) accepts an empty parameter or wildcard. When a route and an Express middleware mount share a dynamic pattern, a request with an empty segment such as GET /tenant/ or GET /files/ matches the Fastify route and runs the handler while the middleware mounted on that pattern is skipped. On a scoped mount such as app.use('/tenant/:tenantId', authMiddleware), an unauthenticated request can reach the protected handler. The default router configuration is sufficient. The practical impact depends on what the empty value selects in the application.
Patches
Upgrade to @fastify/express 4.0.10 or later.
Workarounds
Enforce authentication in a Fastify hook (such as preHandler) that runs after the router has resolved the request, or mount the middleware on a static parent path (for example /tenant instead of /tenant/:tenantId) so that an empty dynamic segment cannot skip it.
References
- GHSA-6h42-57hq-9746 (CVE-2026-112362), a related
@fastify/expresspath-scoped middleware bypass - GHSA-3wf5-7852-vcfq (CVE-2026-6556), a related
@fastify/expressmiddleware bypass via non-string mount paths