Skip to content

Commit a43dec1

Browse files
author
songbingkun
committed
fix(feishu): disable ambient proxy inheritance for websocket by default
1 parent ddb7a8d commit a43dec1

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
@@ -358,7 +358,20 @@ describe("createFeishuWSClient proxy handling", () => {
358358
expect(options.agent).toBeUndefined();
359359
});
360360

361-
it("creates a ws proxy agent when lowercase https_proxy is set", async () => {
361+
it("does not inherit ambient proxy env by default", async () => {
362+
process.env.https_proxy = "http://lower-https:8001";
363+
process.env.HTTPS_PROXY = "http://upper-https:8002";
364+
process.env.HTTP_PROXY = "http://upper-http:8999";
365+
366+
await createFeishuWSClient(baseAccount);
367+
368+
expect(proxyAgentCtorMock).not.toHaveBeenCalled();
369+
const options = firstWsClientOptions();
370+
expect(options.agent).toBeUndefined();
371+
});
372+
373+
it("creates a ws proxy agent when explicitly enabled and lowercase https_proxy is set", async () => {
374+
process.env.OPENCLAW_FEISHU_WS_USE_PROXY = "1";
362375
process.env.https_proxy = "http://lower-https:8001";
363376

364377
await createFeishuWSClient(baseAccount);
@@ -368,7 +381,8 @@ describe("createFeishuWSClient proxy handling", () => {
368381
expect(options.agent).toEqual({ proxied: true });
369382
});
370383

371-
it("creates a ws proxy agent when uppercase HTTPS_PROXY is set", async () => {
384+
it("creates a ws proxy agent when explicitly enabled and uppercase HTTPS_PROXY is set", async () => {
385+
process.env.OPENCLAW_FEISHU_WS_USE_PROXY = "1";
372386
process.env.HTTPS_PROXY = "http://upper-https:8002";
373387

374388
await createFeishuWSClient(baseAccount);
@@ -378,7 +392,8 @@ describe("createFeishuWSClient proxy handling", () => {
378392
expect(options.agent).toEqual({ proxied: true });
379393
});
380394

381-
it("falls back to HTTP_PROXY for ws proxy agent creation", async () => {
395+
it("falls back to HTTP_PROXY when explicitly enabled", async () => {
396+
process.env.OPENCLAW_FEISHU_WS_USE_PROXY = "1";
382397
process.env.HTTP_PROXY = "http://upper-http:8999";
383398

384399
await createFeishuWSClient(baseAccount);

‎extensions/feishu/src/client.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,18 @@ let feishuClientSdk: FeishuClientSdk = defaultFeishuClientSdk;
7373
export const FEISHU_HTTP_TIMEOUT_MS = 30_000;
7474
export const FEISHU_HTTP_TIMEOUT_MAX_MS = 300_000;
7575
export const FEISHU_HTTP_TIMEOUT_ENV_VAR = "OPENCLAW_FEISHU_HTTP_TIMEOUT_MS";
76+
export const FEISHU_WS_USE_PROXY_ENV_VAR = "OPENCLAW_FEISHU_WS_USE_PROXY";
7677

7778
type FeishuHttpInstanceLike = Pick<
7879
typeof feishuClientSdk.defaultHttpInstance,
7980
"request" | "get" | "post" | "put" | "patch" | "delete" | "head" | "options"
8081
>;
8182

8283
async function getWsProxyAgent() {
83-
return resolveAmbientNodeProxyAgent<Agent>();
84+
if (process.env[FEISHU_WS_USE_PROXY_ENV_VAR] === "1") {
85+
return resolveAmbientNodeProxyAgent<Agent>();
86+
}
87+
return undefined;
8488
}
8589

8690
// Multi-account client cache

0 commit comments

Comments
 (0)