Skip to content

Commit aaa52a7

Browse files
fix(clawsweeper): address review for automerge-openclaw-openclaw-77010 (1)
1 parent 878f5a5 commit aaa52a7

5 files changed

Lines changed: 117 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Docs: https://docs.openclaw.ai
166166
- CLI/plugins: explain when a missing plugin command alias belongs to a bundled plugin that is disabled by default, including the `openclaw plugins enable <plugin>` repair command. (#76835)
167167
- Gateway/Bonjour: auto-start LAN multicast discovery only on macOS hosts while preserving explicit `openclaw plugins enable bonjour` startup elsewhere, so Linux servers and containers that do not need LAN discovery avoid default mDNS probing and watchdog churn. Refs #74209.
168168
- Gateway/macOS: stop `doctor` and LaunchAgent recovery from running `launchctl kickstart -k` after a fresh bootstrap, avoiding an immediate SIGTERM of the just-started gateway while still nudging already-loaded launchd jobs. Fixes #76261. Thanks @solosage1.
169-
- Proxy/debugging: disable debug proxy CONNECT upstream forwarding while managed proxy mode is active unless `OPENCLAW_DEBUG_PROXY_ALLOW_DIRECT_CONNECT_WITH_MANAGED_PROXY=1` is explicitly set for approved local diagnostics. Thanks @jesse-merhi and @mjamiv.
169+
- Proxy/debugging: disable debug proxy direct upstream forwarding for proxy requests and CONNECT tunnels while managed proxy mode is active unless `OPENCLAW_DEBUG_PROXY_ALLOW_DIRECT_CONNECT_WITH_MANAGED_PROXY=1` is explicitly set for approved local diagnostics. Thanks @jesse-merhi and @mjamiv.
170170
- Google Meet: route stateful CLI session commands through the gateway-owned runtime so joined realtime sessions survive after the starting CLI process exits. Fixes #76344. Thanks @coltonharris-wq.
171171
- Memory/status: split builtin sqlite-vec store readiness from embedding-provider readiness in `memory status --deep` and `openclaw status`, so local vector-store failures no longer look like provider failures and provider failures no longer hide a healthy local vector store.
172172
- CLI/doctor: trust a ready gateway memory probe when CLI-side active memory backend resolution is unavailable, preventing false "No active memory plugin is registered" warnings for healthy runtime setups. Fixes #76792. Thanks @som-686.

docs/cli/proxy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ semantics.
6868

6969
- `start` defaults to `127.0.0.1` unless `--host` is set.
7070
- `run` starts a local debug proxy and then runs the command after `--`.
71-
- The debug proxy's CONNECT forwarding opens upstream TCP sockets for diagnostics. When OpenClaw managed proxy mode is active, CONNECT forwarding is disabled by default; set `OPENCLAW_DEBUG_PROXY_ALLOW_DIRECT_CONNECT_WITH_MANAGED_PROXY=1` only for approved local diagnostics.
71+
- The debug proxy's direct upstream forwarding opens upstream sockets for diagnostics. When OpenClaw managed proxy mode is active, direct forwarding for proxy requests and CONNECT tunnels is disabled by default; set `OPENCLAW_DEBUG_PROXY_ALLOW_DIRECT_CONNECT_WITH_MANAGED_PROXY=1` only for approved local diagnostics.
7272
- `validate` exits with code 1 when proxy config or destination checks fail.
7373
- Captures are local debugging data; use `openclaw proxy purge` when finished.
7474

docs/security/network-proxy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ proxy:
194194
- The proxy improves coverage for process-local JavaScript HTTP and WebSocket clients, but it is not an OS-level network sandbox.
195195
- Raw `net`, `tls`, and `http2` sockets, native addons, and child processes may bypass Node-level proxy routing unless they inherit and respect proxy environment variables.
196196
- IRC is a raw TCP/TLS channel outside operator-managed forward proxy routing. In deployments that require all egress through that forward proxy, set `channels.irc.enabled=false` unless direct IRC egress is explicitly approved.
197-
- The local debug proxy is diagnostic tooling and its CONNECT upstream forwarding is disabled by default while managed proxy mode is active; enable direct CONNECT forwarding only for approved local diagnostics.
197+
- The local debug proxy is diagnostic tooling and its direct upstream forwarding for proxy requests and CONNECT tunnels is disabled by default while managed proxy mode is active; enable direct forwarding only for approved local diagnostics.
198198
- User local WebUIs and local model servers should be allowlisted in the operator proxy policy when needed; OpenClaw does not expose a general local-network bypass for them.
199199
- Gateway control-plane proxy bypass is intentionally limited to `localhost` and literal loopback IP URLs. Use `ws://127.0.0.1:18789`, `ws://[::1]:18789`, or `ws://localhost:18789` for local direct Gateway control-plane connections; other hostnames route like ordinary hostname-based traffic.
200200
- OpenClaw does not inspect, test, or certify your proxy policy.

src/proxy-capture/proxy-server.managed-proxy.test.ts

Lines changed: 84 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { mkdtemp, rm } from "node:fs/promises";
2-
import { Socket } from "node:net";
2+
import { createServer as createHttpServer } from "node:http";
3+
import { Socket, type AddressInfo } from "node:net";
34
import { tmpdir } from "node:os";
45
import { join } from "node:path";
56
import { afterEach, beforeEach, describe, expect, it } from "vitest";
6-
import { assertDebugProxyDirectConnectAllowed, startDebugProxyServer } from "./proxy-server.js";
7+
import { assertDebugProxyDirectUpstreamAllowed, startDebugProxyServer } from "./proxy-server.js";
78

89
let testRoot: string | undefined;
910

@@ -47,7 +48,60 @@ async function connectThroughProxy(proxyUrl: string): Promise<string> {
4748
return data;
4849
}
4950

50-
describe("debug proxy managed-proxy CONNECT policy", () => {
51+
async function requestThroughProxy(proxyUrl: string, targetUrl: string): Promise<string> {
52+
const proxy = new URL(proxyUrl);
53+
const target = new URL(targetUrl);
54+
const socket = new Socket();
55+
let data = "";
56+
socket.setEncoding("utf8");
57+
socket.on("data", (chunk) => {
58+
data += chunk;
59+
});
60+
await new Promise<void>((resolve, reject) => {
61+
socket.once("error", reject);
62+
socket.connect(Number(proxy.port), proxy.hostname, resolve);
63+
});
64+
socket.write(`GET ${target.href} HTTP/1.1\r\nHost: ${target.host}\r\nConnection: close\r\n\r\n`);
65+
await new Promise<void>((resolve) => socket.once("end", resolve));
66+
socket.destroy();
67+
return data;
68+
}
69+
70+
async function startCanaryOrigin(): Promise<{
71+
requestCount: () => number;
72+
stop: () => Promise<void>;
73+
url: string;
74+
}> {
75+
let requests = 0;
76+
const server = createHttpServer((_req, res) => {
77+
requests += 1;
78+
res.end("ok");
79+
});
80+
await new Promise<void>((resolve, reject) => {
81+
server.once("error", reject);
82+
server.listen(0, "127.0.0.1", () => {
83+
server.off("error", reject);
84+
resolve();
85+
});
86+
});
87+
const address = server.address() as AddressInfo;
88+
return {
89+
requestCount: () => requests,
90+
stop: async () =>
91+
await new Promise<void>((resolve, reject) => {
92+
server.close((error) => {
93+
if (error) {
94+
reject(error);
95+
return;
96+
}
97+
resolve();
98+
});
99+
}),
100+
url: `http://127.0.0.1:${address.port}/metadata`,
101+
};
102+
}
103+
104+
describe("debug proxy managed-proxy direct upstream policy", () => {
51105
const originalProxyActive = process.env["OPENCLAW_PROXY_ACTIVE"];
52106
const originalAllowDirect =
53107
process.env["OPENCLAW_DEBUG_PROXY_ALLOW_DIRECT_CONNECT_WITH_MANAGED_PROXY"];
@@ -73,31 +127,31 @@ describe("debug proxy managed-proxy CONNECT policy", () => {
73127
await cleanupTestDirs();
74128
});
75129

76-
it("allows direct CONNECT upstreams when managed proxy mode is inactive", () => {
77-
expect(() => assertDebugProxyDirectConnectAllowed()).not.toThrow();
130+
it("allows direct upstreams when managed proxy mode is inactive", () => {
131+
expect(() => assertDebugProxyDirectUpstreamAllowed()).not.toThrow();
78132
});
79133

80-
it("rejects direct CONNECT upstreams while managed proxy mode is active", () => {
134+
it("rejects direct upstreams while managed proxy mode is active", () => {
81135
process.env["OPENCLAW_PROXY_ACTIVE"] = "1";
82136

83-
expect(() => assertDebugProxyDirectConnectAllowed()).toThrow(
84-
/Debug proxy CONNECT upstream forwarding is disabled/,
137+
expect(() => assertDebugProxyDirectUpstreamAllowed()).toThrow(
138+
/Debug proxy direct upstream forwarding is disabled/,
85139
);
86140
});
87141

88142
it("uses shared truthy parsing for managed proxy mode", () => {
89143
process.env["OPENCLAW_PROXY_ACTIVE"] = "true";
90144

91-
expect(() => assertDebugProxyDirectConnectAllowed()).toThrow(
92-
/Debug proxy CONNECT upstream forwarding is disabled/,
145+
expect(() => assertDebugProxyDirectUpstreamAllowed()).toThrow(
146+
/Debug proxy direct upstream forwarding is disabled/,
93147
);
94148
});
95149

96-
it("allows direct CONNECT upstreams with explicit diagnostic override", () => {
150+
it("allows direct upstreams with explicit diagnostic override", () => {
97151
process.env["OPENCLAW_PROXY_ACTIVE"] = "1";
98152
process.env["OPENCLAW_DEBUG_PROXY_ALLOW_DIRECT_CONNECT_WITH_MANAGED_PROXY"] = "1";
99153

100-
expect(() => assertDebugProxyDirectConnectAllowed()).not.toThrow();
154+
expect(() => assertDebugProxyDirectUpstreamAllowed()).not.toThrow();
101155
});
102156

103157
it("rejects CONNECT upstreams before opening direct sockets while managed proxy mode is active", async () => {
@@ -108,9 +162,26 @@ describe("debug proxy managed-proxy CONNECT policy", () => {
108162

109163
expect(response).toContain("403 Forbidden");
110164
expect(response).toContain("Connection: close");
111-
expect(response).toContain("Debug proxy CONNECT upstream forwarding is disabled");
165+
expect(response).toContain("Debug proxy direct upstream forwarding is disabled");
166+
} finally {
167+
await server.stop();
168+
}
169+
});
170+
171+
it("rejects absolute-form HTTP proxy requests before opening direct upstreams while managed proxy mode is active", async () => {
172+
process.env["OPENCLAW_PROXY_ACTIVE"] = "1";
173+
const origin = await startCanaryOrigin();
174+
const server = await startDebugProxyServer({ settings: await makeSettings() });
175+
try {
176+
const response = await requestThroughProxy(server.proxyUrl, origin.url);
177+
178+
expect(response).toContain("403 Forbidden");
179+
expect(response).toContain("Connection: close");
180+
expect(response).toContain("Debug proxy direct upstream forwarding is disabled");
181+
expect(origin.requestCount()).toBe(0);
112182
} finally {
113183
await server.stop();
184+
await origin.stop();
114185
}
115186
});
116187
});

src/proxy-capture/proxy-server.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ function allowsDirectConnectWithManagedProxy(env: NodeJS.ProcessEnv = process.en
2424
return isTruthyEnvValue(env[DEBUG_PROXY_DIRECT_CONNECT_OVERRIDE]);
2525
}
2626

27-
export function assertDebugProxyDirectConnectAllowed(env: NodeJS.ProcessEnv = process.env): void {
27+
export function assertDebugProxyDirectUpstreamAllowed(env: NodeJS.ProcessEnv = process.env): void {
2828
if (!isManagedProxyActive(env) || allowsDirectConnectWithManagedProxy(env)) {
2929
return;
3030
}
3131
throw new Error(
32-
"Debug proxy CONNECT upstream forwarding is disabled while managed proxy mode is active. " +
32+
"Debug proxy direct upstream forwarding is disabled while managed proxy mode is active. " +
3333
`Set ${DEBUG_PROXY_DIRECT_CONNECT_OVERRIDE}=1 only for approved local diagnostics.`,
3434
);
3535
}
@@ -99,6 +99,33 @@ export async function startDebugProxyServer(params: {
9999
const server = createServer(async (req: IncomingMessage, res: ServerResponse) => {
100100
const flowId = randomUUID();
101101
const target = normalizeTargetUrl(req);
102+
try {
103+
assertDebugProxyDirectUpstreamAllowed();
104+
} catch (error) {
105+
const message = error instanceof Error ? error.message : String(error);
106+
store.recordEvent({
107+
sessionId: params.settings.sessionId,
108+
ts: Date.now(),
109+
sourceScope: "openclaw",
110+
sourceProcess: params.settings.sourceProcess,
111+
protocol: target.protocol === "https:" ? "https" : "http",
112+
direction: "local",
113+
kind: "error",
114+
flowId,
115+
method: req.method,
116+
host: target.host,
117+
path: `${target.pathname}${target.search}`,
118+
errorText: message,
119+
});
120+
const responseBody = `${message}\n`;
121+
res.writeHead(403, {
122+
Connection: "close",
123+
"Content-Type": "text/plain; charset=utf-8",
124+
"Content-Length": Buffer.byteLength(responseBody),
125+
});
126+
res.end(responseBody);
127+
return;
128+
}
102129
const body = await readBody(req);
103130
store.recordEvent({
104131
sessionId: params.settings.sessionId,
@@ -214,7 +241,7 @@ export async function startDebugProxyServer(params: {
214241
headersJson: JSON.stringify(req.headers),
215242
});
216243
try {
217-
assertDebugProxyDirectConnectAllowed();
244+
assertDebugProxyDirectUpstreamAllowed();
218245
} catch (error) {
219246
const message = error instanceof Error ? error.message : String(error);
220247
store.recordEvent({

0 commit comments

Comments
 (0)