Skip to main content
Menu
Advisories

@fastify/express vulnerable to path-scoped middleware bypass via request URL decoding and normalization mismatches

GHSA-W877-HJCP-88RCPublished Updated GitHub

Description

Impact

@fastify/express passes Express a request URL that does not match the path Fastify's router (find-my-way) dispatched, so path-scoped Express middleware can be skipped while the route handler still runs. On a scoped route such as app.use('/tenant/:id/admin', authMiddleware), an unauthenticated request reaches the handler while the middleware (authentication, authorization, rate limiting) is skipped. No special configuration is required.

Three request forms trigger the mismatch. Since 4.0.3, the plugin percent-decodes the URL before Express parses it, so a backslash combined with whitespace or # (for example /tenant/x%5C%20/admin) makes Express rewrite \ to / and miss parameterized, prefixed and RegExp mounts, and %25 is decoded twice, so middleware and handler see different parameter and query values (/acct/%2561lice gives alice in middleware and %61lice in the handler). In every release, a request target starting with * (for example GET *admin) is routed to /admin by Fastify while Express does not match a mount on /admin, which skips static mounts as well.

Patches

Upgrade to @fastify/express 4.0.10 or later. Express now receives the path the router matched, request targets that do not start with / are rejected with a 400, and req.url keeps the query string encoded. RegExp mount paths are matched against the percent-encoded path, as in Express.

Workarounds

Enforce authentication in a Fastify hook (such as preHandler) that runs after the router has resolved the request, and base the decision on the matched route (request.routeOptions.url). To block only the two bypasses, reject request targets that start with * or whose path contains a backslash in an onRequest hook registered before @fastify/express.

Affected versions

References

GitHub · fastify/fastify-express