security(tunnels,proxy): dual-mode isolated proxy origin, direct SSH dialing, HTTPS upstream, SOCKS5 & TTL tunnels

This commit is contained in:
tyuXX 2026-11-27 22:48:53 +00:00
parent 838e69ba4e
commit ca67c85fbf
7 changed files with 1243 additions and 135 deletions

View file

@ -97,6 +97,7 @@ describe('Phase 3: TunnelManager, Authenticated /proxy HTTP+WS & Local/Remote TC
dataDir,
port: 0,
host: '127.0.0.1',
proxyPort: 0,
publicDir: path.resolve('dist/public'),
watchConfig: false,
});
@ -210,6 +211,46 @@ describe('Phase 3: TunnelManager, Authenticated /proxy HTTP+WS & Local/Remote TC
const unauthProxy = await fetch(`${baseUrl}/proxy/web-ui/hello`);
expect(unauthProxy.status).toBe(401);
// Same-origin /proxy is blocked with 403 by default; test isolated proxyPort ticket flow first!
const blockedSameOrigin = await api('/proxy/web-ui/hello');
expect(blockedSameOrigin.status).toBe(403);
expect(blockedSameOrigin.data.error).toBe('PROXY_ORIGIN_ISOLATION_REQUIRED');
const ticketRes = await api('/api/tunnels/app1/web-ui/proxy-ticket', {
method: 'POST',
body: {},
});
expect(ticketRes.status).toBe(200);
expect(ticketRes.data.mode).toBe('port');
const launchUrl = String(ticketRes.data.launchUrl);
const proxyBaseUrl = `http://127.0.0.1:${server.proxyPort}`;
// Redeem single-use ticket on isolated proxy origin to receive scoped gcoord_proxy_sid cookie
const proxyJar = new CookieJar();
const ticketHit = await fetch(launchUrl, { redirect: 'manual' });
expect(ticketHit.status).toBe(302);
proxyJar.updateFrom(ticketHit);
expect(proxyJar.header()).toContain('gcoord_proxy_sid=');
const isoHello = await fetch(`${proxyBaseUrl}/proxy/web-ui/hello`, {
headers: { Cookie: proxyJar.header() },
});
expect(isoHello.status).toBe(200);
const isoHelloData = (await isoHello.json()) as { ok: boolean };
expect(isoHelloData.ok).toBe(true);
expect(upstream.getLastCookie() ?? '').not.toContain('gcoord_sid');
expect(upstream.getLastCookie() ?? '').not.toContain('gcoord_proxy_sid');
// Also enable allowSameOriginProxy explicitly to test same-origin backwards compatibility
expect(
(
await api('/api/auth/security-policy', {
method: 'PUT',
body: { allowSameOriginProxy: true },
})
).status,
).toBe(200);
// Authenticated GET & POST JSON stream through proxy without exposing hub session cookies
const authedHello = await api('/proxy/web-ui/hello');
expect(authedHello.status).toBe(200);
@ -304,7 +345,35 @@ describe('Phase 3: TunnelManager, Authenticated /proxy HTTP+WS & Local/Remote TC
expect(localHttp.status).toBe(200);
expect(((await localHttp.json()) as { ok: boolean }).ok).toBe(true);
// 3. Remote TCP (R) tunnel via forwardIn
// 3. Remote TCP (R) tunnel targets 127.0.0.1 -> blocked by Zero-Trust egress guard unless allowlisted
const blockedRemoteTcp = await api('/api/tunnels', {
method: 'POST',
body: {
serverId: 'app1',
tunnel: {
id: 'tcp-remote',
name: 'Remote TCP Reverse',
mode: 'remote-tcp',
bindHost: '127.0.0.1',
targetHost: '127.0.0.1',
targetPort: upstream.port,
autoStart: false,
},
start: true,
},
});
expect(blockedRemoteTcp.data.startError).toBeTruthy();
// Allow 127.0.0.1/32 in egressAllowedCidrs -> Remote TCP (R) starts and forwards cleanly
expect(
(
await api('/api/auth/security-policy', {
method: 'PUT',
body: { egressAllowedCidrs: ['127.0.0.1/32'] },
})
).status,
).toBe(200);
const remoteTcpRes = await api('/api/tunnels', {
method: 'POST',
body: {