Skip to main content
Menu
Advisories

@fastify/middie vulnerable to path-scoped middleware bypass via Unicode case folding

GHSA-R5H5-R25J-5VHRPublished Updated GitHub

Description

Impact

@fastify/middie versions <= 9.3.6 do not read routerOptions.caseSensitive and match path-scoped middleware mount paths with a case-insensitive regular expression that does not fold non-ASCII characters. When routing is case-insensitive (caseSensitive: false), Fastify's router folds the request path with toLowerCase(), which maps the Unicode character U+212A KELVIN SIGN to the ASCII letter k, while the middleware does not. The two layers disagree on the canonical request path: a request such as /api/%E2%84%AAeys is routed to the /api/keys handler while a path-scoped middleware mounted at /api/keys (authentication, authorization, rate limiting) never matches and is skipped. An unauthenticated client reaches the protected handler by spelling a k in the mount path as %E2%84%AA. Only a mount path containing k is affected, and only when the application enables caseSensitive: false.

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. Leaving routing case-sensitive (the default) also avoids the issue.

Affected versions

References

GitHub · fastify/middie