CVE-2026-33807: @fastify/express Authentication Bypass Vulnerability

CRITICAL
Advisory Identifier: GHSA-hrwm-hgmj-7p9c
CVSS 9.1
CWE-436
Published
Advisory Summary

CVE-2026-33807 is a CRITICAL (CVSS 9.1) authentication bypass vulnerability (CWE-436: Interpretation Conflict) affecting @fastify/express libraries in the npm ecosystem. The issue involves @fastify/express's middleware path doubling causes authentication bypass in child plugin scopes. Remediation is available by upgrading affected packages to version 4.0.5.

CVE-2026-33807 at a Glance

CVE Identifier CVE-2026-33807
GHSA Identifier GHSA-hrwm-hgmj-7p9c
Severity CRITICAL
CVSS v3.1 Base Score 9.1
CWE Classification CWE-436: Interpretation Conflict
Affected Product @fastify/express
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 9.1

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2026-33807

To remediate this vulnerability, upgrade all affected @fastify/express dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

@fastify/express fixed: 4.0.5
npm install @fastify/express@4.0.5
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls @fastify/express

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2026-33807, inspect your project dependencies using npm:

npm ls @fastify/express

Analyze the terminal output to locate any version of @fastify/express in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 4.0.5), your application is affected.

Note: The npm ls @fastify/express command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-436: Interpretation Conflict, where product a handles inputs or steps differently than product b, which causes a to perform incorrect actions based on its perception of b's state. In @fastify/express, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary `@fastify/express` v4.0.4 contains a path handling bug in the `onRegister` function that causes middleware paths to be doubled when inherited by child plugins. This results in complete bypass of Express middleware security controls for all routes defined within child plugin scopes that share a prefix with parent-scoped middleware. No special configuration is required — this affects the default Fastify configuration. ### Details The vulnerability exists in the `onRegister` function at `index.js` lines 92-101. When a child plugin is registered with a prefix, the `onRegister` hook copies middleware from the parent scope and re-registers it using `instance.use(...middleware)`. However, the middleware paths stored in `kMiddlewares` are already prefixed from their original registration. The call flow demonstrates the problem: 1. Parent scope registers middleware: `app.use('/admin', authFn)` — `use()` calculates path as `'' + '/admin' = '/admin'` — stores `['/admin', authFn]` in `kMiddlewares` 2. Child plugin registers with `{ prefix: '/admin' }` — triggers `onRegister(instance)` 3. `onRegister` copies parent middleware and calls `instance.use('/admin', authFn)` on child 4. Child's `use()` function calculates path as `'/admin' + '/admin' = '/admin/admin'` — registers middleware with doubled path 5. Routes in child scope use the child's Express instance, where middleware is registered under the incorrect path `/admin/admin` 6. Requests to `/admin/secret` don't match `/admin/admin` — middleware is silently skipped The root cause is in the `use()` function at lines 25-26, which always prepends `this.prefix` to string paths, combined with `onRegister` re-calling `use()` with already-prefixed paths. ### PoC ```javascript const fastify = require('fastify'); const http = require('http'); function get(port, url) { return new Promise((resolve, reject) => { http.get('http://localhost:' + port + url, (res) => { let data = ''; res.on('data', (chunk) => data += chunk); res.on('end', () => resolve({ status: res.statusCode, body: data })); }).on('error', reject); }); } async function test() { const app = fastify({ logger: false }); await app.register(require('@fastify/express')); // Middleware enforcing auth on /admin routes app.use('/admin', function(req, res, next) { if (!req.headers.authorization) { res.statusCode = 403; res.setHeader('content-type', 'application/json'); res.end(JSON.stringify({ error: 'Forbidden' })); return; } next(); }); // Root scope route — middleware works correctly app.get('/admin/root-data', async () => ({ data: 'root-secret' })); // Child scope route — middleware BYPASSED await app.register(async function(child) { child.get('/secret', async () => ({ data: 'child-secret' })); }, { prefix: '/admin' }); await app.listen({ port: 19876, host: '0.0.0.0' }); // Root scope: correctly blocked let r = await get(19876, '/admin/root-data'); console.log('/admin/root-data (no auth):', r.status, r.body); // Output: 403 {"error":"Forbidden"} // Child scope: BYPASSED — secret data returned without auth r = await get(19876, '/admin/secret'); console.log('/admin/secret (no auth):', r.status, r.body); // Output: 200 {"data":"child-secret"} await app.close(); } test(); ``` Actual output: ``` /admin/root-data (no auth): 403 {"error":"Forbidden"} /admin/secret (no auth): 200 {"data":"child-secret"} ``` ### Impact Complete bypass of Express middleware security controls for all routes defined in child plugin scopes. Authentication, authorization, rate limiting, CSRF protection, audit logging, and any other middleware-based security mechanisms are silently skipped for affected routes. - No special request crafting is required — normal requests bypass the middleware - It affects the idiomatic Fastify plugin pattern commonly used in production - The bypass is silent with no errors or warnings - Developers' basic testing of root-scoped routes will pass, masking the vulnerability - Any child plugin scope that shares a prefix with middleware is affected Applications using `@fastify/express` with path-scoped middleware and child plugins with matching prefixes are vulnerable in default configurations. ### Affected Versions - `@fastify/express` v4.0.4 (latest at time of discovery) - Fastify 5.x in default configuration - No special router options required (`ignoreDuplicateSlashes` not needed) - Affects any child plugin registration where the prefix overlaps with middleware path scoping - Does NOT affect middleware registered without path scoping (global middleware) - Does NOT affect middleware registered on root path (`/`) due to special case handling ### Variant Testing | Scenario | Middleware Path | Child Prefix | Result | |---|---|---|---| | Root route `/admin/root-data` | `/admin` | N/A | Middleware runs (403) | | Child route `/admin/secret` | `/admin` | `/admin` | **BYPASS** (200) | | Child route `/api/data` | `/api` | `/api` | **BYPASS** (200) | | Nested child `/admin/sub/data` | `/admin` | `/admin/sub` | **BYPASS** — path becomes `/admin/sub/admin` | | Middleware on `/` with any child | `/` | `/api` | No bypass — `path === '/' && prefix.length > 0` special case | ### Suggested Fix The `onRegister` function should store and re-use the original unprefixed middleware paths, or avoid re-calling the `use()` function entirely. Options include: 1. Store the original path and function separately in `kMiddlewares` before prefixing 2. Strip the parent prefix before re-registering in child scopes 3. Store already-constructed Express middleware objects rather than re-processing paths

CVE-2026-33807 Affected @fastify/express Versions

1 component(s)
Fixed Versions:
4.0.5
Product / Package Ecosystem Affected Versions Fixed Version
@fastify/express
npm
< 4.0.5
4.0.5

References

Frequently Asked Questions

What is CVE-2026-33807?
CVE-2026-33807 is a security vulnerability in @fastify/express involving @fastify/express's middleware path doubling causes authentication bypass in child plugin scopes under CWE-436: Interpretation Conflict.
Which @fastify/express versions are affected?
Affected versions include releases prior to 4.0.5 across affected packages: @fastify/express.
What version fixes CVE-2026-33807?
Upgrading to 4.0.5 (or the latest patched release for your respective branch) resolves the vulnerability.
Is @fastify/express affected?
Yes, @fastify/express is affected in releases prior to 4.0.5. Upgrade your dependency to 4.0.5 or later.
What is the CVSS score of CVE-2026-33807?
CVE-2026-33807 has a CVSS v3.1 base score of 9.1 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N.
What CWE is associated with CVE-2026-33807?
CVE-2026-33807 is classified under CWE-436: Interpretation Conflict (Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state.).
How can I check npm dependencies for CVE-2026-33807?
Run the dependency tree command: 'npm ls @fastify/express'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-hrwm-hgmj-7p9c",
  "modified" : "2026-04-16T01:03:25Z",
  "published" : "2026-04-16T01:03:25Z",
  "aliases" : [ "CVE-2026-33807" ],
  "summary" : "@fastify/express's middleware path doubling causes authentication bypass in child plugin scopes",
  "details" : "### Summary\n\n`@fastify/express` v4.0.4 contains a path handling bug in the `onRegister` function that causes middleware paths to be doubled when inherited by child plugins. This results in complete bypass of Express middleware security controls for all routes defined within child plugin scopes that share a prefix with parent-scoped middleware. No special configuration is required — this affects the default Fastify configuration.\n\n### Details\n\nThe vulnerability exists in the `onRegister` function at `index.js` lines 92-101. When a child plugin is registered with a prefix, the `onRegister` hook copies middleware from the parent scope and re-registers it using `instance.use(...middleware)`. However, the middleware paths stored in `kMiddlewares` are already prefixed from their original registration.\n\nThe call flow demonstrates the problem:\n1. Parent scope registers middleware: `app.use('/admin', authFn)` — `use()` calculates path as `'' + '/admin' = '/admin'` — stores `['/admin', authFn]` in `kMiddlewares`\n2. Child plugin registers with `{ prefix: '/admin' }` — triggers `onRegister(instance)`\n3. `onRegister` copies parent middleware and calls `instance.use('/admin', authFn)` on child\n4. Child's `use()` function calculates path as `'/admin' + '/admin' = '/admin/admin'` — registers middleware with doubled path\n5. Routes in child scope use the child's Express instance, where middleware is registered under the incorrect path `/admin/admin`\n6. Requests to `/admin/secret` don't match `/admin/admin` — middleware is silently skipped\n\nThe root cause is in the `use()` function at lines 25-26, which always prepends `this.prefix` to string paths, combined with `onRegister` re-calling `use()` with already-prefixed paths.\n\n### PoC\n\n```javascript\nconst fastify = require('fastify');\nconst http = require('http');\n\nfunction get(port, url) {\n  return new Promise((resolve, reject) => {\n    http.get('http://localhost:' + port + url, (res) => {\n      let data = '';\n      res.on('data', (chunk) => data += chunk);\n      res.on('end', () => resolve({ status: res.statusCode, body: data }));\n    }).on('error', reject);\n  });\n}\n\nasync function test() {\n  const app = fastify({ logger: false });\n  await app.register(require('@fastify/express'));\n  \n  // Middleware enforcing auth on /admin routes\n  app.use('/admin', function(req, res, next) {\n    if (!req.headers.authorization) {\n      res.statusCode = 403;\n      res.setHeader('content-type', 'application/json');\n      res.end(JSON.stringify({ error: 'Forbidden' }));\n      return;\n    }\n    next();\n  });\n  \n  // Root scope route — middleware works correctly\n  app.get('/admin/root-data', async () => ({ data: 'root-secret' }));\n  \n  // Child scope route — middleware BYPASSED\n  await app.register(async function(child) {\n    child.get('/secret', async () => ({ data: 'child-secret' }));\n  }, { prefix: '/admin' });\n  \n  await app.listen({ port: 19876, host: '0.0.0.0' });\n  \n  // Root scope: correctly blocked\n  let r = await get(19876, '/admin/root-data');\n  console.log('/admin/root-data (no auth):', r.status, r.body);\n  // Output: 403 {\"error\":\"Forbidden\"}\n  \n  // Child scope: BYPASSED — secret data returned without auth\n  r = await get(19876, '/admin/secret');\n  console.log('/admin/secret (no auth):', r.status, r.body);\n  // Output: 200 {\"data\":\"child-secret\"}\n  \n  await app.close();\n}\ntest();\n```\n\nActual output:\n```\n/admin/root-data (no auth): 403 {\"error\":\"Forbidden\"}\n/admin/secret (no auth): 200 {\"data\":\"child-secret\"}\n```\n\n### Impact\n\nComplete bypass of Express middleware security controls for all routes defined in child plugin scopes. Authentication, authorization, rate limiting, CSRF protection, audit logging, and any other middleware-based security mechanisms are silently skipped for affected routes.\n\n- No special request crafting is required — normal requests bypass the middleware\n- It affects the idiomatic Fastify plugin pattern commonly used in production\n- The bypass is silent with no errors or warnings\n- Developers' basic testing of root-scoped routes will pass, masking the vulnerability\n- Any child plugin scope that shares a prefix with middleware is affected\n\nApplications using `@fastify/express` with path-scoped middleware and child plugins with matching prefixes are vulnerable in default configurations.\n\n### Affected Versions\n\n- `@fastify/express` v4.0.4 (latest at time of discovery)\n- Fastify 5.x in default configuration\n- No special router options required (`ignoreDuplicateSlashes` not needed)\n- Affects any child plugin registration where the prefix overlaps with middleware path scoping\n- Does NOT affect middleware registered without path scoping (global middleware)\n- Does NOT affect middleware registered on root path (`/`) due to special case handling\n\n### Variant Testing\n\n| Scenario | Middleware Path | Child Prefix | Result |\n|---|---|---|---|\n| Root route `/admin/root-data` | `/admin` | N/A | Middleware runs (403) |\n| Child route `/admin/secret` | `/admin` | `/admin` | **BYPASS** (200) |\n| Child route `/api/data` | `/api` | `/api` | **BYPASS** (200) |\n| Nested child `/admin/sub/data` | `/admin` | `/admin/sub` | **BYPASS** — path becomes `/admin/sub/admin` |\n| Middleware on `/` with any child | `/` | `/api` | No bypass — `path === '/' && prefix.length > 0` special case |\n\n### Suggested Fix\n\nThe `onRegister` function should store and re-use the original unprefixed middleware paths, or avoid re-calling the `use()` function entirely. Options include:\n1. Store the original path and function separately in `kMiddlewares` before prefixing\n2. Strip the parent prefix before re-registering in child scopes\n3. Store already-constructed Express middleware objects rather than re-processing paths",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@fastify/express"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "4.0.5"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 4.0.4"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/fastify/fastify-express/security/advisories/GHSA-hrwm-hgmj-7p9c"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-33807"
  }, {
    "type" : "WEB",
    "url" : "https://cna.openjsf.org/security-advisories.html"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/fastify/fastify-express"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-436" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-04-16T01:03:25Z",
    "nvd_published_at" : "2026-04-15T10:16:48Z"
  }
}