{"id":"CVE-2026-33807","aliases":["CVE-2026-33807","GHSA-hrwm-hgmj-7p9c"],"related":["CVE-2026-6270"],"kind":"vulnerability","state":"published","title":"@fastify/express vulnerable to middleware path doubling causing authentication bypass in child plugin scopes","summary":"@fastify/express v4.0.4 and earlier contains a path handling bug in the onRegister function that causes middleware paths to be doubled when inherited by child plugins. When a child plugin is registered with a prefix that matches a middleware path, the middleware path is prefixed a second time, causing it to never match incoming requests. This results in complete bypass of Express middleware security controls, including authentication, authorization, and rate limiting, for all routes defined within affected child plugin scopes. No special configuration or request crafting is required.\n\nUpgrade to @fastify/express v4.0.5 or later.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"@fastify/express v4.0.4 and earlier contains a path handling bug in the onRegister function that causes middleware paths to be doubled when inherited by child plugins. When a child plugin is registered with a prefix that matches a middleware path, the middleware path is prefixed a second time, causing it to never match incoming requests. This results in complete bypass of Express middleware security controls, including authentication, authorization, and rate limiting, for all routes defined within affected child plugin scopes. No special configuration or request crafting is required.\n\nUpgrade to @fastify/express v4.0.5 or later.","source":"cvelist"},{"lang":"en","text":"### 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","format":"markdown","source":"ghsa"},{"lang":"es","text":"@fastify/express v4.0.4 y anteriores contiene un error de manejo de rutas en la función onRegister que provoca que las rutas de middleware se dupliquen cuando son heredadas por plugins hijos. Cuando un plugin hijo se registra con un prefijo que coincide con una ruta de middleware, la ruta de middleware se prefija una segunda vez, lo que provoca que nunca coincida con las solicitudes entrantes. Esto resulta en una omisión completa de los controles de seguridad de middleware de Express, incluyendo autenticación, autorización y limitación de velocidad, para todas las rutas definidas dentro de los ámbitos de los plugins hijos afectados. No se requiere configuración especial ni elaboración de solicitudes.\n\nActualice a @fastify/express v4.0.5 o posterior.","source":"nvd"}],"published":"2026-04-15T09:52:26.838Z","modified":"2026-10-26T21:10:00.170Z","severity":{"scorer":"openjs","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N","score":9.1,"rating":"CRITICAL"},"severities":[{"scorer":"openjs","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N","score":9.1,"rating":"CRITICAL"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N","score":9.1,"rating":"CRITICAL"}],"cwes":["CWE-436"],"affected":[{"ranges":[{"type":"semver","introduced":"0","fixed":"4.0.5","status":"affected"},{"type":"semver","version":"4.0.5","status":"unaffected"}],"vendor":"fastify","product":"@fastify/express","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"4.0.5"}],"ecosystem":"npm","package":"@fastify/express","purl":"pkg:npm/%40fastify/express","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"4.0.5"}],"vendor":"fastify","product":"fastify/express","cpe":"cpe:2.3:a:fastify:fastify\\/express:*:*:*:*:*:node.js:*:*","source":"nvd"}],"references":[{"url":"https://github.com/fastify/fastify-express/security/advisories/GHSA-hrwm-hgmj-7p9c","tags":["exploit","mitigation","vendor-advisory","web"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://cna.openjsf.org/security-advisories.html","tags":["vendor-advisory","web"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-33807","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/fastify/fastify-express","tags":["package"],"sources":["ghsa"]}],"credits":["FredKSchott","mcollina","UlisesGascon","climba03003"],"assigner":"openjs","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"total","date":"2026-04-15T13:09:41.621Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-33807","url":"https://www.cve.org/CVERecord?id=CVE-2026-33807","licence":"CVE Terms of Use","modified":"2026-04-15T13:09:45.259Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-hrwm-hgmj-7p9c","url":"https://github.com/advisories/GHSA-hrwm-hgmj-7p9c","licence":"CC-BY-4.0","modified":"2026-07-08T08:14:43.215Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-33807","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-33807","licence":"Public domain","modified":"2026-10-26T21:10:00.170Z"}],"updatedAt":"2026-11-25T22:59:18.825Z","epss":{"score":0.00447,"percentile":0.4061,"date":"2026-12-01T12:00:22.000Z"}}