Skip to content

Commit 202ea4b

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 ae9474b commit 202ea4b

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
@@ -504,7 +504,20 @@ describe("createFeishuWSClient proxy handling", () => {
504504
expect(options.agent).toBeUndefined();
505505
});
506506

507-
it("creates a ws proxy agent when lowercase https_proxy is set", async () => {
507+
it("does not inherit ambient proxy env by default", async () => {
508+
process.env.https_proxy = "http://lower-https:8001";
509+
process.env.HTTPS_PROXY = "http://upper-https:8002";
510+
process.env.HTTP_PROXY = "http://upper-http:8999";
511+
512+
await createFeishuWSClient(baseAccount);
513+
514+
expect(proxyAgentCtorMock).not.toHaveBeenCalled();
515+
const options = firstWsClientOptions();
516+
expect(options.agent).toBeUndefined();
517+
});
518+
519+
it("creates a ws proxy agent when explicitly enabled and lowercase https_proxy is set", async () => {
520+
process.env.OPENCLAW_FEISHU_WS_USE_PROXY = "1";
508521
process.env.https_proxy = "http://lower-https:8001";
509522

510523
await createFeishuWSClient(baseAccount);
@@ -514,7 +527,8 @@ describe("createFeishuWSClient proxy handling", () => {
514527
expect(options.agent).toEqual({ proxied: true });
515528
});
516529

517-
it("creates a ws proxy agent when uppercase HTTPS_PROXY is set", async () => {
530+
it("creates a ws proxy agent when explicitly enabled and uppercase HTTPS_PROXY is set", async () => {
531+
process.env.OPENCLAW_FEISHU_WS_USE_PROXY = "1";
518532
process.env.HTTPS_PROXY = "http://upper-https:8002";
519533

520534
await createFeishuWSClient(baseAccount);
@@ -524,7 +538,8 @@ describe("createFeishuWSClient proxy handling", () => {
524538
expect(options.agent).toEqual({ proxied: true });
525539
});
526540

527-
it("falls back to HTTP_PROXY for ws proxy agent creation", async () => {
541+
it("falls back to HTTP_PROXY when explicitly enabled", async () => {
542+
process.env.OPENCLAW_FEISHU_WS_USE_PROXY = "1";
528543
process.env.HTTP_PROXY = "http://upper-http:8999";
529544

530545
await createFeishuWSClient(baseAccount);

‎extensions/feishu/src/client.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ function setRequestUserAgent(req: unknown) {
9191
inst.interceptors?.request?.use(setRequestUserAgent);
9292
}
9393

94+
export const FEISHU_WS_USE_PROXY_ENV_VAR = "OPENCLAW_FEISHU_WS_USE_PROXY";
9495
export { FEISHU_HTTP_TIMEOUT_ENV_VAR, FEISHU_HTTP_TIMEOUT_MAX_MS, FEISHU_HTTP_TIMEOUT_MS };
9596

9697
type FeishuHttpInstanceLike = Pick<
@@ -99,7 +100,10 @@ type FeishuHttpInstanceLike = Pick<
99100
>;
100101

101102
async function getWsProxyAgent() {
102-
return resolveAmbientNodeProxyAgent<Agent>();
103+
if (process.env[FEISHU_WS_USE_PROXY_ENV_VAR] === "1") {
104+
return resolveAmbientNodeProxyAgent<Agent>();
105+
}
106+
return undefined;
103107
}
104108

105109
// Multi-account client cache

0 commit comments

Comments
 (0)