@fastify/express vulnerable to middleware bypass with case-insensitive routing via Unicode mount paths and case-sensitive matchers
Description
Impact
With routerOptions.caseSensitive: false, Fastify's router (find-my-way) lowercases the request path with toLowerCase() and routes a request whatever its spelling. To mirror that, @fastify/express 4.0.10 lowercases the path it hands to Express and adds the i flag to RegExp mount paths (GHSA-6rmc-f24g-hmp6). Two kinds of path-scoped middleware are still skipped.
- Express matches a string mount path with the
iflag of a regular expression, which does not fold every character astoLowerCase()does:İ(U+0130) becomesi̇,ẞ(U+1E9E) becomesß, andK(U+212A),Ω(U+2126) andÅ(U+212B) become ASCII or other letters. A mount path or plugin prefix containing such a character, such asfastify.use('/İletişim/admin', auth), does not match the lowercased path, so with 4.0.10 every request to the routes below it skips the middleware. Earlier versions are bypassed by a request spelled in lowercase. - Matching inside an Express Router or application passed to
fastify.use()can still be case-sensitive: a RegExp mount path without theiflag, aRouter({ caseSensitive: true }), or an application withcase sensitive routingenabled. Such a mount only matches its own casing, soGET /admin/usersruns the handler for/Admin/userswhilerouter.use(/^\/Admin/, auth)is skipped, and since 4.0.10 lowercases the path, so isGET /Admin/users.
Only applications that set caseSensitive: false are affected.
Patches
Upgrade to @fastify/express 4.0.14 or later. String mount paths are lowercased as the request path is, and a request that a case-sensitive matcher would match in the route's own spelling fails with a 500 instead of skipping the middleware.
Workarounds
Enforce authentication in a Fastify hook (such as preHandler) that runs after the router has resolved the request, avoid characters such as İ and ẞ in mount paths, and match case-insensitively inside Express routers and applications (add the i flag to RegExp mount paths and do not enable caseSensitive or case sensitive routing).
References
- GHSA-6rmc-f24g-hmp6 (CVE-2026-129850), the original case-folding bypass