The vulnerability is a path normalization inconsistency between the @fastify/middie middleware and the Fastify router. The root cause is that the middleware engine did not use the same path normalization rules as the router. An attacker could craft a URL (e.g., //secret instead of /secret) that would fail to match the middleware's path rule, thus bypassing authentication or authorization checks. However, the Fastify router would normalize this path, routing the request to the protected endpoint as if the middleware had been successfully passed.
The analysis of the patch commit 140e0dd0359d890fec7e6ea1dcc5134d6bd554d4 reveals two key functions involved:
-
fastifyMiddie in index.js: This function is the plugin's entry point. The patch shows that it was modified to read the routerOptions (like ignoreDuplicateSlashes, useSemicolonDelimiter, etc.) from the Fastify instance and pass them to the middie engine. Previously, it initialized the engine without these options, causing the engine to be unaware of the router's normalization behavior.
-
middie in lib/engine.js: This is the core middleware processing engine. The patch modifies it to accept the router options and introduces a new normalizePathForMatching helper function. This new function explicitly applies the same normalization logic that the Fastify router uses (removeDuplicateSlashes, sanitizeUrlPath, trimLastSlash). The middleware matching logic was updated to use this consistently normalized path, closing the bypass vulnerability.
Therefore, both fastifyMiddie and middie are identified as the vulnerable functions, as they were responsible for the inconsistent handling of URL paths that led to the security flaw.