fix(auth): reject spoofed local host headers
This commit is contained in:
@@ -700,4 +700,14 @@ describe('client auth routes', () => {
|
|||||||
|
|
||||||
expect(dependencies.uiAuthController.handlePasskeyStatus).toHaveBeenCalledTimes(1);
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (host === 'localhost' || host === '127.0.0.1' || host === '::1' || host === '[::1]') {
|
const isLocalHostname = host === 'localhost'
|
||||||
return true;
|
|| host === 'host.docker.internal'
|
||||||
}
|
|| isPrivateOrLoopbackIp(host);
|
||||||
|
return isLocalHostname && isPrivateOrLoopbackIp(getSocketRemoteIp(req));
|
||||||
if (isPrivateOrLoopbackIp(host)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (host === 'host.docker.internal') {
|
|
||||||
return isPrivateOrLoopbackIp(getSocketRemoteIp(req));
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getClientIp = (req) => {
|
const getClientIp = (req) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user