Skip to main content
Menu
Advisories

@fastify/express vulnerable to middleware bypass via RegExp mount paths under parameterized prefixes

GHSA-84W6-XRF3-F8Q8Published Updated GitHub

Description

Impact

@fastify/express does not rewrite RegExp mount paths to account for a parameterized Fastify plugin prefix. When a plugin is registered under a parameterized prefix (for example /tenant/:tenantId) and middleware is mounted with a RegExp (for example app.use(/^\/private/, authMiddleware)), the plugin prefix is treated as literal text when the Express matcher is built, so the matcher expects the literal :tenantId instead of a concrete value such as acme. Express never matches the mount against the real URL and silently skips the middleware, while Fastify still runs the route handler.

Applications that use RegExp-mounted Express middleware for authentication or authorization inside a parameterized-prefix plugin can expose protected routes to unauthenticated clients. No special configuration is required beyond a parameterized prefix and a RegExp mount; the default router settings are sufficient.

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 resolves the request, or avoid RegExp mount paths under parameterized plugin prefixes (use a string mount path, or move the parameter out of the prefix).

Affected versions

References

GitHub · fastify/fastify-express