CVE-2026-135279 — @fastify/express (4.0.14) — CWE-287 · CWE-436
@fastify/express is the plugin that lets an application run Express middleware and Express applications inside the Fastify web framework. In versions before 4.0.14, a request with an empty dynamic route parameter reaches a Fastify route handler while middleware mounted for that path inside an Express Router or sub-application is skipped, because Fastify's router accepts an empty value where Express requires a non-empty one, and an unanchored regular-expression mount passed to the plugin is bypassed the same way. An earlier fix covered only the mount paths passed to the plugin directly, not middleware mounted inside a routed Express application. An attacker can use this to bypass authentication or other middleware-based access controls on the affected routes, with the practical impact depending on what the empty value selects in the application. The issue is fixed in @fastify/express 4.0.14, and users should upgrade to 4.0.14 or later. As a workaround, enforce authentication in a Fastify hook such as preHandler that runs after routing, mount the middleware on a static parent path, or require non-empty values in the route params schema.
@fastify/express is the plugin that lets an application run Express middleware and Express applications inside the Fastify web framework. In versions before 4.0.14, a request with an empty dynamic route parameter reaches a Fastify route handler while middleware mounted for that path inside an Express Router or sub-application is skipped, because Fastify's router accepts an empty value where Express requires a non-empty one, and an unanchored regular-expression mount passed to the plugin is bypassed the same way. An earlier fix covered only the mount paths passed to the plugin directly, not middleware mounted inside a routed Express application. An attacker can use this to bypass authentication or other middleware-based access controls on the affected routes, with the practical impact depending on what the empty value selects in the application. The issue is fixed in @fastify/express 4.0.14, and users should upgrade to 4.0.14 or later. As a workaround, enforce authentication in a Fastify hook such as preHandler that runs after routing, mount the middleware on a static parent path, or require non-empty values in the route params schema.
CVE‑2026‑135279 – Fastify‑Express Plugin Route‑Parameter Bypass
🎯 What is this vulnerability?
| Item | Detail |
|---|---|
| Component | @fastify/express plugin (versions < 4.0.14) |
| Vulnerable function | The bridge that forwards an incoming Fastify request to an embedded Express router/sub‑application. |
| Root cause | CWE‑287: Improper Authentication – the plugin relies on the *Fastify* router to decide whether a request matches a route before invoking the *Express* middleware stack. Fastify’s router treats a dynamic route parameter (/:id) as a match even when the captured value is an empty string (""). Express, by contrast, does not consider an empty segment a match for a dynamic parameter. The plugin therefore skips the Express middleware (often authentication, ACL, CSRF checks, etc.) when the request URL contains an empty value for a parameter that the Fastify route expects. <br><br>CWE‑436: Interpretation Conflict – the mismatch in path‑matching semantics between Fastify and Express creates an interpretation conflict that the bridge fails to reconcile. The plugin only normalised mount‑paths supplied directly to it; it did not normalise paths that are later added inside an Express router or sub‑application, leaving the conflict exploitable. |
Technical flow of the flaw
1. Fastify registers a route, e.g. fastify.get('/api/users/:userId', handler).
2. Inside the Fastify handler the plugin mounts an Express router:
fastify.register(require('@fastify/express')).after(() => {
const router = require('express').Router();
router.use(authMiddleware); // <‑‑ authentication
router.get('/profile', (req, res) => { … });
fastify.use('/api/users/:userId', router);
});3. A request arrives at /api/users//profile (note the double slash → empty userId).
4. Fastify’s router matches the path because it only checks that a segment exists; the captured userId value is the empty string.
5. The plugin forwards the request to the Express router without re‑evaluating the empty segment. Express treats the empty segment as non‑matching for :userId, so the request is considered to be targeting the mounted base path (/api/users/) without any further sub‑path. Consequently the Express router’s middleware stack (including authMiddleware) is never executed and the request is handed directly to the Fastify handler (or to a downstream Fastify route that may be less protected).
The result is a bypass of any middleware‑based access control that lives inside the Express router/sub‑application for routes that contain a dynamic parameter.
⚡ Attack Chain
1. Discovery & Reconnaissance
| Step | Technique | Expected Artefacts |
|---|---|---|
| a. Identify Fastify usage | Scan public HTTP headers, error pages, or JavaScript bundles for strings like fastify, @fastify/express, or fastify-express (e.g., X-Powered-By: Fastify). | Header X-Powered-By: Fastify or stack traces in 404/500 pages. |
| b. Fingerprint plugin version | Query the package.json via exposed source‑code repositories (GitHub, GitLab) or by requesting /package.json if the server mistakenly serves it. Look for "@fastify/express": "4.0.x" or earlier. | "@fastify/express": "4.0.12" → vulnerable. |
| c. Locate dynamic‑parameter routes | Use automated crawling (e.g., ffuf, dirsearch) with patterns that include double slashes (//) or empty segments to see if the server returns a *different* response (e.g., a protected page becomes accessible). | Response code 200 with content that normally requires authentication when the request contains //. |
2. Exploitation
Note: The exact endpoint (/api/users/:userId/profile) is an illustrative example. The attack works on any Fastify route that contains a dynamic segment and mounts an Express router/sub‑app under that route.Goal: Reach a protected Express endpoint while skipping its authentication middleware.
PoC (cURL)
# Illustrative target: protected profile endpoint
# Normal request (requires auth):
# GET /api/users/123/profile → 401 Unauthorized
# Exploit request (empty param):
# GET /api/users//profile → 200 OK (auth bypass)
curl -i -s "http://victim.example.com/api/users//profile"Explanation of the request
| Part | Why it matters |
|---|---|
// between users and profile | Produces an *empty* value for the :userId dynamic segment. Fastify matches the route, Express does not, so the Express middleware stack is never entered. |
| No authentication headers | Because the middleware that would reject the request is bypassed, the request succeeds without a token or cookie. |
If the application uses a static parent mount (e.g., fastify.use('/api/users', router) without a dynamic segment), the bypass does not occur. The vulnerability is limited to dynamic‑parameter mounts.
3. Post‑exploitation
| Impact | How it is achieved |
|---|---|
| Confidentiality breach | Access to user‑specific data (/profile, /settings, etc.) without a valid session token. |
| Privilege escalation | If the Express router implements role‑based checks after authentication (e.g., if (req.user.isAdmin) …), the attacker can reach admin‑only endpoints by supplying an empty parameter that maps to a privileged Fastify handler. |
| Data manipulation | POST/PUT/PATCH endpoints behind the same router can be invoked to modify resources (e.g., change email, password) without authentication. |
| Further lateral movement | Once inside, the attacker may retrieve internal API keys, configuration files, or use the compromised account to pivot to other services that trust the Fastify application. |
Because the vulnerability does not provide remote code execution, the impact stops at confidentiality and integrity (as reflected by the CVSS vector C:H/I:H/A:N).
🌍 Real‑World Impact
| CIA Triad | CVSS Vector Interpretation |
|---|---|
| Confidentiality (C:H) | An unauthenticated attacker can read sensitive data that should be protected by Express‑level authentication (e.g., personal profiles, financial records). |
| Integrity (I:H) | The attacker can modify or delete resources that are normally protected, leading to data tampering. |
| Availability (A:N) | No denial‑of‑service effect is directly caused by the flaw; the service remains available. |
Practical consequences
- SaaS platforms that expose user‑specific APIs via Fastify + Express may leak personal data.
- Internal admin panels built on this stack could be accessed without credentials, allowing configuration changes.
- Compliance regimes (PCI‑DSS, GDPR) could be violated because authentication controls are effectively bypassed.
Given the network‑reachable, low‑complexity, unauthenticated nature of the exploit (AV:N/AC:L/PR:N/UI:N), an attacker can weaponise this vulnerability at scale with automated scanners.
🛡️ Remediation & Mitigation
1. Patch
| Action | Details |
|---|---|
| Upgrade | Move to @fastify/express ≥ 4.0.14. The fix normalises both direct mount paths and paths added later inside an Express router, rejecting empty dynamic parameters before routing to Express. |
| Version range | All versions < 4.0.14 are vulnerable. The latest stable release (as of the CVE publication date) is the recommended target. |
| Test | After upgrade, run integration tests that include requests with empty segments (//) and verify that the Express middleware is still invoked (expect 401/403). |
2. Immediate Work‑arounds (if patch cannot be applied)
| Technique | Implementation |
|---|---|
| Fastify pre‑handler hook | Enforce authentication *after* Fastify routing, before any Express router is invoked. Example: |
fastify.addHook('preHandler', async (request, reply) => {
// Simple token check – runs for every matched Fastify route
if (!request.headers.authorization) {
reply.code(401).send({ error: 'Missing auth' });
}
});| Static parent mount | Mount the Express router on a static path (no : parameters) and perform any parameter validation inside Fastify handlers. Example: fastify.use('/api/users', router); |
|---|---|
| Schema validation for params | Define a Fastify schema that rejects empty strings for the dynamic segment. |
fastify.route({
method: 'GET',
url: '/api/users/:userId/profile',
schema: {
params: {
type: 'object',
properties: {
userId: { type: 'string', minLength: 1 }
},
required: ['userId']
}
},
handler: …
});| Express‑side guard | Add a catch‑all middleware at the top of every Express router that verifies the captured param is non‑empty. |
router.use((req, res, next) => {
if (req.params && Object.values(req.params).some(v => v === '')) {
return res.status(400).send('Invalid route parameter');
}
next();
});3. Detection
| Indicator | Log pattern / SIEM rule |
|---|---|
| Fastify route hit with empty param | GET /api/users//profile → status 200 (or any non‑error) where a 401/403 is expected. |
| Express middleware not executed | Absence of log entries that the authentication middleware normally writes (e.g., Auth check passed for user …). Correlate with the same request URL containing //. |
| Unexpected token usage | Requests that contain an Authorization header and an empty dynamic segment – may indicate probing. |
| WAF rule (ModSecurity example) |
SecRule REQUEST_URI "@rx \/[^\/]+\/\/" \
"id:1000010,phase:2,deny,log,msg:'Fastify‑Express empty‑param bypass attempt',tag:'application-multi',tag:'fastify',severity:2"⚠️ Urgency
//) is sufficient; no prior authentication or user interaction is required. @fastify/[email protected] (or later) immediately on any production system that mounts Express routers under Fastify routes containing dynamic parameters. Apply the work‑arounds above as interim controls if a rolling upgrade is not feasible.Bottom line: The mismatch between Fastify’s permissive empty‑segment matching and Express’s stricter semantics creates an authentication bypass that can be triggered with a single extra slash. Because the bypass is unauthenticated, network‑accessible, and leads to full read/write of protected resources, remediation must be treated as a top‑priority emergency fix.
[🤖 CVE Professor AI Security Engine]
FOFA Query