GHSA-6hw5-45gm-fj88: @fastify/express has a middleware authentication bypass via URL normalization gaps (duplicate slashes and semicolons)
Summary`@fastify/express` v4.0.4 fails to normalize URLs before passing them to Express middleware when Fastify router normalization options are enabled. This allows complete bypass of path-scoped authentication middleware via two vectors:**Duplicate slashes** (`//admin/dashboard`) when `ignoreDuplicateSlashes: true` is configured**Semicolon delimiters** (`/admin;bypass`) when `useSemicolonDelimiter: true` is configuredIn both cases, Fastify's router normalizes the URL and matches the route, but `@fastify/express` passes the original un-normalized URL to Express middleware, which fails to match and is skipped.Note: This is distinct from GHSA-g6q3-96cp-5r5m (CVE-2026-22037), which addressed URL percent-encoding bypass and was patched in v4.0.3. These normalization gaps remain in v4.0.4. A similar class of normalization issue was addressed in `@fastify/middie` via GHSA-8p85-9qpw-fwgw (CVE-2026-2880), but `@fastify/express` does not include the equivalent fixes.DetailsThe vulnerability exists in `@fastify/express`'s `enhanceRequest` function (`index.js` lines 43-46):The `decodeURI()` function only handles percent-encoding — it does not normalize duplicate slashes or strip semicolon-delimited parameters. When Fastify's router options are enabled, `find-my-way` applies these normalizations during route matching, but `@fastify/express` passes the original URL to Express middleware.Vector 1: Duplicate SlashesWhen `ignoreDuplicateSlashes: true` is set, Fastify's `find-my-way` router normalizes `//admin/dashboard` to `/admin/dashboard` for route matching. However, Express middleware receives `//admin/dashboard`. Express's `app.use('/admin', authMiddleware)` expects paths to start with `/admin/`, but `//admin` does not match the `/admin` prefix pattern.The attack sequence:Client sends `GET //admin/dashboard`Fastify's router normalizes this to `/admin/dashboard` and finds a matching route`enhanceRequest` sets `req.raw.url = "//admin/dashboard"` (preserves double slash)Express middleware `app.use('/admin', authMiddleware)` does not match `//admin` prefixAuthentication is bypassed, and the Fastify route handler executesVector 2: Semicolon DelimitersWhen `useSemicolonDelimiter: true` is configured, the router uses `find-my-way`'s `safeDecodeURI()` which treats semicolons as query string delimiters, splitting `/admin;bypass` into path `/admin` and querystring `bypass` for route matching. However, `@fastify/express` passes the full URL `/admin;bypass` to Express middleware.Express uses path-to-regexp v0.1.12 internally, which compiles middleware paths like `/admin` to the regex `/^\/admin\/?(?=\/|$)/i`. A semicolon character does not satisfy the lookahead condition, causing the middleware match to fail.The attack flow:Request `GET /admin;bypass` arrivesFastify router: splits at `;` — matches route `GET /admin`Express middleware: regex `/^\/admin\/?(?=\/|$)/i` fails against `/admin;bypass` — middleware skippedRoute handler executes without authentication checksPoCDuplicate Slash BypassSave as `server.js` and run with `node server.js`:Multiple variants work: `///admin`, `/.//admin`, `//admin//dashboard`, etc.Semicolon BypassActual output:The semicolon bypass works with any text after it: `/admin;`, `/admin;x`, `/admin;jsessionid=123`.ImpactComplete authentication bypass for applications using Express middleware for path-based access control. An unauthenticated attacker can access protected routes (admin panels, APIs, user data) by manipulating the URL path.**Duplicate slash vector** affects applications that:Use `@fastify/express` with `ignoreDuplicateSlashes: true`Rely on Express middleware for authentication/authorizationUse path-scoped middleware patterns like `app.use('/admin', authMiddleware)`**Semicolon vector** affects applications that:Use `@fastify/express` with `useSemicolonDelimiter: true` (commonly enabled for Java application server compatibility, e.g., handling `;jsessionid=` parameters)Rely on Express middleware for authentication/authorizationUse path-scoped middleware patterns like `app.use('/admin', authMiddleware)`The bypass works against all Express middleware that uses prefix path matching, including popular packages like `express-basic-auth`, custom authentication middleware, and rate limiting middleware.The `ignoreDuplicateSlashes` and `useSemicolonDelimiter` options are documented as convenience features, not marked as security-sensitive, so developers would not expect them to impact middleware security.Affected Versions`@fastify/express` v4.0.4 (latest) with Fastify 5.xRequires `ignoreDuplicateSlashes: true` or `useSemicolonDelimiter: true` in Fastify configuration (via top-level option or `routerOptions`)Variant Testing**Duplicate slashes:**| Request | Express Middleware | Handler Runs | Result |
|---------|-------------------|--------------|--------|
| `GET /admin/dashboard` | Invoked (blocks) | No | 403 Forbidden |
| `GET //admin/dashboard` | Skipped | Yes | 200 OK — **BYPASS** |
| `GET ///admin/dashboard` | Skipped | Yes | 200 OK — **BYPASS** |
| `GET /.//admin/dashboard` | Skipped | Yes | 200 OK — **BYPASS** |
| `GET //admin//dashboard` | Skipped | Yes | 200 OK — **BYPASS** |
| `GET /admin//dashboard` | Invoked (blocks) | No | 403 Forbidden |**Semicolons:**| URL | Express MW Fires | Route Matches | Result |
|---|---|---|---|
| `/admin` | Yes | Yes (200/403) | Normal |
| `/admin;` | No | Yes (200) | **BYPASS** |
| `/admin;bypass` | No | Yes (200) | **BYPASS** |
| `/admin;x=1` | No | Yes (200) | **BYPASS** |
| `/admin;/dashboard` | No | Yes (200, routes to /admin) | **BYPASS** |
| `/admin/dashboard;x` | Yes | Yes (routes to /admin/dashboard) | Normal (prefix /admin/ still matches) |The semicolon bypass is effective when the semicolon appears immediately after the middleware prefix boundary. For sub-paths where the prefix is already matched (e.g., `/admin/dashboard;x`), Express's prefix regex succeeds because the `/admin/` part matches before the semicolon appears.Suggested Fix`@fastify/express` should normalize URLs before passing them to Express middleware, respecting the router normalization options that are enabled. Specifically:When `ignoreDuplicateSlashes` is enabled, apply `FindMyWay.removeDuplicateSlashes()` to `req.raw.url` before middleware executionWhen `useSemicolonDelimiter` is enabled, strip semicolon-delimited parameters from the URL before passing to ExpressThis would match the normalization behavior that `@fastify/middie` already implements via `sanitizeUrlPath()` and `normalizePathForMatching()`.
CVSS v4.0: 9.1
CVSS v3.1: 9.1