79% vs 51%: independent neobanks lag on app security. Read the report

Deep Dive

Deep Dive

Fastify Middleware Bypass Exposes Protected Routes (CVE-2026-124626)

Five path-matching flaws in Fastify's Express and middie layers let unauthenticated requests skip auth middleware; fixed in 4.0.10 and 9.3.8.

TL;DR

  • Five path-matching flaws in @fastify/express and @fastify/middie let a request reach a route handler while the path-scoped middleware mounted on the same pattern is skipped. Authentication, authorization and rate limiting can all be bypassed.
  • Every @fastify/express release before 4.0.10 is affected, and every @fastify/middie release before 9.3.8. The flaws need no special configuration, only a route and a middleware mount that share a dynamic pattern.
  • Each CVE record rates its flaw Critical, CVSS v3.1 9.1. No exploitation is known, and none of the five is in CISA KEV as of 2026-11-21.
  • Upgrade to @fastify/express 4.0.10 or later and @fastify/middie 9.3.8 or later. See "How do I fix it?" for the preHandler workaround.

Am I affected?

All of these must hold:

  • The application uses @fastify/express before 4.0.10, or @fastify/middie before 9.3.8.
  • It mounts path-scoped middleware, such as app.use('/tenant/:id/admin', auth), and relies on that middleware for authentication, authorization or rate limiting.
  • A Fastify route is reachable through a path that the two matchers read differently. Empty parameter or wildcard values, a plugin prefix join, a percent-encoded backslash, a double-encoded percent sign or an asterisk-form target can all create that difference.

The flaws affect both routers' default settings. A static mount such as app.use('/admin', auth) is not affected by the empty-segment variant, but the URL-decoding and asterisk-form variants can still skip it.

@fastify/express is often adopted when a team moves an Express application to Fastify or reuses Express middleware for sessions, authentication or rate limiting. The mount path then becomes the only guard for a group of routes. That pattern is what turns a path-parsing difference into an authentication bypass.

Package Affected versions Fixed version
@fastify/express (CVE-2026-124626) 4.0.5 to 4.0.9 4.0.10
@fastify/express (CVE-2026-129504) 4.0.0 to 4.0.9 4.0.10
@fastify/express (CVE-2026-133120) Before 4.0.10 4.0.10
@fastify/express (CVE-2026-133867) 4.0.7 to 4.0.9 4.0.10
@fastify/middie (CVE-2026-133250) 9.3.7 and earlier 9.3.8

The fixed releases are @fastify/express 4.0.10 and @fastify/middie 9.3.8, both published on 2026-11-20. The current releases are 4.0.11 and 9.3.9.

Check the installed versions and the lockfile:

npm ls @fastify/express @fastify/middie
grep -n '"@fastify/express"\|"@fastify/middie"' package-lock.json
npm view @fastify/express version
npm view @fastify/middie version

For a pnpm or Yarn workspace, run pnpm why @fastify/express @fastify/middie or yarn why @fastify/express @fastify/middie. A transitive copy counts: the package can arrive through another plugin.

How do I fix it?

Upgrade both packages to their fixed releases, then rebuild and redeploy the application.

  1. Run npm install @fastify/express@^4.0.10 @fastify/middie@^9.3.8.
  2. Update the lockfile and commit it, so every environment resolves the fixed versions.
  3. Rebuild the application and restart every instance. A rolling restart that keeps old workers alive leaves them exposed.
  4. Confirm the running versions with npm ls in the deployed image.

If you cannot upgrade yet, enforce authentication in a Fastify hook that runs after the router has resolved the request. Base the decision on the matched route, not on request.url:

fastify.addHook('preHandler', async (request, reply) => {
  if (request.routeOptions.url.startsWith('/tenant/')) {
    await requireSession(request, reply)
  }
})

This covers all five variants because the router has already chosen the handler. It requires you to enumerate the protected routes. A mount path alone is not enough, because the bypass is a disagreement about which path was matched.

An onRequest hook registered before @fastify/express can reject request targets that start with *, contain a backslash, or contain %5C or %25, checking both the raw and the decoded target, since the plugin percent-decodes the URL only after the hook runs. That is a narrower workaround: it does not cover the empty-segment, prefix-join or RegExp-mount variants, and rejecting every %25 can block legitimate requests.

What is the root cause?

Fastify's router and the middleware layer each parse the request path, and the two parsers disagree on some paths. The router dispatches the handler, the middleware matcher skips the mount, and the request runs without the middleware.

@fastify/express 4.0.9 rewrites the URL before Express sees it and then hands the request to Express in runConnect:

// index.js, 4.0.9
function enhanceRequest (req, reply, next) {
  const { url } = req.raw
  req.raw.originalUrl = url
  const normalizedUrl = normalizeUrl(url, {
    ignoreDuplicateSlashes,
    useSemicolonDelimiter
  })
  // ...
  req.raw.url = normalizedUrl
  // ...
}

function runConnect (req, reply, next) {
  if (this[kMiddlewares].length > 0) {
    // ...
    this.express(req.raw, reply.raw, next)
  } else {
    next()
  }
}

Express matches the middleware against req.raw.url. Fastify's router, find-my-way, matched the route against its own reading of the request target. When the two readings differ, the handler runs and the middleware does not.

Five differences matter:

  • path-to-regexp requires a non-empty value for a dynamic segment, while find-my-way accepts an empty one. GET /tenant//admin reaches /tenant/:id/admin with id empty, and the mount is skipped.
  • A plugin prefix ending in /, or a mount path without a leading /, makes the concatenated Express mount differ from the route Fastify serves.
  • Since 4.0.3, the plugin percent-decodes the URL before Express parses it. A backslash combined with whitespace or # is rewritten to / by Express, and %25 is decoded twice, so the middleware and the handler see different parameter values.
  • A request target that starts with *, such as *admin, is routed to /admin by find-my-way, while Express does not match a mount on /admin.
  • A RegExp mount under a parameterized plugin prefix is built with the prefix's literal :tenantId, so it never matches the concrete value.

@fastify/middie has the same class of bug in its own matcher. It compares the request path with path-to-regexp while the router uses find-my-way, and the same empty-segment, asterisk-form and literal-percent differences apply.

The five advisories are the fourth round in this area. @fastify/express fixed a prefix-rewrite bypass in 4.0.7 (CVE-2026-6556) and a path-scoped mount bypass in 4.0.9 (CVE-2026-112362). @fastify/middie fixed an absolute-form bypass in 9.3.6 and three path-scoped bypasses in 9.3.7 (CVE-2026-132131). Each fix closed the variant it described, and the next variant appeared in the same matcher.

Both parsers are reasonable in isolation. find-my-way is built for speed and accepts an empty segment as a parameter value. path-to-regexp models Express mount paths and requires at least one character. The flaw is the assumption that the two always agree on the same request. Every variant in this batch is a case where they do not.

How is it exploited?

  1. The attacker finds a route that a path-scoped middleware is meant to protect, for example /tenant/:id/admin with app.use('/tenant/:id/admin', auth).
  2. The attacker sends a request whose path matches the route in find-my-way but not the mount in path-to-regexp, for example GET /tenant//admin or GET /tenant/%5C%20/admin.
  3. Fastify dispatches the handler for /tenant/:id/admin.
  4. Express evaluates the middleware mount against the path it received and finds no match.
  5. The handler runs without the authentication, authorization or rate-limiting middleware.
  6. The attacker repeats the request with a different spelling if the first one is normalized or rejected by a proxy.

The advisories describe the requests, and the researchers reproduced the bypasses against real listeners. No public exploit code is included in the advisories. The attack needs no credentials and no user interaction.

How does the attack flow?

One request is read two ways: Fastify's router selects a protected handler, and the middleware matcher selects nothing, so the handler runs without its guard.

flowchart LR A["Request with an
ambiguous path"] --> B["find-my-way matches
the protected route"] B --> C["Handler selected"] A --> D["path-to-regexp tests
the mount path"] D --> E["No middleware match,
the mount is skipped"] C --> F["Handler runs without
authentication"] E --> F

Weekly npm downloads of Fastify, middie and the Express compatibility layer
Figure 1: The middleware layer sits under a large part of the Fastify ecosystem. Source: npm registry download counts for the week ending November 20, 2026, checked November 21, 2026

What can an attacker do?

An attacker who can reach an affected route can invoke a handler that the application meant to protect. The impact depends on what that handler does. The advisories describe access to protected routes, not remote code execution.

The impact needs all of these conditions:

  • The route is reachable from the attacker's network position.
  • A path-scoped middleware protects the route, and the middleware is the only check.
  • The route and the mount share a dynamic pattern, a prefixed plugin, or a path form the two matchers read differently.

A handler that reads or changes tenant data, an administrative endpoint, or an expensive API can be reached without the intended session. A route that also checks authorization inside the handler is not bypassed by this flaw, because that check still runs.

A skipped rate limiter has a different consequence. An endpoint that allows password attempts, invitation acceptance or expensive queries can be reached without its budget. The bypass does not create a new vulnerability in the handler, but it removes the control that made the handler safe to expose.

No exploitation in the wild is known as of 2026-11-21. The CVE records are not in CISA KEV.

Why does the fix work?

@fastify/express 4.0.10 matches middleware on the path the router resolved, rejects request targets that do not start with /, and rejects ambiguous dynamic paths before Express runs.

// index.js, 4.0.10
function runConnect (req, reply, next) {
  if (isDynamicRoute(req.routeOptions.url) && hasAmbiguousDynamicMount(this[kDynamicMountMatchers], req.raw)) {
    const error = new Error('Invalid route parameter')
    error.statusCode = 400
    next(error)
    return
  }
  // ...
  this.express(req.raw, reply.raw, caseSensitive === false ? restoreUrl : next)
}

The release also rewrites RegExp mount paths with the plugin prefix, joins prefix and mount path through one helper, and matches the path after the prefix. The @fastify/middie 9.3.8 release applies the same rules to its matcher. Empty parameter and wildcard values are allowed, targets that do not start with / are rejected, and a literal % is matched as the router keeps it encoded.

The fix is complete for the five variants the advisories describe. It is not a proof that no further path-parsing difference exists. The area has produced four rounds of fixes, and the same two-parser design remains.

How do I check if I was compromised?

No indicators of compromise are published. A successful bypass looks like a normal request to the handler, so application logs may show only the handler's own entries.

Look for requests that exercise the ambiguous forms:

# Empty dynamic segments, asterisk-form targets and encoded backslashes
grep -E 'GET /[^ ]*//|GET \*|%5[Cc]' /var/log/nginx/access.log

Review the routes that path-scoped middleware protects. If any of them handle sensitive data, check the handler logs for requests that arrived without a session where one was expected. A hit is a lead, not proof, because proxies and clients can produce the same spellings.

Timeline

  • 2026-06-30: CVE-2026-6556 is published for a prefix-rewrite bypass in @fastify/express, fixed in 4.0.7.
  • 2026-10-27: CVE-2026-112362 is published for a path-scoped mount bypass, fixed in 4.0.9.
  • 2026-11-18: @fastify/middie 9.3.7 fixes three path-scoped bypasses, including CVE-2026-132131.
  • 2026-11-20: The five new advisories are published and the fixed releases 4.0.10 and 9.3.8 ship.
  • 2026-11-21: The CVE records for the five flaws are published.

FAQ

Is this the same bug as CVE-2026-112362?

No. That advisory covered an earlier path-scoped mount bypass in @fastify/express 4.0.9. The five new CVEs describe different path forms: empty segments, prefix joins, URL decoding, RegExp mounts under a parameterized prefix, and the middie matcher.

Does the flaw affect every Fastify application?

No. It affects applications that mount path-scoped middleware and rely on it for a security decision. An application that authenticates in a Fastify hook, or inside the handler, does not depend on the skipped middleware.

Can an attacker reach an admin route without a session?

Only if the route is protected solely by the skipped middleware. The handler still runs its own checks. The bypass removes one layer, not every layer.

Are the packages still affected after the upgrade?

No. @fastify/express 4.0.10 and @fastify/middie 9.3.8 fix the five variants. The current releases are 4.0.11 and 9.3.9. Rebuild the application so the new versions are in the running image.

Was it exploited in the wild?

No exploitation is known, and none of the five CVEs is in CISA KEV as of 2026-11-21. The advisories describe reproducible bypasses but include no exploit code.

Test your Fastify routes with Ostorlab

A path-matching flaw is easy to miss in code review and hard to see from the outside. Ostorlab's web and API scanning exercises the routes an application exposes and reports the ones that answer without the authentication they should require: https://www.ostorlab.co/product/web_agentic_deep_scan

References

  • Advisory GHSA-662w-h4p6-jq4p, CVE-2026-124626: https://github.com/fastify/fastify-express/security/advisories/GHSA-662w-h4p6-jq4p (checked November 21, 2026)
  • Advisory GHSA-f44m-4qwg-5587, CVE-2026-129504: https://github.com/fastify/fastify-express/security/advisories/GHSA-f44m-4qwg-5587 (checked November 21, 2026)
  • Advisory GHSA-w877-hjcp-88rc, CVE-2026-133120: https://github.com/fastify/fastify-express/security/advisories/GHSA-w877-hjcp-88rc (checked November 21, 2026)
  • Advisory GHSA-84w6-xrf3-f8q8, CVE-2026-133867: https://github.com/fastify/fastify-express/security/advisories/GHSA-84w6-xrf3-f8q8 (checked November 21, 2026)
  • Advisory GHSA-gcf6-j9m3-p97x, CVE-2026-133250: https://github.com/fastify/middie/security/advisories/GHSA-gcf6-j9m3-p97x (checked November 21, 2026)
  • @fastify/express 4.0.10 release: https://github.com/fastify/fastify-express/releases/tag/v4.0.10 (checked November 21, 2026)
  • @fastify/middie 9.3.8 release: https://github.com/fastify/middie/releases/tag/v9.3.8 (checked November 21, 2026)
  • @fastify/express 4.0.9 source, index.js: https://github.com/fastify/fastify-express/blob/v4.0.9/index.js (checked November 21, 2026)
  • @fastify/express 4.0.10 source, index.js: https://github.com/fastify/fastify-express/blob/v4.0.10/index.js (checked November 21, 2026)
  • Advisory GHSA-6h42-57hq-9746, CVE-2026-112362: https://github.com/fastify/fastify-express/security/advisories/GHSA-6h42-57hq-9746 (checked November 21, 2026)
  • Advisory GHSA-3wf5-7852-vcfq, CVE-2026-6556: https://github.com/fastify/fastify-express/security/advisories/GHSA-3wf5-7852-vcfq (checked November 21, 2026)
  • npm download counts, week ending November 20, 2026: https://api.npmjs.org/downloads/point/last-week/fastify (checked November 21, 2026)
  • CISA Known Exploited Vulnerabilities catalog, version 2026.11.20: https://www.cisa.gov/known-exploited-vulnerabilities-catalog (checked November 21, 2026)