From a946e5db228ac2117c0eda8daeecde20dcd74030 Mon Sep 17 00:00:00 2001 From: OpenClaw AI Date: Sun, 15 Mar 2026 18:21:31 +0000 Subject: [PATCH] fix(http): redact sensitive request config in error logs --- src/http-helpers/index.ts | 14 +++++++++++++- tests/http-helpers/index.test.ts | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/http-helpers/index.ts b/src/http-helpers/index.ts index dede11d..a7445c1 100644 --- a/src/http-helpers/index.ts +++ b/src/http-helpers/index.ts @@ -133,6 +133,18 @@ export const put = async (endpoint: string, options?: RequestOptions): Promise { + if (!config || typeof config !== "object") { + return undefined; + } + const maybe = config as Record; + return { + method: maybe.method, + url: maybe.url, + timeout: maybe.timeout, + }; +}; + const errorHandling = (err: unknown) => { if (axios.isAxiosError(err)) { if (err.response) { @@ -142,7 +154,7 @@ const errorHandling = (err: unknown) => { status: err.response?.status, statusText: err.response?.statusText, data: err.response?.data, - config: err.response?.config, + config: sanitizeAxiosResponseConfig(err.response?.config), }), ); if (err.response?.data) { diff --git a/tests/http-helpers/index.test.ts b/tests/http-helpers/index.test.ts index 6cb943c..04899f5 100644 --- a/tests/http-helpers/index.test.ts +++ b/tests/http-helpers/index.test.ts @@ -1,6 +1,7 @@ import { parseDropNotificationParams, parseOrdersScoringParams, + sanitizeAxiosResponseConfig, } from "../../src/http-helpers/index.ts"; import type { DropNotificationParams, OrdersScoringParams } from "../../src/types.ts"; @@ -27,4 +28,21 @@ describe("utilities", () => { expect(params).deep.equal({ ids: "0,1,2" }); }); }); + + describe("sanitizeAxiosResponseConfig", () => { + it("removes sensitive headers and auth details", () => { + const sanitized = sanitizeAxiosResponseConfig({ + method: "post", + url: "https://clob.polymarket.com/order", + timeout: 5000, + headers: { Authorization: "Bearer secret" }, + auth: { username: "u", password: "p" }, + }); + expect(sanitized).deep.equal({ + method: "post", + url: "https://clob.polymarket.com/order", + timeout: 5000, + }); + }); + }); });