Skip to main content
Menu
Advisories

@fastify/express vulnerable to middleware bypass with case-insensitive routing via Unicode mount paths and case-sensitive matchers

GHSA-F446-H93M-FVR5Published Updated GitHub

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 i flag of a regular expression, which does not fold every character as toLowerCase() does: İ (U+0130) becomes i̇, ẞ (U+1E9E) becomes ß, and K (U+212A), Ω (U+2126) and Å (U+212B) become ASCII or other letters. A mount path or plugin prefix containing such a character, such as fastify.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 the i flag, a Router({ caseSensitive: true }), or an application with case sensitive routing enabled. Such a mount only matches its own casing, so GET /admin/users runs the handler for /Admin/users while router.use(/^\/Admin/, auth) is skipped, and since 4.0.10 lowercases the path, so is GET /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

Affected versions

References

GitHub · fastify/fastify-express