Path-Scoped Authentication Middleware Bypass: How to Find and Fix It in Fastify and Node.js APIs
On 21 November a CVE record was published for CVE-2026-124626, a CVSS 9.1 flaw in @fastify/express, the plugin that lets Express middleware run inside Fastify. An unauthenticated request with an empty path segment can reach a handler while the authentication middleware mounted on that same path never runs. It is a path-scoped authentication middleware bypass, and it is the fourth one in @fastify/express this year. Its sibling package @fastify/middie has had four more.
Eight advisories, two packages, one root cause. That pattern matters more than any single CVE, because the same mistake lives in plenty of Node.js, Python and Java codebases that have never touched Fastify. This guide explains the bug class, shows how to check your own services in about fifteen minutes, and gives a structural fix that stops the next variant too.
What actually went wrong
According to the CVE record, versions 4.0.5 through 4.0.9 of @fastify/express match path-scoped Express middleware with a matcher that needs a non-empty value for a dynamic segment, while Fastify’s router accepts an empty parameter or wildcard value. So when a route and an Express middleware share a pattern such as /tenant/:tenantId, a request with the parameter left empty matches the route and runs the handler, while the middleware mounted on that pattern is skipped. The record notes that no special configuration is needed, and that the real impact depends on what an empty value selects in your application. The fix is in 4.0.10 (4.0.13 is the current release on npm).
The earlier advisories follow the same shape:
| Advisory | Package | What the two matchers disagreed on | Fixed in |
|---|---|---|---|
| CVE-2026-22037 | @fastify/express | URL-encoded characters (/%61dmin vs /admin) | 4.0.3 |
| CVE-2026-33808 | @fastify/express | Duplicate slashes and ; delimiters when router normalisation options are on | 4.0.5 |
| CVE-2026-33807 | @fastify/express | Middleware path prefixed twice inside child plugin scopes | 4.0.5 |
| CVE-2026-124626 | @fastify/express | Empty dynamic segment or wildcard | 4.0.10 |
| CVE-2026-22031 | @fastify/middie | URL-encoded characters | 9.1.0 |
| CVE-2026-2880 | @fastify/middie | Router normalisation options (duplicate slashes, semicolons) | 9.2.0 |
| CVE-2026-33804 | @fastify/middie | Deprecated top-level ignoreDuplicateSlashes option not read | 9.3.2 |
| CVE-2026-6270 | @fastify/middie | Middleware path re-prefixed in child plugin scopes | 9.3.2 |
In every case there are two parsers. The router decides which handler runs. The middleware matcher decides which security checks run. When they read the same URL differently, the gap between them is an unauthenticated path to your handler. Security teams call this a parser differential, and it is the same family as the path-confusion bugs that have hit reverse proxies and API gateways for years.
Why path-scoped auth is fragile by design
Mounting authentication by URL prefix feels natural:
await app.register(require('@fastify/express'))
app.use('/tenant/:tenantId', requireAuth) // auth decided by URL pattern
app.get('/tenant/:tenantId', getTenant) // handler decided by router
It reads well, but it splits one decision across two components. Every normalisation rule the router applies (decoding, slash collapsing, semicolons, empty segments, trailing slashes, case, prefixes added by plugins) must be applied identically by the middleware matcher, forever, across upgrades. Each of the eight fixes above closed one rule. None of them can promise there is no ninth.
The safer model is to attach authentication to the route itself, not to a string that is supposed to match it.
A 15-minute exposure check
1. Find the packages. In each Node.js service repository:
npm ls @fastify/express @fastify/middie
Anything below @fastify/express 4.0.10 or @fastify/middie 9.3.2 is affected by at least one advisory in the table. npm audit should flag the published GHSAs, but at the time of writing the newest one may not be in every advisory database yet, so check versions directly. Do the same check against your container images and lockfiles, not only package.json: a transitive copy pinned by another package is still loaded.
2. Find path-scoped security middleware. Search for app.use( or fastify.use( calls whose first argument is a path and whose function does authentication, authorisation, tenant selection or rate limiting. Those are the mounts these bugs skip. Middleware with no path argument runs on every request and was not the target of these advisories.
3. Write the probes as tests. For every protected route, add an automated test in your own test suite that sends an unauthenticated request and expects 401 or 403, for each variant: the normal path, an encoded character (/%61dmin), a doubled slash, a ; suffix, an empty dynamic segment, and the same route under any plugin prefix. Run these against your own services only. If any variant returns 200, you have a live bypass regardless of which package version you run.
4. Check what an empty value means. The CVE record warns that impact depends on what the empty value selects. A query like WHERE tenant_id = '' might return nothing; an ORM call that drops an empty filter might return every tenant. Read the handler, not just the middleware.
The structural fix: authorise in the route, not the URL
Upgrade first. Then move security checks to Fastify’s own lifecycle hooks, which are bound to the route object after routing has happened, so there is no second matcher to disagree with:
// Every route registered inside this plugin gets the hook, whatever the URL looks like
app.register(async function protectedRoutes (scope) {
scope.addHook('onRequest', authenticate) // throws or replies 401
scope.get('/tenant/:tenantId', async (request, reply) => {
const { tenantId } = request.params
if (!tenantId || tenantId !== request.user.tenantId) {
return reply.code(403).send()
}
return loadTenant(tenantId)
})
}, { prefix: '/api' })
Three principles sit behind that snippet:
- Default deny. Put the auth hook on a scope that contains every protected route, and make public routes the explicit exception. A forgotten route then fails closed.
- Validate parameters in the handler. Reject empty or malformed identifiers with a schema (
minLength: 1on the param) and compare them with the caller’s identity. Authorisation that depends on a URL segment must check that segment. - Treat compatibility layers as temporary.
@fastify/expressand@fastify/middieexist so teams can carry Express middleware across during a migration. Security-critical middleware is the first thing to port to native hooks, not the last.
If you are not on Fastify, the lesson transfers directly. Any setup where a gateway, proxy or middleware layer enforces auth by path, and a different component routes the request, has the same two-parser risk. Our 11-19 article on publisher trust and provenance covers the other half of dependency risk: knowing what you installed in the first place.
Impact assessment
- Severity: CVSS 9.1 (network, no privileges, no user interaction; high confidentiality and integrity impact) for CVE-2026-124626.
- Who is affected: Fastify services that load
@fastify/express4.0.5–4.0.9 and mount security middleware on a path that shares a dynamic pattern with a route. Earlier versions are affected by the earlier advisories in the table. - Exploitation: we have seen no public report of exploitation as of 25 November. The request needed is trivial once someone reads the advisory, so treat this as patch-now for internet-facing APIs.
- Business risk: cross-tenant data access in multi-tenant SaaS, where the skipped middleware is often the one that checks which tenant the caller belongs to.
The CloudShieldSecure perspective
At CloudKonsult we see the same pattern in cloud estates that we see in this bug: a control that exists is assumed to apply. A WAF rule, an API gateway policy or an auth middleware is configured, so the route is ticked as protected, and nobody tests the path variants. CloudShieldSecure is built around continuous verification of what is actually exposed: which API endpoints answer without authentication, which services run dependency versions with known bypasses, and which routes have drifted away from the controls they were assigned. The question to ask is not “do we have auth middleware?” but “does every route reject an unauthenticated request in every form the router accepts?”
Recommended actions
- Run
npm ls @fastify/express @fastify/middieacross all Node.js services and images; upgrade to@fastify/express4.0.10+ (current 4.0.13) and@fastify/middie9.3.2+. - List every path-scoped
use()mount that performs authentication, authorisation, tenant selection or rate limiting. - Add unauthenticated negative tests for each protected route covering encoded, doubled-slash, semicolon, empty-segment and prefixed variants; fail the build on any 200.
- Move security checks into Fastify
onRequest/preHandlerhooks on an encapsulated scope, with default deny. - Validate route parameters (non-empty, schema-checked) and compare them to the caller’s identity inside the handler.
- Review access logs for requests to protected route patterns with empty segments since the affected versions were deployed.
Sources and references
- CVE-2026-124626 record (OpenJS Foundation CNA), via OSV and NVD; vendor advisory GHSA-662w-h4p6-jq4p
- GHSA-g6q3-96cp-5r5m / CVE-2026-22037 · GHSA-6hw5-45gm-fj88 / CVE-2026-33808 · GHSA-hrwm-hgmj-7p9c / CVE-2026-33807
- @fastify/middie: GHSA-cxrg-g7r8-w69p · GHSA-8p85-9qpw-fwgw · GHSA-v9ww-2j6r-98q6 · GHSA-72c6-fx6q-fr5w
- @fastify/express on npm (release history) · Fastify hooks documentation
Assess your security posture today
CloudShield Secure scans, validates, and prioritises threats across your entire attack surface.
Explore CloudShield Secure →