Skip to main content
Menu
Advisories

@fastify/middie vulnerable to path-scoped middleware bypass via array mount-path type confusion

GHSA-HFWP-44M5-9364Published Updated GitHub

Description

Impact

@fastify/middie versions <= 9.3.6 normalize a path-scoped middleware's mount path with the internal sanitizePrefixUrl helper, which is written for string inputs, but use() also accepts an array of mount paths and passes the array straight through. The string operations silently do nothing on an array, so a trailing slash on an element such as /secret/ survives into the generated route-matching regular expression, and an element of exactly / (a catch-all mount) is dropped entirely. The compiled regex then fails to match subroutes such as /secret/data, so the path-scoped middleware (authentication, authorization, rate limiting) is skipped while Fastify's router still dispatches the request to the handler. On 8.0.0 through 9.0.0, which use path-to-regexp 6, the impact is narrower: subroutes such as /secret/data are still matched, only the mount root itself (for example /secret) is skipped, and a / element is dropped only when it is the last element of the array. An application is affected when it mounts middleware on an array of paths where an element carries a trailing slash, including one introduced by joining a plugin prefix that ends in /, or is exactly /. 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 array mount paths with a trailing-slash element for security-relevant middleware.

Affected versions

References

GitHub · fastify/middie