Skip to content

fix(cli): redact machine-readable error payloads - #124075

Merged
steipete merged 1 commit into
mainfrom
steipete/cli-json-error-redaction
Aug 15, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/cli-json-error-redaction

Conversation

@steipete

@steipete steipete commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Related: #123929

What Problem This Solves

Fixes an issue where several CLI failures exposed internal JavaScript error class names, and where --json commands serialized caught errors without redaction. The affected paths included System, Directory, Gmail webhook setup, daemon status, and config dry-run output; credential-shaped text in a thrown error could reach machine-readable stdout unchanged.

This is AI-assisted work, reviewed and validated against the affected command boundaries.

Why This Change Was Made

PR #123929 moved direct error(String(err)) calls to the canonical redacting formatter, but its sweep missed values wrapped by danger(...) and values nested inside writeJson({ error: ... }). This change routes those surviving CLI rendering paths through formatErrorMessage, including the omitted webhooks gmail run catch, unsafe preformatted daemon status messages, and SecretRef resolution failures that feed config dry-run JSON.

Redaction remains caller-owned. writeJson and writeStdout are generic, byte-preserving output primitives used for structured and intentionally literal payloads; centrally rewriting their output would risk changing unrelated machine contracts and would repeat work for already-safe payloads. Formatting only caught errors preserves unrelated JSON bytes and keeps the existing error keys and exit codes unchanged.

No new cross-file CLI result abstraction was added. The canonical formatter is already the shared abstraction, while the existing command-local wrappers retain ownership of JSON selection, colorization, and exit behavior.

User Impact

Operators now receive readable error messages without internal class-name prefixes. Machine consumers keep valid JSON and the same keys, while secret-shaped values in caught errors are redacted before they reach stdout. All affected commands preserve their prior exit codes, and human output keeps terminal colorization.

Evidence

Before, the live Directory repro produced:

{
  "error": "AgentSelectionRequiredError: Multiple agents are configured, but this operation has no explicit owner. ..."
}

The pre-fix boundary run failed 15 assertions across the three reported commands, including a Gmail JSON case that observed the full synthetic credential-shaped value: https://github.com/openclaw/openclaw/actions/runs/31870151321

After building the exact head with the cliStartup build profile, the isolated macOS repro (OPENCLAW_STATE_DIR under /private/tmp, OPENCLAW_SKIP_CHANNELS=1) produced valid JSON with exit 1:

{
  "error": "Multiple agents are configured, but this operation has no explicit owner. Select an agent explicitly; CLI callers can pass --agent <id>, channels can add a binding, and ambient services can set their agentId target."
}

Human mode produced the same message without the class name and exited 1.

Validation:

Production LOC: +51/-28 (net +23, primarily canonical formatter imports and explicit safe formatting at security boundaries) | Tests: +138/-36 (net +102)

@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: M maintainer Maintainer-authored PR labels Aug 15, 2026
@steipete
steipete marked this pull request as ready for review August 15, 2026 07:06
@steipete
steipete marked this pull request as draft August 15, 2026 07:08
@steipete
steipete marked this pull request as ready for review August 15, 2026 07:08
@steipete
steipete force-pushed the steipete/cli-json-error-redaction branch from cd86410 to b2e09c6 Compare August 15, 2026 07:16
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 15, 2026, 3:34 AM ET / 07:34 UTC.

ClawSweeper review

What this changes

This PR applies the canonical redacting error formatter to several CLI human and JSON error paths, adds boundary regressions, and repairs an unrelated Control UI lint failure.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open: the latest lint-only commit did not address the prior P1. Shared Gateway and Node lifecycle failures still serialize raw caught errors into JSON responses, so class names and credential-shaped text can remain exposed.

Priority: P1
Reviewed head: ddc8f69f6be131036834c99f8d56dabc12e1eee6

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch has useful focused coverage and reported runtime evidence, but it remains incomplete at the shared security boundary.
Proof confidence 🌊 off-meta tidepool Not applicable: This is maintainer-authored work, so the external contributor proof gate does not apply; the PR body nevertheless includes terminal after-fix evidence for its changed paths.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is maintainer-authored work, so the external contributor proof gate does not apply; the PR body nevertheless includes terminal after-fix evidence for its changed paths.
Evidence reviewed 6 items Current-main unsafe lifecycle boundary: Current main and the PR head both retain raw error stringification before the lifecycle failure callback.
JSON emission path: The shared lifecycle failure callback writes its supplied error message directly into the JSON response.
Formatter contract: The canonical formatter uses the owner redactor, and its tests prove bearer-token text is removed.
Findings 1 actionable finding [P1] Format shared lifecycle errors before JSON emission
Security Needs attention Shared lifecycle errors bypass redaction: Gateway and Node lifecycle failures pass raw String(err) into a JSON-emitting callback, allowing credential-shaped service errors to appear in machine-readable output.

How this fits together

CLI service commands call shared Gateway and Node lifecycle code, which turns service-manager failures into terminal text or machine-readable JSON. The formatter must run before that shared lifecycle owner emits its response.

flowchart LR
A[Gateway or Node command] --> B[Shared lifecycle owner]
B --> C[Caught service error]
C --> D{Error formatting}
D --> E[Terminal failure]
D --> F[JSON failure response]
F --> G[Operator automation]
Loading

Before merge

  • Format shared lifecycle errors before JSON emission (P1) - The shared Gateway/Node lifecycle owner still passes String(err) to fail, and fail writes that text directly to JSON. A named service error containing a bearer token therefore bypasses the formatter despite the status-command fixes; format every caught lifecycle error and add a JSON redaction regression. This is the still-unfixed blocker from the prior review.
  • Resolve security concern: Shared lifecycle errors bypass redaction - Gateway and Node lifecycle failures pass raw String(err) into a JSON-emitting callback, allowing credential-shaped service errors to appear in machine-readable output.
  • Resolve merge risk (P1) - Merging leaves shared Gateway and Node lifecycle commands able to place raw service-error class names and credential-shaped text in --json output.
  • Complete next step (P2) - The protected maintainer PR needs its shared lifecycle security blocker resolved and re-reviewed before merge.

Findings

  • [P1] Format shared lifecycle errors before JSON emission — src/cli/daemon-cli/lifecycle-core.ts:143
  • [medium] Shared lifecycle errors bypass redaction — src/cli/daemon-cli/lifecycle-core.ts:143
Agent review details

Security

Needs attention: A shared daemon lifecycle path still bypasses the redacting formatter before emitting JSON.

PR surface

Source +23, Tests +102. Total +125 across 20 files.

View PR surface stats
Area Files Added Removed Net
Source 13 55 32 +23
Tests 7 138 36 +102
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 20 193 68 +125

Review metrics

Metric Value Why it matters
Production versus test delta production +51/-28; tests +138/-36; test support +4/-4 The positive production growth is justified by explicit security formatting at command boundaries, but the shared lifecycle owner remains outside the sweep.
Uncovered lifecycle boundary 14 direct caught-error stringifications across 2 shared lifecycle modules These untouched paths can feed the daemon JSON failure response without the canonical redactor.

Stored data model

Persistent data-model change detected: serialized state: src/cli/config-cli.test.ts, serialized state: src/cli/daemon-cli/status.test.ts, serialized state: src/cli/node-cli/daemon.test.ts, serialized state: src/cli/system-cli.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Finish the shared lifecycle sweep (recommended)
    Route lifecycle-core and response caught errors through the canonical formatter and prove Gateway and Node JSON failures redact secrets before merge.

Technical review

Best possible solution:

Format every caught service error in the shared lifecycle and install-response owners, then add JSON regressions that reject both a named error and a synthetic bearer token.

Do we have a high-confidence way to reproduce the issue?

Yes, source-reproducible: make a shared service operation reject with a named error containing a bearer token and invoke Gateway or Node lifecycle --json; lifecycle-core currently passes String(err) to the JSON emitter.

Is this the best way to solve the issue?

No. Updating status commands is insufficient because Gateway and Node lifecycle commands share the untouched lifecycle-core and response owners; those caught errors must use the canonical formatter there.

Full review comments:

  • [P1] Format shared lifecycle errors before JSON emission — src/cli/daemon-cli/lifecycle-core.ts:143
    The shared Gateway/Node lifecycle owner still passes String(err) to fail, and fail writes that text directly to JSON. A named service error containing a bearer token therefore bypasses the formatter despite the status-command fixes; format every caught lifecycle error and add a JSON redaction regression. This is the still-unfixed blocker from the prior review.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9e911d560102.

Labels

Label justifications:

  • P1: Shared Gateway and Node lifecycle commands can still expose sensitive caught-error text through machine-readable output.
  • merge-risk: 🚨 security-boundary: The PR claims a redaction sweep but leaves a shared service-error path that can disclose credential-shaped values.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This is maintainer-authored work, so the external contributor proof gate does not apply; the PR body nevertheless includes terminal after-fix evidence for its changed paths.

Evidence

Security concerns:

  • [medium] Shared lifecycle errors bypass redaction — src/cli/daemon-cli/lifecycle-core.ts:143
    Gateway and Node lifecycle failures pass raw String(err) into a JSON-emitting callback, allowing credential-shaped service errors to appear in machine-readable output.
    Confidence: 0.99

What I checked:

Likely related people:

  • steipete: Blame attributes the remaining lifecycle boundary to this contributor, who also authored the preceding merged formatter sweep. (role: recent lifecycle contributor and formatter-sweep author; confidence: high; commits: 289c31ad7340, 2463ea0a5e64; files: src/cli/daemon-cli/lifecycle-core.ts, src/infra/errors.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Format the lifecycle-core and response failure paths, then add a Gateway or Node lifecycle JSON regression with a named bearer-token error.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-15T07:21:59.839Z sha b2e09c696c1d5ea7b2bd606410c7a1d53395cb20 :: needs changes before merge. :: [P1] Redact daemon lifecycle errors before JSON emission

@openclaw-barnacle openclaw-barnacle Bot added the app: web-ui App: web-ui label Aug 15, 2026
@steipete
steipete force-pushed the steipete/cli-json-error-redaction branch from ddc8f69 to 27937f6 Compare August 15, 2026 07:37
@openclaw-barnacle openclaw-barnacle Bot removed the app: web-ui App: web-ui label Aug 15, 2026
@steipete
steipete merged commit 49e1ea2 into main Aug 15, 2026
187 checks passed
@steipete
steipete deleted the steipete/cli-json-error-redaction branch August 15, 2026 07:44
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes maintainer Maintainer-authored PR merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant