fix: allow external host origin behind HTTP proxy

Accept browser https origins when TLS terminates before an HTTP proxy hop
Honor forwarded external host while rejecting mismatched origins
Add tests for proxy and host matching behavior
This commit is contained in:
Bohdan Triapitsyn
2026-09-01 14:38:44 +03:00
parent bec7a82568
commit 40e4b6f857
2 changed files with 48 additions and 5 deletions
@@ -46,4 +46,38 @@ describe('request security runtime', () => {
socket: {},
})).resolves.toBe(false);
});
test('allows the external host when TLS terminates before an HTTP proxy hop', async () => {
const runtime = createRuntime();
await expect(runtime.isRequestOriginAllowed({
headers: {
origin: 'https://devchamber.example.com',
host: 'devchamber.example.com',
'x-forwarded-proto': 'http',
},
socket: {},
})).resolves.toBe(true);
});
test('uses the forwarded external host without trusting a different origin', async () => {
const runtime = createRuntime();
const request = {
headers: {
host: '127.0.0.1:3000',
'x-forwarded-host': 'devchamber.example.com',
'x-forwarded-proto': 'http',
},
socket: {},
};
await expect(runtime.isRequestOriginAllowed({
...request,
headers: { ...request.headers, origin: 'https://devchamber.example.com' },
})).resolves.toBe(true);
await expect(runtime.isRequestOriginAllowed({
...request,
headers: { ...request.headers, origin: 'https://evil.example.com' },
})).resolves.toBe(false);
});
});