Skip to content

Commit 077824c

Browse files
committed
fix(feishu): disable ambient proxy inheritance for WebSocket by default
Feishu WebSocket currently inherits ambient proxy environment variables (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY) via resolveAmbientNodeProxyAgent(). When a proxy is configured for unrelated outbound traffic (e.g. Gemini API access) and the proxy endpoint is unavailable or misconfigured for Feishu's long-poll WebSocket, the connection silently fails with only: [ws] ws connect failed This makes Feishu inbound fragile and hard to debug, since direct connection with the same app credentials succeeds. Fix: make getWsProxyAgent() return undefined by default. Ambient proxy inheritance is only enabled when OPENCLAW_FEISHU_WS_USE_PROXY=1 is set. Updates tests to cover: - default behavior: no proxy agent created even when proxy env is set - explicit opt-in: proxy agent created when OPENCLAW_FEISHU_WS_USE_PROXY=1 Fixes #65799
1 parent 14a113f commit 077824c

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

‎extensions/feishu/src/client.test.ts‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,20 @@ describe("createFeishuWSClient proxy handling", () => {
401401
expect(options.agent).toBeUndefined();
402402
});
403403

404-
it("creates a ws proxy agent when lowercase https_proxy is set", async () => {
404+
it("does not inherit ambient proxy env by default", async () => {
405+
process.env.https_proxy = "http://lower-https:8001";
406+
process.env.HTTPS_PROXY = "http://upper-https:8002";
407+
process.env.HTTP_PROXY = "http://upper-http:8999";
408+
409+
await createFeishuWSClient(baseAccount);
410+
411+
expect(proxyAgentCtorMock).not.toHaveBeenCalled();
412+
const options = firstWsClientOptions();
413+
expect(options.agent).toBeUndefined();
414+
});
415+
416+
it("creates a ws proxy agent when explicitly enabled and lowercase https_proxy is set", async () => {
417+
process.env.OPENCLAW_FEISHU_WS_USE_PROXY = "1";
405418
process.env.https_proxy = "http://lower-https:8001";
406419

407420
await createFeishuWSClient(baseAccount);
@@ -411,7 +424,8 @@ describe("createFeishuWSClient proxy handling", () => {
411424
expect(options.agent).toEqual({ proxied: true });
412425
});
413426

414-
it("creates a ws proxy agent when uppercase HTTPS_PROXY is set", async () => {
427+
it("creates a ws proxy agent when explicitly enabled and uppercase HTTPS_PROXY is set", async () => {
428+
process.env.OPENCLAW_FEISHU_WS_USE_PROXY = "1";
415429
process.env.HTTPS_PROXY = "http://upper-https:8002";
416430

417431
await createFeishuWSClient(baseAccount);
@@ -421,7 +435,8 @@ describe("createFeishuWSClient proxy handling", () => {
421435
expect(options.agent).toEqual({ proxied: true });
422436
});
423437

424-
it("falls back to HTTP_PROXY for ws proxy agent creation", async () => {
438+
it("falls back to HTTP_PROXY when explicitly enabled", async () => {
439+
process.env.OPENCLAW_FEISHU_WS_USE_PROXY = "1";
425440
process.env.HTTP_PROXY = "http://upper-http:8999";
426441

427442
await createFeishuWSClient(baseAccount);

‎extensions/feishu/src/client.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ let feishuClientSdk: FeishuClientSdk = defaultFeishuClientSdk;
8383
}
8484
}
8585

86+
export const FEISHU_WS_USE_PROXY_ENV_VAR = "OPENCLAW_FEISHU_WS_USE_PROXY";
8687
export { FEISHU_HTTP_TIMEOUT_ENV_VAR, FEISHU_HTTP_TIMEOUT_MAX_MS, FEISHU_HTTP_TIMEOUT_MS };
8788

8889
type FeishuHttpInstanceLike = Pick<
@@ -91,7 +92,10 @@ type FeishuHttpInstanceLike = Pick<
9192
>;
9293

9394
async function getWsProxyAgent() {
94-
return resolveAmbientNodeProxyAgent<Agent>();
95+
if (process.env[FEISHU_WS_USE_PROXY_ENV_VAR] === "1") {
96+
return resolveAmbientNodeProxyAgent<Agent>();
97+
}
98+
return undefined;
9599
}
96100

97101
// Multi-account client cache

0 commit comments

Comments
 (0)