Skip to main content
Menu
Advisories

@fastify/express vulnerable to middleware bypass via empty route parameters in Express routers and sub-applications

GHSA-F9QF-HFC5-7XPJPublished Updated GitHub

Description

Impact

@fastify/express 4.0.10 rejects a request when an empty parameter or wildcard value would let it skip middleware mounted with fastify.use() on a dynamic path (GHSA-662w-h4p6-jq4p). That check only covers the mount paths passed to fastify.use(). Middleware mounted inside an Express Router or application that is itself passed to fastify.use(), which is how the README adds a complete Express application, is matched by Express with path-to-regexp, which requires a non-empty value for a dynamic segment, while Fastify's router (find-my-way) accepts an empty one.

A request with an empty value therefore reaches the Fastify route handler while the middleware is skipped. For example, GET /tenants//admin runs the handler for /tenants/:tenant/admin without router.use('/tenants/:tenant/admin', auth), GET /files/ runs the handler for /files/* without router.all('/files/*path', auth), and GET /reports/2026- runs the handler for /reports/:year-:month without a mount on the same pattern. The same check also misses a RegExp mount passed to fastify.use() that is not anchored: it tests the pattern anywhere in the path, while Express only runs a RegExp mount whose match starts the path, so with fastify.use(/\/users\/[^/]+/, auth), GET /users//users/x runs the handler for /users/:id/* without the middleware. 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.14 or later.

Workarounds

Enforce authentication in a Fastify hook (such as preHandler) that runs after the router has resolved the request, mount the middleware on a static parent path (for example router.use('/tenants', auth)), or require non-empty values in the route's params schema (minLength: 1) so that an empty value is rejected before the handler runs.

References

Affected versions

References

GitHub · fastify/fastify-express