Skip to main content
Menu
Advisories

@fastify/express vulnerable to middleware bypass via mount paths starting with an optional group

GHSA-J373-FCW4-2CCVPublished Updated GitHub

Description

Impact

Express 5 writes an optional leading segment as a group, for example fastify.use('{/:lang}/admin', auth), which Express matches against /admin and /en/admin. When @fastify/express joins a mount path with the plugin prefix (GHSA-f44m-4qwg-5587), it treats a path that does not start with / as relative and puts a slash in front of it, so the mount becomes /{/:lang}/admin, which only matches //admin and //en/admin. Under a prefix ending in a slash, such as /api/, it becomes /api/{/:lang}/admin. The middleware then never runs for GET /admin/users, GET /en/admin/users or their prefixed equivalents, while the Fastify routes still do.

At the top level this is a regression in 4.0.10; under a prefix ending in a slash it affects every version since 4.0.5, the first to use Express 5.

Patches

Upgrade to @fastify/express 4.0.14 or later.

Workarounds

Mount the middleware on each spelling explicitly (fastify.use(['/admin', '/:lang/admin'], auth)), or enforce authentication in a Fastify hook (such as preHandler) that runs after the router has resolved the request.

References

Affected versions

References

GitHub · fastify/fastify-express