fix(auth): reject spoofed local host headers

This commit is contained in:
Bohdan Triapitsyn
2026-07-12 00:46:41 +03:00
parent 4f65e01a63
commit a8953ad6f9
2 changed files with 14 additions and 13 deletions
@@ -700,4 +700,14 @@ describe('client auth routes', () => {
expect(dependencies.uiAuthController.handlePasskeyStatus).toHaveBeenCalledTimes(1);
});
it('does not trust a private Host header from a public socket peer', () => {
const tunnelAuthController = createTunnelAuth();
tunnelAuthController.setActiveTunnel({ tunnelId: 'tunnel-1', publicUrl: 'https://tunnel.example.com' });
expect(tunnelAuthController.classifyRequestScope({
headers: { host: '192.168.1.5:57123' },
socket: { remoteAddress: '203.0.113.10' },
})).toBe('unknown-public');
});
});
@@ -172,19 +172,10 @@ const isLocalHost = (host, req) => {
return false;
}
if (host === 'localhost' || host === '127.0.0.1' || host === '::1' || host === '[::1]') {
return true;
}
if (isPrivateOrLoopbackIp(host)) {
return true;
}
if (host === 'host.docker.internal') {
return isPrivateOrLoopbackIp(getSocketRemoteIp(req));
}
return false;
const isLocalHostname = host === 'localhost'
|| host === 'host.docker.internal'
|| isPrivateOrLoopbackIp(host);
return isLocalHostname && isPrivateOrLoopbackIp(getSocketRemoteIp(req));
};
const getClientIp = (req) => {