CVE-2026-135270: @fastify/express vulnerable to middleware bypass via mount paths starting with an optional group
@fastify/express is the plugin that lets an application run Express middleware and Express applications inside the Fastify web framework. In versions from 4.0.5 before 4.0.14, a mount path that begins with an Express 5 optional leading segment written as a group is treated as relative and has a slash prepended when it is joined to the plugin prefix, which changes what the pattern matches so the middleware ends up mounted on a path that no longer corresponds to the real request paths. The middleware therefore never runs for requests that match the intended routes, while the Fastify routes still resolve to their handlers. An attacker can use this to bypass authentication or other middleware-based access controls on the affected routes. The issue is fixed in @fastify/express 4.0.14, and users should upgrade to 4.0.14 or later. As a workaround, mount the middleware on each path spelling explicitly, or enforce authentication in a Fastify hook such as preHandler that runs after the router resolves the request.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Fixed in 4.0.14 - Compensating control
As a workaround, mount the middleware on each path spelling explicitly, or enforce authentication in a Fastify preHandler hook that runs after the router resolves the request.
Event History
Frequently Asked Questions
Which deployments are exposed to this bypass?
Applications using @fastify/express versions 4.0.5 through 4.0.13 are affected only when middleware is mounted on a path beginning with an Express 5 optional leading segment written as a group. Routes protected by that middleware may remain reachable through their Fastify handlers without the middleware running.
What does an attacker need to exploit the issue?
The attacker needs network access to an affected route whose authentication or other access control is enforced solely by the incorrectly mounted Express middleware. No credentials or user interaction are required, but exploitation depends on the affected mount-path pattern being present.
How can we mitigate the issue before upgrading?
Mount the middleware separately on each explicit path spelling, rather than using the optional leading grouped segment. Alternatively, enforce authentication in a Fastify hook such as preHandler, which runs after the router resolves the request.
How can we determine whether our application is affected?
Review @fastify/express usage for versions before 4.0.14 and inspect middleware mount paths for ones that begin with an Express 5 optional leading segment written as a group. Test requests to the intended protected Fastify routes and verify that the expected middleware executes before the handler.