CVE-2026-22031: @fastify/middie Fastify Middie Middleware Path Bypass Vulnerability
HIGHCVE-2026-22031 is a HIGH (CVSS 8.4) fastify middie middleware path bypass vulnerability (CWE-177: Improper Handling of URL Encoding (Hex Encoding)) affecting @fastify/middie libraries in the npm ecosystem. The issue involves fastify middie middleware path bypass. Remediation is available by upgrading affected packages to version 9.1.0.
CVE-2026-22031 at a Glance
Security Impact
CVSS: 8.4
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:L).
How to Fix CVE-2026-22031
To remediate this vulnerability, upgrade all affected @fastify/middie dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
npm install @fastify/middie@9.1.0
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
npm ls @fastify/middie
How to Check if You Are Affected
To determine whether your Node.js application is affected by CVE-2026-22031, inspect your project dependencies using npm:
npm ls @fastify/middie
Analyze the terminal output to locate any version of @fastify/middie in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 9.1.0), your application is affected.
Note: The npm ls @fastify/middie 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-177: Improper Handling of URL Encoding (Hex Encoding), where the product does not properly handle when all or part of an input has been url encoded. In @fastify/middie, 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
CVE-2026-22031 Affected @fastify/middie Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
@fastify/middie
|
npm |
< 9.1.0
|
9.1.0
|
References
Frequently Asked Questions
What is CVE-2026-22031?
Which @fastify/middie versions are affected?
What version fixes CVE-2026-22031?
Is @fastify/middie affected?
What is the CVSS score of CVE-2026-22031?
What CWE is associated with CVE-2026-22031?
How can I check npm dependencies for CVE-2026-22031?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-cxrg-g7r8-w69p",
"modified" : "2026-01-20T16:34:50Z",
"published" : "2026-01-20T16:34:50Z",
"aliases" : [ "CVE-2026-22031" ],
"summary" : "Fastify Middie Middleware Path Bypass",
"details" : "### 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.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:L"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "npm",
"name" : "@fastify/middie"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "9.1.0"
} ]
} ],
"database_specific" : {
"last_known_affected_version_range" : "<= 9.0.3"
}
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/fastify/middie/security/advisories/GHSA-cxrg-g7r8-w69p"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-22031"
}, {
"type" : "WEB",
"url" : "https://github.com/fastify/middie/pull/245"
}, {
"type" : "WEB",
"url" : "https://github.com/fastify/middie/commit/d44cd56eb724490babf7b452fdbbdd37ea2effba"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/fastify/middie"
}, {
"type" : "WEB",
"url" : "https://github.com/fastify/middie/releases/tag/v9.1.0"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-177" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2026-01-20T16:34:50Z",
"nvd_published_at" : "2026-01-19T16:15:54Z"
}
}