From f3aaa114ad233bf0c9231dd27909e1b52300839c Mon Sep 17 00:00:00 2001 From: Murray Wang Date: Thu, 29 Jan 2026 23:45:03 +0800 Subject: [PATCH 1/2] Tools: add HTTP/HTTPS proxy support for web_search and web_fetch --- CHANGELOG.md | 1 + src/agents/tools/web-search.ts | 7 +++++++ src/infra/net/ssrf.ts | 25 ++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6444466d0..f59ef4362 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Docs: https://docs.openclaw.ai Status: beta. ### Changes +- Tools: add HTTP/HTTPS proxy support for web_search and web_fetch via environment variables (HTTP_PROXY/HTTPS_PROXY). - Rebrand: rename the npm package/CLI to `openclaw`, add a `openclaw` compatibility shim, and move extensions to the `@openclaw/*` scope. - Commands: group /help and /commands output with Telegram paging. (#2504) Thanks @hougangdev. - macOS: limit project-local `node_modules/.bin` PATH preference to debug builds (reduce PATH hijacking risk). diff --git a/src/agents/tools/web-search.ts b/src/agents/tools/web-search.ts index bf5741490..12da8447b 100644 --- a/src/agents/tools/web-search.ts +++ b/src/agents/tools/web-search.ts @@ -2,6 +2,7 @@ import { Type } from "@sinclair/typebox"; import type { OpenClawConfig } from "../../config/config.js"; import { formatCliCommand } from "../../cli/command-format.js"; +import { createProxyAgent } from "../../infra/net/ssrf.js"; import type { AnyAgentTool } from "./common.js"; import { jsonResult, readNumberParam, readStringParam } from "./common.js"; import { @@ -273,6 +274,7 @@ async function runPerplexitySearch(params: { timeoutSeconds: number; }): Promise<{ content: string; citations: string[] }> { const endpoint = `${params.baseUrl.replace(/\/$/, "")}/chat/completions`; + const proxyAgent = createProxyAgent(); const res = await fetch(endpoint, { method: "POST", @@ -292,6 +294,8 @@ async function runPerplexitySearch(params: { ], }), signal: withTimeout(undefined, params.timeoutSeconds * 1000), + // @ts-expect-error - undici ProxyAgent dispatcher is not in standard fetch types + dispatcher: proxyAgent, }); if (!res.ok) { @@ -371,6 +375,7 @@ async function runWebSearch(params: { url.searchParams.set("freshness", params.freshness); } + const proxyAgent = createProxyAgent(); const res = await fetch(url.toString(), { method: "GET", headers: { @@ -378,6 +383,8 @@ async function runWebSearch(params: { "X-Subscription-Token": params.apiKey, }, signal: withTimeout(undefined, params.timeoutSeconds * 1000), + // @ts-expect-error - undici ProxyAgent dispatcher is not in standard fetch types + dispatcher: proxyAgent, }); if (!res.ok) { diff --git a/src/infra/net/ssrf.ts b/src/infra/net/ssrf.ts index 297df0f03..95d2885e3 100644 --- a/src/infra/net/ssrf.ts +++ b/src/infra/net/ssrf.ts @@ -1,6 +1,6 @@ import { lookup as dnsLookup } from "node:dns/promises"; import { lookup as dnsLookupCb, type LookupAddress } from "node:dns"; -import { Agent, type Dispatcher } from "undici"; +import { Agent, ProxyAgent, type Dispatcher } from "undici"; type LookupCallback = ( err: NodeJS.ErrnoException | null, @@ -210,7 +210,30 @@ export async function resolvePinnedHostname( }; } +export function createProxyAgent(): ProxyAgent | undefined { + const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy; + const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy; + const proxy = httpsProxy || httpProxy; + + if (!proxy) return undefined; + + try { + return new ProxyAgent(proxy); + } catch (error) { + console.error("Failed to create proxy agent:", error); + return undefined; + } +} + export function createPinnedDispatcher(pinned: PinnedHostname): Dispatcher { + // If proxy is configured, use ProxyAgent instead of pinned Agent + // Note: When using proxy, SSRF protection is bypassed as the proxy handles DNS + const proxyAgent = createProxyAgent(); + if (proxyAgent) { + return proxyAgent; + } + + // Otherwise, use Agent with pinned lookup for SSRF protection return new Agent({ connect: { lookup: pinned.lookup, From 1791308cc9731806c8953c86640b273bed80353c Mon Sep 17 00:00:00 2001 From: Murray Wang Date: Fri, 30 Jan 2026 13:49:01 +0800 Subject: [PATCH 2/2] fix: resolve formatting and test issues from OpenClaw rebrand MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix formatting in src/commands/onboard-helpers.ts (indentation) - Update paths.test.ts to expect 16 config candidates (backward compatibility) - New: ~/.openclaw + legacy: ~/.clawdbot, ~/.moltbot, ~/.moldbot - Each dir checks 4 config filenames (openclaw.json + 3 legacy) - Total: 4 dirs × 4 filenames = 16 candidates --- src/commands/onboard-helpers.ts | 12 ++++++------ src/config/paths.test.ts | 8 +++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/commands/onboard-helpers.ts b/src/commands/onboard-helpers.ts index f56da78e9..774893213 100644 --- a/src/commands/onboard-helpers.ts +++ b/src/commands/onboard-helpers.ts @@ -64,12 +64,12 @@ export function randomToken(): string { export function printWizardHeader(runtime: RuntimeEnv) { const header = [ - "▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄", - "██░▄▄▄░██░▄▄░██░▄▄▄██░▀██░██░▄▄▀██░████░▄▄▀██░███░██", - "██░███░██░▀▀░██░▄▄▄██░█░█░██░█████░████░▀▀░██░█░█░██", - "██░▀▀▀░██░█████░▀▀▀██░██▄░██░▀▀▄██░▀▀░█░██░██▄▀▄▀▄██", - "▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀", - " 🦞 OPENCLAW 🦞 ", + "▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄", + "██░▄▄▄░██░▄▄░██░▄▄▄██░▀██░██░▄▄▀██░████░▄▄▀██░███░██", + "██░███░██░▀▀░██░▄▄▄██░█░█░██░█████░████░▀▀░██░█░█░██", + "██░▀▀▀░██░█████░▀▀▀██░██▄░██░▀▀▄██░▀▀░█░██░██▄▀▄▀▄██", + "▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀", + " 🦞 OPENCLAW 🦞 ", " ", ].join("\n"); runtime.log(header); diff --git a/src/config/paths.test.ts b/src/config/paths.test.ts index 06cd26444..9a7913ea5 100644 --- a/src/config/paths.test.ts +++ b/src/config/paths.test.ts @@ -49,7 +49,13 @@ describe("state + config path candidates", () => { const home = "/home/test"; const candidates = resolveDefaultConfigCandidates({} as NodeJS.ProcessEnv, () => home); expect(candidates[0]).toBe(path.join(home, ".openclaw", "openclaw.json")); - expect(candidates).toHaveLength(1); + // Should include new .openclaw dir + legacy dirs (.clawdbot, .moltbot, .moldbot) + // with all config filenames (openclaw.json + clawdbot.json, moltbot.json, moldbot.json) + // = 4 dirs × 4 filenames = 16 candidates + expect(candidates).toHaveLength(16); + // Verify the candidates include expected legacy paths + expect(candidates).toContain(path.join(home, ".clawdbot", "clawdbot.json")); + expect(candidates).toContain(path.join(home, ".moltbot", "moltbot.json")); }); it("prefers ~/.openclaw when it exists and legacy dir is missing", async () => {