fix: keep tool detail redaction canonical · openclaw/openclaw@219d854
steipete
·
2026-06-01
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -3,7 +3,7 @@ import {
|
3 | 3 | normalizeOptionalString, |
4 | 4 | } from "@openclaw/normalization-core/string-coerce"; |
5 | 5 | import { parseStrictFiniteNumber } from "../infra/parse-finite-number.js"; |
6 | | -import { redactToolDetail } from "../logging/redact.js"; |
| 6 | +import { redactToolPayloadText } from "../logging/redact.js"; |
7 | 7 | import { resolveExecDetail, type ToolDetailMode } from "./tool-display-exec.js"; |
8 | 8 | import { asRecord } from "./tool-display-record.js"; |
9 | 9 | |
@@ -121,7 +121,7 @@ function coerceDisplayValue(
|
121 | 121 | if (!rawLine) { |
122 | 122 | return undefined; |
123 | 123 | } |
124 | | -const firstLine = redactToolDetail(rawLine); |
| 124 | +const firstLine = redactToolPayloadText(rawLine); |
125 | 125 | if (firstLine.length > maxStringChars) { |
126 | 126 | const half = Math.floor((maxStringChars - 1) / 2); |
127 | 127 | return `${firstLine.slice(0, half)}…${firstLine.slice(-(maxStringChars - 1 - half))}`; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | | -import { redactToolDetail } from "../logging/redact.js"; |
| 1 | +import { redactToolPayloadText } from "../logging/redact.js"; |
2 | 2 | import { |
3 | 3 | binaryName, |
4 | 4 | firstPositional, |
@@ -427,7 +427,7 @@ function isGenericSummary(summary: string): boolean {
|
427 | 427 | } |
428 | 428 | |
429 | 429 | function compactRawCommand(raw: string, maxLength = 120): string { |
430 | | -const oneLine = redactToolDetail( |
| 430 | +const oneLine = redactToolPayloadText( |
431 | 431 | raw |
432 | 432 | .replace(/\s*\n\s*/g, " ") |
433 | 433 | .replace(/\s{2,}/g, " ") |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -532,6 +532,15 @@ describe("compactRawCommand middle truncation", () => {
|
532 | 532 | // The sk- prefixed token must be redacted (masked) before truncation |
533 | 533 | expect(result).not.toContain("ABCDEFGHIJKLMNOP1234567890abcdefghij"); |
534 | 534 | }); |
| 535 | + |
| 536 | +it("uses the canonical tool payload redactor before compacting raw commands", () => { |
| 537 | +const longCommand = |
| 538 | +"/opt/custom/bin/deploy --aws-key AKIDABCDEFGHIJKLMNOP1234567890 --output /data/results/deploy-output.json"; |
| 539 | +const result = resolveExecDetail({ command: longCommand }); |
| 540 | + |
| 541 | +expect(result).not.toContain("AKIDABCDEFGHIJKLMNOP1234567890"); |
| 542 | +expect(result).toContain("AKIDAB…7890"); |
| 543 | +}); |
535 | 544 | }); |
536 | 545 | |
537 | 546 | describe("coerceDisplayValue middle truncation", () => { |
@@ -582,4 +591,20 @@ describe("coerceDisplayValue middle truncation", () => {
|
582 | 591 | // The ghp_ token must be redacted before truncation |
583 | 592 | expect(detail).not.toContain("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop"); |
584 | 593 | }); |
| 594 | + |
| 595 | +it("uses the canonical tool payload redactor before compacting string details", () => { |
| 596 | +const longValue = |
| 597 | +"Deploying with AWS key AKIDABCDEFGHIJKLMNOP1234567890 and " + |
| 598 | +"x".repeat(200) + |
| 599 | +" final-step"; |
| 600 | +const detail = formatToolDetail( |
| 601 | +resolveToolDisplay({ |
| 602 | +name: "sessions_spawn", |
| 603 | +args: { task: longValue }, |
| 604 | +}), |
| 605 | +); |
| 606 | + |
| 607 | +expect(detail).not.toContain("AKIDABCDEFGHIJKLMNOP1234567890"); |
| 608 | +expect(detail).toContain("AKIDAB…7890"); |
| 609 | +}); |
585 | 610 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | | -import type { UpdateAvailable } from "../infra/update-startup.js"; |
2 | | - |
3 | 1 | export const GATEWAY_EVENT_UPDATE_AVAILABLE = "update.available" as const; |
4 | 2 | |
| 3 | +export type UpdateAvailableEventData = { |
| 4 | +currentVersion: string; |
| 5 | +latestVersion: string; |
| 6 | +channel: string; |
| 7 | +}; |
| 8 | + |
5 | 9 | export type GatewayUpdateAvailableEventPayload = { |
6 | | -updateAvailable: UpdateAvailable | null; |
| 10 | +updateAvailable: UpdateAvailableEventData | null; |
7 | 11 | }; |
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import { describe, expect, it } from "vitest"; |
2 | | -import { redactToolDetail } from "./browser-redact.ts"; |
| 2 | +import { redactToolDetail, redactToolPayloadText } from "./browser-redact.ts"; |
3 | 3 | |
4 | 4 | describe("browser tool detail redaction", () => { |
5 | 5 | it("redacts tool detail credential families without Node config imports", () => { |
@@ -29,4 +29,10 @@ describe("browser tool detail redaction", () => {
|
29 | 29 | expect(redacted).not.toContain("abc123"); |
30 | 30 | expect(redacted).not.toContain("verySensitiveCookieValue"); |
31 | 31 | }); |
| 32 | + |
| 33 | +it("exposes the tool payload redaction name used by shared display modules", () => { |
| 34 | +expect(redactToolPayloadText("OPENAI_API_KEY=sk-1234567890abcdef")).toBe( |
| 35 | +"OPENAI_API_KEY=sk-123...cdef", |
| 36 | +); |
| 37 | +}); |
32 | 38 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -74,3 +74,5 @@ export function redactToolDetail(detail: string): string {
|
74 | 74 | } |
75 | 75 | return redacted; |
76 | 76 | } |
| 77 | + |
| 78 | +export const redactToolPayloadText = redactToolDetail; |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。