feat(PortProxy): Add feature to preserve original client IP through chained proxies
This commit is contained in:
parent
8cb8fa1a52
commit
c77b31b72c
@ -1,5 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
## 2025-02-21 - 3.6.0 - feat(PortProxy)
|
||||
Add feature to preserve original client IP through chained proxies
|
||||
|
||||
- Added support to bind local address in PortProxy to preserve original client IP.
|
||||
- Implemented test for chained proxies to ensure client IP is preserved.
|
||||
|
||||
## 2025-02-21 - 3.5.0 - feat(PortProxy)
|
||||
Enhance PortProxy to support domain-specific target IPs
|
||||
|
||||
|
@ -175,6 +175,37 @@ tap.test('should stop port proxy', async () => {
|
||||
});
|
||||
|
||||
// Cleanup
|
||||
tap.test('should preserve client IP through chained proxies', async () => {
|
||||
// Create two proxies in chain
|
||||
const firstProxy = new PortProxy({
|
||||
fromPort: PROXY_PORT + 4,
|
||||
toPort: PROXY_PORT + 5, // Point to second proxy
|
||||
toHost: 'localhost',
|
||||
domains: [],
|
||||
sniEnabled: false,
|
||||
defaultAllowedIPs: ['127.0.0.1']
|
||||
});
|
||||
|
||||
const secondProxy = new PortProxy({
|
||||
fromPort: PROXY_PORT + 5,
|
||||
toPort: TEST_SERVER_PORT,
|
||||
toHost: 'localhost',
|
||||
domains: [],
|
||||
sniEnabled: false,
|
||||
defaultAllowedIPs: ['127.0.0.1']
|
||||
});
|
||||
|
||||
await secondProxy.start();
|
||||
await firstProxy.start();
|
||||
|
||||
// Connect through the chain
|
||||
const response = await createTestClient(PROXY_PORT + 4, TEST_DATA);
|
||||
expect(response).toEqual(`Echo: ${TEST_DATA}`);
|
||||
|
||||
await firstProxy.stop();
|
||||
await secondProxy.stop();
|
||||
});
|
||||
|
||||
tap.test('cleanup port proxy test environment', async () => {
|
||||
await new Promise<void>((resolve) => testServer.close(() => resolve()));
|
||||
});
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartproxy',
|
||||
version: '3.5.0',
|
||||
version: '3.6.0',
|
||||
description: 'a proxy for handling high workloads of proxying'
|
||||
}
|
||||
|
@ -123,9 +123,11 @@ export class PortProxy {
|
||||
const domainConfig = serverName ? findMatchingDomain(serverName) : undefined;
|
||||
const targetHost = domainConfig?.targetIP || this.settings.toHost!;
|
||||
|
||||
// Create connection with IP binding to preserve original client IP
|
||||
const to = plugins.net.createConnection({
|
||||
host: targetHost,
|
||||
port: this.settings.toPort,
|
||||
localAddress: remoteIP.replace('::ffff:', ''), // Remove IPv6 mapping if present
|
||||
});
|
||||
console.log(`Connection established: ${remoteIP} -> ${targetHost}:${this.settings.toPort}${serverName ? ` (SNI: ${serverName})` : ''}`);
|
||||
from.setTimeout(120000);
|
||||
|
Loading…
x
Reference in New Issue
Block a user