fix: patch redirect header handling with loopback regression

This commit is contained in:
cesnimda
2026-11-17 20:34:27 +01:00
parent a1149f0d6c
commit d60a333c15
3 changed files with 49 additions and 3 deletions
+3 -3
View File
@@ -7736,9 +7736,9 @@
"license": "ISC"
},
"node_modules/follow-redirects": {
"version": "1.16.1",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.1.tgz",
"integrity": "sha512-FNvFGzoMLWmE6Yj9spb/zjd7yiNCHiAW9/Tg9CXrQ8wuu32HtlJOwWO11OJafl5FfY3DxTdQ0vj42zU1kvv5jg==",
"version": "1.16.3",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.3.tgz",
"integrity": "sha512-toOSoqN6d51Wjf1aOFJYcoVv1aND9rj/CwjLU0Vz40oDuSpWDayCeKe4JpL5NL0WdFvoOOCI3BRo69HahjbR1A==",
"funding": [
{
"type": "individual",
+1
View File
@@ -38,6 +38,7 @@
"lint:fix": "eslint . --fix",
"typecheck": "tsc --noEmit --incremental false",
"test": "jest",
"test:redirect-security": "node --test test/follow-redirects-security.test.mjs",
"test:pdf-admission": "playwright test --config=playwright.pdf.config.ts",
"test:rate-limits": "playwright test --config=playwright.rate-limits.config.ts",
"test:e2e": "node ./scripts/run-e2e.mjs"
@@ -0,0 +1,45 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import http from 'node:http';
import { once } from 'node:events';
import vm from 'node:vm';
import followRedirects from 'follow-redirects';
const redirects = followRedirects.http;
for (const crossRealm of [false, true]) {
test(`cross-origin redirect strips synthetic custom credentials (${crossRealm ? 'cross' : 'same'} realm)`, async () => {
const sensitiveHeaders = crossRealm ? vm.runInNewContext("['X-API-Key']") : ['X-API-Key'];
assert.equal(Array.isArray(sensitiveHeaders), true);
assert.equal(sensitiveHeaders instanceof Array, !crossRealm);
const target = http.createServer((request, response) => {
response.setHeader('Content-Type', 'application/json');
response.end(JSON.stringify(request.headers));
});
const source = http.createServer((_request, response) => {
response.writeHead(302, { Location: `http://127.0.0.1:${target.address().port}/target` });
response.end();
});
try {
target.listen(0, '127.0.0.1'); await once(target, 'listening');
source.listen(0, '127.0.0.1'); await once(source, 'listening');
const received = await new Promise((resolve, reject) => {
const request = redirects.get({
hostname: '127.0.0.1', port: source.address().port, path: '/', sensitiveHeaders, maxRedirects: 3,
headers: { 'X-API-Key': 'synthetic-only-key', 'X-Harmless': 'retained', Authorization: 'synthetic-only-auth', Cookie: 'synthetic=only' },
}, response => {
let body = '';
response.setEncoding('utf8'); response.on('data', chunk => { body += chunk; });
response.on('error', reject); response.on('end', () => { try { resolve(JSON.parse(body)); } catch (error) { reject(error); } });
});
request.setTimeout(3000, () => request.destroy(new Error('Loopback redirect timed out')));
request.on('error', reject);
});
assert.equal(received['x-api-key'], undefined);
assert.equal(received.authorization, undefined);
assert.equal(received.cookie, undefined);
assert.equal(received['x-harmless'], 'retained');
} finally {
await Promise.all([source, target].map(server => new Promise(resolve => server.close(resolve))));
}
});
}