@fastify/express vulnerable to RegExp middleware bypass via encoded line terminators
Description
Impact
@fastify/express decodes the request path the way Fastify's router does before handing it to Express (GHSA-g6q3-96cp-5r5m, GHSA-w877-hjcp-88rc), and percent-encodes again the characters that would make Express parse it differently. %E2%80%A8 and %E2%80%A9 are decoded to U+2028 and U+2029, which stay raw, and which a JavaScript regular expression treats as line terminators: . does not match them, and with the m flag ^ and $ match around them. Plain Express sees them percent-encoded.
A RegExp mount path that relies on ., such as fastify.use(/^\/admin(?:\/.*)?$/, auth), therefore does not match GET /admin/users/42%E2%80%A8, while Fastify routes it to /admin/users/:id with the parameter 42\u2028, so the handler runs without the middleware. String mount paths are not affected.
Patches
Upgrade to @fastify/express 4.0.14 or later.
Workarounds
Use string mount paths, use [^] or the s flag instead of . in RegExp mount paths, or enforce authentication in a Fastify hook (such as preHandler) that runs after the router has resolved the request.