@fastify/middie vulnerable to path-scoped middleware bypass via duplicate-slash mount path
Description
Impact
@fastify/middie builds each path-scoped middleware's match regular expression from its mount path without collapsing duplicate slashes, even when the application enables Fastify's routerOptions.ignoreDuplicateSlashes. Fastify's router collapses duplicate slashes in both the registered route and the request path under that option, so a route registered at /admin//secret is served at /admin/secret, but the middleware's compiled match still requires the doubled slash and matches no request the router serves. A path-scoped middleware (authentication, authorization, rate limiting) is therefore skipped while the router dispatches the request to the handler. An application is affected when it enables ignoreDuplicateSlashes and a middleware's mount path reaches middie with a duplicate slash, most commonly by joining a plugin prefix that ends in / to a mount path that starts with /, for example register(plugin, { prefix: '/api//v1/' }). No authentication is required.
Patches
Upgrade to @fastify/middie v9.3.7 or later.
Workarounds
Enforce authorization in a Fastify hook (such as preHandler) that runs after the router has resolved the request. Avoid mount paths and plugin prefixes that introduce duplicate slashes.