fix(http): merge security headers into app.fetch CORS preflight responses

Add a Node-vs-app.fetch parity suite that drives GET/POST/404/CORS-preflight/SSE
through both the real Node server and app.fetch and asserts identical status,
headers, and body. It caught a real divergence: buildFetch's preflight branch
returned only the CORS-specific headers, skipping the security headers
(x-content-type-options, x-frame-options, referrer-policy, x-dns-prefetch-control)
that the Node adapter's writeHead patch applies to every response including the
204 preflight. Fix buildFetch to merge `injected` into the preflight response the
same way, so both paths agree.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-07-09 14:33:31 -05:00
1 parent 08cb8554e6
commit b75f127b2c
2 files changed
+93 -1

No files matched your search

+7 -1
View File
@@ -146,7 +146,13 @@ export function buildFetch(routes: RouteDef[], opts: HttpOptions | undefined) {
ip: headers['x-forwarded-for'] ?? '',
});
if ('preflight' in result) return new Response(null, { status: 204, headers: result.preflight });
// Mirrors the Node adapter, where `result.preflight` is written through the writeHead patch and
// so picks up the same authoritative security headers `injected` carries (Node's writeHead patch
// merges every response — including the 204 preflight — with `injected`; this adapter must too).
if ('preflight' in result) {
return new Response(null, { status: 204, headers: mergeInjectedHeaders(result.preflight, injected) });
}
return outcomeToResponse(result);
};
}