Skip to content

Commit 7e29c32

Browse files
committed
fix(voice-call): redact gateway URLs in CLI operational errors
ClawSweeper P1: the operational-error formatter interpolated the raw connectionDetails.url, so a configured gateway URL with userinfo or query tokens would print credentials into terminal output. Redact the composed message once with the canonical net-policy redactor (also covers remote-controlled close-reason text), exported through the plugin SDK gateway-runtime subpath (+1 documented surface budget). Regression test covers a credential-bearing URL in both the URL and message fields.
1 parent 4f0247e commit 7e29c32

4 files changed

Lines changed: 61 additions & 26 deletions

File tree

‎extensions/voice-call/src/cli-gateway-call.ts‎

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
callGatewayFromCli,
55
isGatewayClientRequestError,
66
isGatewayTransportError,
7+
redactSensitiveUrlLikeString,
78
} from "openclaw/plugin-sdk/gateway-runtime";
89
import {
910
addTimerTimeoutGraceMs,
@@ -55,31 +56,27 @@ function isGatewayCredentialFailure(err: unknown): err is Error {
5556

5657
function gatewayOperationalError(err: unknown): Error {
5758
const message = formatErrorMessage(err);
58-
if (isGatewayClientRequestError(err)) {
59-
return new Error(
60-
`Gateway responded but voicecall failed: ${message}\nThe running Gateway owns the voice-call runtime; check \`openclaw gateway status\` or restart it.`,
61-
);
62-
}
63-
if (isGatewayCredentialFailure(err)) {
64-
return new Error(
65-
`Gateway requires credentials: ${message}\nConfigure gateway.auth or pair this device with \`openclaw devices approve --latest\`.`,
66-
);
67-
}
68-
if (isGatewayTransportError(err)) {
69-
const url = err.connectionDetails.url;
70-
if (err.kind === "timeout") {
71-
const timeout = err.timeoutMs === undefined ? "the configured timeout" : `${err.timeoutMs}ms`;
72-
return new Error(
73-
`Gateway at ${url} did not answer within ${timeout}: ${message}\nIt may be starting or wedged; check \`openclaw gateway status\`.`,
74-
);
59+
const detail = (() => {
60+
if (isGatewayClientRequestError(err)) {
61+
return `Gateway responded but voicecall failed: ${message}\nThe running Gateway owns the voice-call runtime; check \`openclaw gateway status\` or restart it.`;
7562
}
76-
return new Error(
77-
`Gateway connection at ${url} failed: ${message}\nCheck gateway.auth and \`openclaw gateway status\`, then retry.`,
78-
);
79-
}
80-
return new Error(
81-
`Gateway voicecall request failed: ${message}\nCheck \`openclaw gateway status\`, then retry.`,
82-
);
63+
if (isGatewayCredentialFailure(err)) {
64+
return `Gateway requires credentials: ${message}\nConfigure gateway.auth or pair this device with \`openclaw devices approve --latest\`.`;
65+
}
66+
if (isGatewayTransportError(err)) {
67+
const url = err.connectionDetails.url;
68+
if (err.kind === "timeout") {
69+
const timeout =
70+
err.timeoutMs === undefined ? "the configured timeout" : `${err.timeoutMs}ms`;
71+
return `Gateway at ${url} did not answer within ${timeout}: ${message}\nIt may be starting or wedged; check \`openclaw gateway status\`.`;
72+
}
73+
return `Gateway connection at ${url} failed: ${message}\nCheck gateway.auth and \`openclaw gateway status\`, then retry.`;
74+
}
75+
return `Gateway voicecall request failed: ${message}\nCheck \`openclaw gateway status\`, then retry.`;
76+
})();
77+
// Configured gateway URLs may embed userinfo/tokens, and close reasons are
78+
// remote-controlled text; redact once where the text becomes operator-visible.
79+
return new Error(redactSensitiveUrlLikeString(detail));
8380
}
8481

8582
export function isUnknownMethod(err: unknown, method: VoiceCallGatewayMethod): boolean {

‎extensions/voice-call/src/cli.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,39 @@ describe("voice-call CLI status fallback", () => {
227227
expect(loadActiveCallsFromStoreMock).not.toHaveBeenCalled();
228228
});
229229

230+
it("redacts credential-bearing gateway URLs from operational errors", async () => {
231+
callGatewayFromCliMock.mockRejectedValue(
232+
Object.assign(
233+
new Error(
234+
"gateway closed (1008): policy wss://operator:[email protected]:18789",
235+
),
236+
{
237+
name: "GatewayTransportError",
238+
kind: "closed",
239+
code: 1008,
240+
connectionDetails: {
241+
url: "wss://operator:[email protected]:18789?token=tok123",
242+
},
243+
},
244+
),
245+
);
246+
const ensureRuntime = vi.fn();
247+
const program = buildProgram({}, {}, ensureRuntime);
248+
249+
let thrown: unknown;
250+
await program
251+
.parseAsync(["voicecall", "status", "--json"], { from: "user" })
252+
.catch((err: unknown) => {
253+
thrown = err;
254+
});
255+
256+
const text = thrown instanceof Error ? thrown.message : String(thrown);
257+
expect(text).toContain("Gateway connection at wss://***:***@gw.example.ts.net:18789");
258+
expect(text).not.toContain("hunter2secret");
259+
expect(text).not.toContain("tok123");
260+
expect(ensureRuntime).not.toHaveBeenCalled();
261+
});
262+
230263
it("rejects non-decimal tail options through the registered command", async () => {
231264
const program = buildProgram({});
232265
await expect(

‎scripts/plugin-sdk-surface-report.mts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ export function readPluginSdkSurfaceBudgets(env: NodeJS.ProcessEnv = process.env
296296
// +2: lightweight agent config resolution and nonthrowing default-agent lookup.
297297
// +1: focused media-store URL/path ingestion (saveMediaSource) off the deprecated barrel.
298298
// +2: structural Gateway transport and request-error guards for plugin CLI routing.
299-
4330,
299+
// +1: canonical sensitive-URL redactor so plugin CLI errors never print URL userinfo.
300+
4331,
300301
env,
301302
),
302303
publicFunctionExports: readPluginSdkSurfaceBudgetEnv(
@@ -378,7 +379,8 @@ export function readPluginSdkSurfaceBudgets(env: NodeJS.ProcessEnv = process.env
378379
// +2: lightweight agent config resolution and nonthrowing default-agent lookup.
379380
// +1: focused media-store URL/path ingestion (saveMediaSource) off the deprecated barrel.
380381
// +2: structural Gateway transport and request-error guards for plugin CLI routing.
381-
2574,
382+
// +1: canonical sensitive-URL redactor so plugin CLI errors never print URL userinfo.
383+
2575,
382384
env,
383385
),
384386
publicDeprecatedExports: readPluginSdkSurfaceBudgetEnv(

‎src/plugin-sdk/gateway-runtime.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
export { addGatewayClientOptions, callGatewayFromCli } from "../cli/gateway-rpc.js";
44
export type { GatewayRpcOpts } from "../cli/gateway-rpc.js";
55
export { isGatewayClientRequestError, isGatewayTransportError } from "../gateway/call.js";
6+
// Plugin CLIs echo gateway URLs/close reasons into operator-visible errors;
7+
// they must use the canonical redactor so URL userinfo/tokens never print.
8+
export { redactSensitiveUrlLikeString } from "@openclaw/net-policy/redact-sensitive-url";
69
export { isLoopbackHost } from "../gateway/net.js";
710
export async function resolveAdvertisedLanHost(): Promise<string | null> {
811
const runtime = await import("../infra/advertised-lan-host.js");

0 commit comments

Comments
 (0)