CVE-2026-124626 — @fastify/express @fastify/express — CWE-287 · CWE-436
CVE-2026-124626 is a CRITICAL severity security vulnerability (CWE-287, CWE-436) (CVSS 9.1/10 (EPSS: 0.8%)) affecting @fastify/express @fastify/express. Technical vector analysis shows that an attacker can exploit this flaw remotely over the network without authentication (PR:N) with zero user interaction (UI:N), resulting in complete compromise of system confidentiality and integrity (C:H/I:H).
📄 Official NVD / MITRE Original Record Text
@fastify/express is a compatibility layer that lets Express middleware run inside the Fastify web framework. In versions 4.0.5 through 4.0.9, the plugin matches path-scoped Express middleware with a matcher that requires a non-empty value for a dynamic segment, while Fastify's router accepts an empty parameter or wildcard value. When a route and an Express middleware mount share a dynamic pattern, a request with an empty segment matches the Fastify route and runs the handler while the middleware mounted on that pattern is skipped, so on a scoped mount an unauthenticated request can reach a protected handler. No special configuration is required, and the practical impact depends on what the empty value selects in the application. The issue is fixed in @fastify/express 4.0.10, and users should upgrade to 4.0.10 or later.
🎯 What is this vulnerability?
Vulnerability ID: CVE‑2026‑124626
Affected component: @fastify/express (Fastify‑Express compatibility plugin) – versions 4.0.5 through 4.0.9
CVSS v3.1: 9.1 / 10 (CRITICAL) – AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N
Technical flaw
@fastify/express lets an Express‑style middleware stack be mounted inside a Fastify application.
When a path‑scoped Express middleware is registered, the plugin builds a Fastify route matcher that mirrors the Express pattern.
- In Express, a dynamic segment (e.g.,
/:id) does not match an empty string – the segment must contain at least one character. - Fastify’s router, however, treats the same pattern as matching an empty value (or a wildcard) when the request URL contains a double slash or a trailing slash that yields an empty segment.
- Fastify resolves the route and executes
handler. - The Express middleware is bypassed because its matcher never fires for the empty segment.
- AV:N – exploitable over the network.
- AC:L – low attack complexity (just a crafted URL).
- PR:N – no privileges required.
- UI:N – no user interaction needed. S:U – impact is unchanged* across the vulnerable component.
- C:H / I:H – full confidentiality and integrity breach (protected resources become reachable).
- A:N – no direct denial‑of‑service effect.
Consequences:
| Step | Expected Fastify/Express behaviour | Actual behaviour in 4.0.5‑4.0.9 |
|---|---|---|
1️⃣ Route registration (fastify.get('/users/:id', handler)) | Fastify will match /users/123 but not /users/ (empty :id). | Fastify does match /users/ (empty :id). |
2️⃣ Express middleware mount (fastify.use('/users/:id', authMw)) | Express middleware should be invoked for any request that matches the same pattern, i.e. only when :id is non‑empty. | The plugin’s matcher skips the middleware when the segment is empty, because it re‑uses Fastify’s permissive match. |
Thus, when a protected handler (handler) is behind an authentication/authorization middleware (authMw) that is mounted on the same dynamic path, an attacker can send a request where the dynamic segment is empty (e.g., GET /users/) and:
The flaw is a classic authorization bypass (CWE‑287: Improper Authentication) caused by an interpretation conflict between two routing engines (CWE‑436). No authentication check is performed for the empty‑segment request, allowing unauthenticated access to a handler that is assumed to be protected.
The CVSS vector reflects this:
⚡ Attack Chain
Below is a realistic, step‑by‑step exploitation flow. All commands are illustrative; the exact route names depend on the target application.
1️⃣ Discovery & Reconnaissance
| Action | How it is performed |
|---|---|
| Identify Fastify usage | Scan the public surface (e.g., npm view <package> or package-lock.json in a disclosed repo) for fastify and @fastify/express. |
| Fingerprint plugin version | Look for the @fastify/express version in package.json, package-lock.json, or via HTTP response headers that leak the version (some apps expose X-Powered-By: Fastify and a custom header X-Express-Compat-Version). |
| Locate a protected route | Enumerate endpoints (e.g., via OpenAPI spec, Swagger UI, or by brute‑forcing common REST paths). Identify routes that are *supposed* to be behind authentication middleware (e.g., /api/users/:userId/profile). |
| Confirm dynamic segment handling | Send two requests: <br> GET /api/users/123/profile → expect 401/403 (protected). <br> GET /api/users//profile (empty segment) → if the response is 200 or returns data, the vulnerability is present. |
2️⃣ Exploitation
Goal – Reach a handler that should be protected by an Express middleware but is bypassed due to the empty‑segment match.
Note: The exact URI (/api/users/:userId/profile) is an illustrative example; replace it with the real pattern discovered in step 1.# Illustrative PoC using curl
# The double slash creates an empty segment for the dynamic parameter ":userId"
curl -i -s "http://target.example.com/api/users//profile"Expected outcome on a vulnerable system
Set-Cookie or Authorization header challenges because the auth middleware never ran.If the server returns a 401/403, the target is either not vulnerable or the route does not share the same dynamic pattern between Fastify and Express.
3️⃣ Post‑Exploitation
The concrete impact depends on what the protected handler does. Typical high‑impact scenarios:
| Protected handler | Potential post‑exploitation outcome |
|---|---|
User profile endpoint (GET /users/:id/profile) | Disclosure of personal data (PII), API keys, or session tokens → confidentiality breach. |
Admin dashboard (GET /admin/:section) | Ability to read or modify configuration, create new admin users, or trigger privileged actions → integrity breach. |
File download (GET /files/:fileId) | Direct download of arbitrary files stored on the server (e.g., backups, source code) → confidentiality breach. |
State‑changing endpoint (POST /settings/:id) | If the same pattern is used for a POST/PUT route, an attacker could *write* data without auth, leading to integrity compromise (e.g., change email, password, or webhook URLs). |
Because the vulnerability bypasses authentication entirely, an attacker can chain this with other application‑specific logic (e.g., CSRF tokens, rate‑limiting bypass) to achieve a full compromise of the affected service.
🌍 Real‑World Impact
| CIA Triad | CVSS‑derived impact | Practical consequence |
|---|---|---|
| Confidentiality (C:H) | High – attacker can retrieve data that the application assumes is protected. | Exposure of user records, API keys, internal identifiers, or any data returned by the protected handler. |
| Integrity (I:H) | High – attacker can invoke state‑changing handlers without auth (if such handlers share the same pattern). | Unauthorized modification of resources, creation of privileged accounts, alteration of configuration, injection of malicious payloads. |
| Availability (A:N) | None – the bug does not directly cause denial‑of‑service. | No direct DoS, but indirect effects (e.g., data exfiltration leading to service shutdown) are possible. |
Typical victims
@fastify/express 4.0.5‑4.0.9 in production.Given the network‑accessible, unauthenticated nature of the flaw, an external attacker can exploit it without prior foothold, making it a critical risk for any internet‑facing deployment.
🛡️ Remediation & Mitigation
1️⃣ Patch
| Affected versions | Fixed in |
|---|---|
@fastify/express 4.0.5 – 4.0.9 | 4.0.10 (or any later release) |
Upgrade steps
# Using npm
npm install @fastify/express@^4.0.10 --save
# Using yarn
yarn add @fastify/express@^4.0.10After upgrading, verify the version:
npm list @fastify/express
# → @fastify/[email protected]2️⃣ Workarounds (if immediate upgrade is impossible)
| Mitigation | How to implement |
|---|---|
| Explicit route validation | Add a Fastify pre‑handler that rejects empty dynamic segments before the request reaches the Express middleware. Example (illustrative): |
fastify.addHook('preHandler', (request, reply, done) => {
const emptyParam = Object.values(request.params).some(v => v === '');
if (emptyParam) {
return reply.code(400).send({ error: 'Invalid path parameter' });
}
done();
});|
| Mount Express middleware on a non‑dynamic base path | Instead of fastify.use('/users/:id', authMw), mount on /users and perform the :id check inside the middleware itself. |
|---|---|
| WAF / ModSecurity rule | Block requests that contain a double slash (//) in the URL path for routes that are known to be protected. Example ModSecurity rule (illustrative): |
SecRule REQUEST_URI "@rx \/[^\/]+\/\/[^\/]+" "id:1000010,phase:2,deny,status:403,msg:'Empty path segment detected'"|
| Network segmentation | Restrict external access to the vulnerable API endpoints (e.g., via firewall or API gateway) to trusted IP ranges until the patch is applied. |
|---|---|
| Logging & monitoring | Enable detailed request logging (including request.params) and alert on empty‑segment accesses. |
3️⃣ Detection – Indicators of Compromise
| Log source | Pattern to watch for |
|---|---|
Fastify access logs (e.g., pino output) | msg="request completed" url="/api/users//profile" status=200 (status 200 on a route that normally returns 401/403). |
| Express middleware logs (if they log entry/exit) | Absence of the expected auth‑middleware log line for a request that otherwise matches the route. |
| Web server (NGINX/Apache) access logs | GET /api/users//profile HTTP/1.1" 200 where the same endpoint with a non‑empty segment returns 401/403. |
| Application‑level audit logs | Successful privileged actions (e.g., admin:updateUser) originating from a source IP that never performed a prior authentication event. |
| IDS/IPS signatures | Look for the double‑slash pattern in HTTP requests targeting known dynamic routes. |
Sample pino log snippet (vulnerable case)
{"level":30,"time":1732324801234,"pid":12345,"hostname":"app01","msg":"request completed","reqId":"abc123","method":"GET","url":"/api/users//profile","statusCode":200,"responseTime":12}In a patched system the same request would be rejected (e.g., 400/404) or the auth middleware would log a denial.
⚠️ Urgency
@fastify/express 4.0.5‑4.0.9 and mounts authentication/authorization middleware on dynamic routes.Recommended timeline
| Timeframe | Action |
|---|---|
| 0‑24 h | Identify affected instances, verify version, apply the upgrade to 4.0.10 (or later). |
| 24‑72 h | Deploy temporary mitigations (pre‑handler validation, WAF rule) if upgrade cannot be completed immediately. |
| ≤ 1 week | Verify remediation via testing (double‑slash request should now return 400/401/403). |
| Ongoing | Add monitoring for empty‑segment requests and enforce strict version pinning in package.json to prevent accidental regression. |
Bottom line: The flaw stems from a mismatch between Fastify’s permissive routing and Express’s stricter segment validation, resulting in an authentication bypass for empty dynamic segments. Because the bypass is trivial to trigger and can expose or modify any data behind the protected handler, the vulnerability must be patched immediately.
[🤖 CVE Professor AI Security Engine]
FOFA Query