Skip to content

fix(backup): remote namespace owner names can inject terminal control codes into backup output - #184597

Closed
KrasimirKralev wants to merge 1 commit into
openclaw:mainfrom
KrasimirKralev:fix/backup-namespace-owner-terminal-controls
Closed

KrasimirKralev wants to merge 1 commit into
openclaw:mainfrom
KrasimirKralev:fix/backup-namespace-owner-terminal-controls

Conversation

@KrasimirKralev

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: openclaw backup list and the namespace-ownership refusal of openclaw backup create --to <location> print another installation's owner.json hostname (and device id) verbatim, so terminal escape sequences stored in a shared storage location reach the operator's terminal (clear screen, retitle the window, recolor or fake follow-up text).

  • Problem: owner.json in backups/<namespace>/ is written by whichever installation claimed that namespace, and its hostname/deviceId are only checked as non-empty strings. Both human output paths interpolate them raw.
  • What did NOT change (scope boundary): --json output and the stored owner.json keep their original values; namespace validation, ownership checks, takeover (--claim-namespace) and every other backup message are untouched. Plain hostnames render byte-for-byte as before.
  • Requested by a maintainer/owner? No. This is the sibling of fix(backup): escape terminal controls in schedule and record output #184153 (fix(backup): escape schedule and record report controls), which applied the same sanitizer to the schedule acknowledgement and external record label but left these two remote-sourced fields raw.

User Impact

User impact: operators who share a storage location between several installations see the other installations' hostnames as inert text in backup list and in the "belongs to another OpenClaw installation" refusal; a hostile or corrupted owner.json can no longer drive their terminal. Nothing changes for scripts that read --json.

Why This Change Was Made

  • What changed: backupListCommand (src/commands/backup-remote.ts) wraps the namespace owner hostname in sanitizeTerminalText in its human branch only, and assertOwner (src/commands/backup-namespace.ts) sanitizes the owner hostname and the shortened device id inside the refusal message, the same boundary-only approach as fix(backup): escape terminal controls in schedule and record output #184153.
  • Root cause: ownerSchema accepts any non-empty string for hostname/deviceId (correctly: it is metadata, not an identifier we resolve), but the two places that show it to a person did not escape it.
  • Missing detection / guardrail: no test covered human output of remote owner metadata. The new src/commands/backup-remote.namespace-output.test.ts plants a hostile owner.json in a real filesystem storage location and checks both outputs carry no control characters while the JSON result keeps the stored hostname. Both cases fail on main and pass with this change. Local gates on the touched files: oxfmt --check, oxlint, tsgo:core, the commands test tsconfig shard, the line-cap ratchet and the assertion-safety ratchet all pass. The new test file contains no vi.mock factory; check-test-mock-exports.mts did not finish within 10 minutes on this machine, so it was not run locally.

Evidence

  • Behavior or issue addressed: remote namespace owner hostname/device id printed raw by openclaw backup list and by the ownership refusal of openclaw backup create --to.
  • Real environment tested: Linux, Node 24.22.1, source checkout run with node --import ./scripts/tsx.mjs src/entry.ts, isolated HOME/OPENCLAW_STATE_DIR/OPENCLAW_CONFIG_PATH, one filesystem storage location named archive (encryption: "none") initialized with openclaw storage init archive. A foreign namespace laptop was planted with an owner.json whose hostname is laptop\u001b]0;owned\u0007\u001b[2J\u001b[31mFAKE: backup OK plus one timestamped backup object. Output piped through cat -v so control bytes are visible.
  • Exact steps or command run after this patch: node --import ./scripts/tsx.mjs src/entry.ts backup list --from archive, node --import ./scripts/tsx.mjs src/entry.ts backup create --to archive --namespace laptop, node --import ./scripts/tsx.mjs src/entry.ts backup list --from archive --json
  • Evidence after fix:
--- before (upstream/main eb9f9fa1dc3)
$ node --import ./scripts/tsx.mjs src/entry.ts backup list --from archive | cat -v
Available namespaces in archive:
laptop (laptop^[]0;owned^G^[[2J^[[31mFAKE: backup OK)
$ node --import ./scripts/tsx.mjs src/entry.ts backup create --to archive --namespace laptop 2>&1 | cat -v
Backup namespace "laptop" in archive belongs to another OpenClaw installation (laptop^[]0;owned^G^[[2J^[[31mFAKE: backup OK, device dev-00000000). Pass --namespace <name> to use a separate namespace, or --claim-namespace to take it over deliberately (for example after moving to new hardware).
exit 1

--- after (this branch, 681c5b8b1c1)
$ node --import ./scripts/tsx.mjs src/entry.ts backup list --from archive | cat -v
Available namespaces in archive:
laptop (laptopFAKE: backup OK)
$ node --import ./scripts/tsx.mjs src/entry.ts backup create --to archive --namespace laptop 2>&1 | cat -v
Backup namespace "laptop" in archive belongs to another OpenClaw installation (laptopFAKE: backup OK, device dev-00000000). Pass --namespace <name> to use a separate namespace, or --claim-namespace to take it over deliberately (for example after moving to new hardware).
exit 1
$ node --import ./scripts/tsx.mjs src/entry.ts backup list --from archive --json | grep -o '"hostname": "[^"]*"'
"hostname": "laptop\u001b]0;owned\u0007\u001b[2J\u001b[31mFAKE: backup OK"
$ node --import ./scripts/tsx.mjs src/entry.ts backup list --from archive --namespace laptop
20261026T000000Z-deadbeef.tar.gz  1 bytes (1 stored)
  • Observed result after fix: running node … backup list and node … backup create from source, the ESC/BEL sequences (^[, ^G) are gone from both human outputs while the readable hostname text stays; the refusal still exits 1 with the same guidance; --json still returns the stored hostname unchanged, and listing the namespace's backups is unaffected.
  • What was not tested: a remote (non-filesystem) storage provider; the stored value is read through the same readNamespaceOwner path for every provider. The backup create run stops at the ownership refusal, so no archive upload ran.
  • Proof limitations or environment constraints: the before listing omits its trailing "No backups in archive/." line, which only names this machine's default namespace.

…efusals

backup list printed the owner.json hostname from a shared storage location
verbatim, and the namespace ownership refusal embedded the remote hostname
and device id raw, so terminal control sequences written by another
installation reached the operator's terminal. Apply the existing terminal
sanitizer at those human output boundaries; JSON output and stored owner
records keep their original values.
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: S labels Oct 26, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Sanitize remote backup owner identities in namespace listings and ownership refusal messages.

Example: A shared archive contains namespace laptop with hostname laptop\u001b[2J.

  • Before: Running backup list prints the erase-screen escape sequence.
  • After: The listing prints laptop as inert text; JSON retains the original hostname.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair supported by inspectable CLI traces and two distinct filesystem-backed regressions.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Supplied Linux CLI output at head 681c5b8 exercises backup list and backup create against isolated filesystem storage containing a hostile foreign owner: controls disappear, the refusal still exits 1, raw JSON metadata survives, and namespace-specific listing remains functional.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Another installation or shared-storage writer can place terminal controls in owner metadata that execute when an operator lists backups or encounters an ownership refusal.
Reason: The patch restores safe human rendering without changing backup policy, configuration, or stored metadata.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR fixes a concrete terminal-injection path still present on current main, with a minimal patch and no actionable findings.

Priority: P2
Reviewed head: 681c5b8b1c1a30737c150c820d36f05c12601f10

Before merge

None.

Findings

None.

Agent review details

How this fits together

Backup commands read namespace owner metadata through the storage owner, then render namespace listings or reject writes belonging to another installation.

flowchart LR
 A[Shared storage owner metadata] --> B[Namespace reader]
 B --> C[Backup listing]
 B --> D[Ownership check]
 C --> E[Terminal sanitizer]
 D --> E
 E --> F[Human output]
 C --> G[Unchanged JSON output]
Loading

Technical review

Best possible solution:

Merge the focused output-boundary sanitization once existing required checks pass.

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

Source traces remote nonempty strings directly into terminal output on main, and the contributor supplies matching before/after CLI traces; this read-only review ran no target code.

Is this the best way to solve the issue?

Reusing the existing terminal sanitizer at the two rendering boundaries is the smallest complete fix and preserves ownership decisions, storage bytes, and JSON consumers.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9532824c38d7.

Provenance checked

  • Remote namespace discovery and ownership refusal keeps the original intent (37ffe3c: Named storage locations support offsite backups, installation-specific ownership, and discovery of another machine's backups.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Exact introduced patch: The pinned introduction diff adds the existing sanitizer only at the two output boundaries, plus two filesystem-backed regressions. (src/commands/backup-namespace.ts:51, 681c5b8b1c1a)
  • Current main remains affected: Current main retains raw hostname interpolation in listings and raw hostname/device interpolation in refusals; both production files are unchanged from the introduction base. (src/commands/backup-remote.ts:223, 9532824c38d7)
  • Existing sanitizer contract: The shared sanitizer strips ANSI sequences and removes or visibly escapes control characters; its tests independently cover cursor controls, OSC clipboard payloads, and line controls. (packages/terminal-core/src/safe-text.ts:11, 681c5b8b1c1a)
  • Supplied real CLI evidence: The full PR body supplies before/after Linux CLI output at the reviewed head using isolated filesystem storage: both human outputs lose ESC/BEL sequences, refusal remains exit 1, JSON preserves metadata, and explicit namespace listing works. Captured body identity: b08afece6931417f7fc0248d274536b26f6d9c04a08d83dec6d90b3afa3780c7. (681c5b8b1c1a)
  • Feature history and intent: Merged feat: back up to external disks and Cloudflare R2 with storage locations #161913 introduced namespace ownership and cross-machine discovery; later history includes runtime preparation, scratch staging, and resource simplification. The changed refusal line traces to the feature commit. Rename-follow history encountered an unavailable-object limit; ordinary path history and blame remained available. (src/commands/backup-namespace.ts:50, 37ffe3ce94e2)
  • Related merged repair is distinct: Merged fix(backup): escape terminal controls in schedule and record output #184153 credits Alix-007 and sanitizes schedule acknowledgements and external record reports; it does not cover remote namespace owner identities. (4d26a4aad96b)

Likely related people:

  • Peter Steinberger: Raw commit 37ffe3c adds src/commands/backup-namespace.ts:49 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 37ffe3ce94e2; files: src/commands/backup-namespace.ts)

PR surface

Source +2, Tests +84. Total +86 across 3 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 2 4 2 +2
Tests 1 84 0 +84
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 88 2 +86

Labels

Label changes:

  • add P2: Terminal-injection hardening has a concrete trigger limited to operators reading attacker-controlled or corrupted shared backup metadata.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Terminal-injection hardening has a concrete trigger limited to operators reading attacker-controlled or corrupted shared backup metadata.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 26, 2026, 8:24 AM ET / 12:24 UTC.

obviyus added a commit that referenced this pull request Oct 28, 2026
…amilies (#186502)

fix(cli): route remaining CLI reports through the terminal-text owner

After #185927 added one owner for escaping untrusted values in CLI output, contributors kept opening one PR per command to escape the next report. This moves the remaining human-readable reports in the plugins, secrets, sessions, memory and memory-wiki, workboard, backup, pairing, oc-path, config and setup commands onto `terminalText` / `displayPath`, and extends the owner to neutralize bidirectional control characters. JSON output, persisted identities, raw exports and the CLI's own colors are unchanged, and the trusted styling of `renderTable` is untouched.

This absorbs the per-site fixes from @Leon-SK668 (#184454, #184379, #185374, #186449, #184396, #184788, #184813, #184394), @huwei-xydt (#185895, #185719), @wangmiao0668000666 (#175600, #175181, #175179), @SunnyShu0925 (#184747), @KrasimirKralev (#184597) and @arpe1618 (#150599), whose original commits are kept. Families no PR touched (update, Doctor, install-trust producers and others) are listed under "Not fixed here".

Evidence: 85 built-CLI invocations per ref with crafted control and bidi characters in the reported values, captured as raw stdout bytes. Main printed the raw sequences; this change printed them neutralized, with identical normal colors and unchanged JSON. Details: #186502 (comment).

Co-authored-by: 胡伟0668000622 <[email protected]>
Co-authored-by: Claude Code <[email protected]>
Co-authored-by: Leon-SK668 <[email protected]>
Co-authored-by: wangmiao0668000666 <[email protected]>
Co-authored-by: SunnyShu <0668000539@local>
Co-authored-by: Krasimir Kralev <[email protected]>
Co-authored-by: arpe1618 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks @KrasimirKralev. This is now fixed at the root in #186502 (3bcca4f), which routes the remaining CLI reports through the shared terminalText owner from terminal-core. Your commit is kept in that merge and you're credited as co-author, so I'm closing this one as covered. For new output sites, please pass untrusted values through terminalText (or displayPath for paths) rather than opening a PR per command.

@obviyus obviyus closed this Oct 28, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
…amilies (openclaw#186502)

fix(cli): route remaining CLI reports through the terminal-text owner

After openclaw#185927 added one owner for escaping untrusted values in CLI output, contributors kept opening one PR per command to escape the next report. This moves the remaining human-readable reports in the plugins, secrets, sessions, memory and memory-wiki, workboard, backup, pairing, oc-path, config and setup commands onto `terminalText` / `displayPath`, and extends the owner to neutralize bidirectional control characters. JSON output, persisted identities, raw exports and the CLI's own colors are unchanged, and the trusted styling of `renderTable` is untouched.

This absorbs the per-site fixes from @Leon-SK668 (openclaw#184454, openclaw#184379, openclaw#185374, openclaw#186449, openclaw#184396, openclaw#184788, openclaw#184813, openclaw#184394), @huwei-xydt (openclaw#185895, openclaw#185719), @wangmiao0668000666 (openclaw#175600, openclaw#175181, openclaw#175179), @SunnyShu0925 (openclaw#184747), @KrasimirKralev (openclaw#184597) and @arpe1618 (openclaw#150599), whose original commits are kept. Families no PR touched (update, Doctor, install-trust producers and others) are listed under "Not fixed here".

Evidence: 85 built-CLI invocations per ref with crafted control and bidi characters in the reported values, captured as raw stdout bytes. Main printed the raw sequences; this change printed them neutralized, with identical normal colors and unchanged JSON. Details: openclaw#186502 (comment).

Co-authored-by: 胡伟0668000622 <[email protected]>
Co-authored-by: Claude Code <[email protected]>
Co-authored-by: Leon-SK668 <[email protected]>
Co-authored-by: wangmiao0668000666 <[email protected]>
Co-authored-by: SunnyShu <0668000539@local>
Co-authored-by: Krasimir Kralev <[email protected]>
Co-authored-by: arpe1618 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants