Skip to content

fix(hooks): escape terminal controls in toggle confirmations - #184303

Closed
Alix-007 wants to merge 1 commit into
openclaw:mainfrom
Alix-007:alix/terminal-hook-toggles-20261026
Closed

Alix-007 wants to merge 1 commit into
openclaw:mainfrom
Alix-007:alix/terminal-hook-toggles-20261026

Conversation

@Alix-007

Copy link
Copy Markdown
Contributor

What Problem This Solves

successful hooks enable/disable confirmations print control sequences and injected line breaks from discovered hook names and custom emoji, after the config mutation has already succeeded.

Why This Change Was Made

Reuse the established terminal-text sanitizer at the human display boundary. Trusted report separators remain separate; raw operation inputs and persisted values do not pass through display conversion.

User Impact

Hook toggle confirmations show readable escaped metadata instead of terminal actions or forged status lines. Both custom-emoji and default-icon branches are covered. The original hook key, selection policy, descriptor, and existing per-hook env values are preserved; enabled bits still follow the requested command. No configuration, protocol/schema, permission, migration or upgrade action changes.

Evidence

  • Scenario: Successful hook enable/disable acknowledgements safely render names and custom emoji without changing raw metadata or config-key writes.

  • Entry: hooks enable / hooks disable through normal built openclaw.mjs; disputed owner ran unmocked: src/cli/hooks-cli.ts executed unmocked

  • Same command on base f4ae32f and head 2633b01: node proof-hooks.mjs "$CHECKOUT" "$PHASE"

    • Before (base): RED escape-hook-enable: controls=6, forgedRow=true, escapedNewline=false; escape-hook-disable: controls=6, forgedRow=true, escapedNewline=false; escape-no-emoji-enable: controls=3, forgedRow=true, escapedNewline=false; escape-no-emoji-disable: controls=3, forgedRow=true, escapedNewline=false
    • After (head): GREEN escape-hook-enable: controls=0, forgedRow=false, escapedNewline=true; escape-hook-disable: controls=0, forgedRow=false, escapedNewline=true; escape-no-emoji-enable: controls=0, forgedRow=false, escapedNewline=true; escape-no-emoji-disable: controls=0, forgedRow=false, escapedNewline=true
  • Readback (subprocess,disk): Normal-built CLI discovers three actual workspace hooks from HOOK.md, commits enable/disable config changes, then prints the acknowledgement. Separate hooks info --json processes return original metadata; direct config and descriptor hash readback verifies exact keys, preserved env fields and unchanged source files.

  • Proof harness: proof-common.mjs sha256=8a6d2e48b1b076878e98641b0791f7fb064f44bbff9522fe43d1d34c6ffb007f; proof-hooks.mjs sha256=0c27781d6201b121bd900ee67029ece46d3f4ac929d86bdc61ed0721c4598c75

  • Control: Authoritative captured CLI control counts: baseline [6,6,3,3], head [0,0,0,0]. Ordinary same-entry command controls succeed with exit0; independent original-value JSON/disk checks pass. Both actions, with and without custom emoji, succeed with correct persisted enabled bits. The ordinary hook succeeds unchanged. All six commands preserve per-hook env metadata; all descriptors remain byte-identical. A marker-capable synthetic handler has zero invocations. Unicode retained; GREEN acknowledgements contain no embedded action controls or forged rows.

  • Other callers checked: Affected human output owner and raw JSON/readback siblings inspected. Existing terminal-core sanitizer reused; no new input validation, storage, backend policy or protocol.

  • Tests: pnpm test src/cli/hooks-cli.toggle.test.ts --maxWorkers=1 => Tests 25 passed (25); exit 0 (measured cost: 24.03 seconds measured command wall time, including native wrapper/worker preparation and artifact verification; not just assertion duration. The first cold run took 136.252s and hit the existing Gateway-owner refusal case's 120s timeout; worker preparation alone took108.437s, and24 other cases passed. The unmodified full-file rerun passed all25 in 24.03s using retained compiler outputs; no test, timeout or assertion was changed.)

  • Not tested: Isolated Linux local config and workspace hooks only. This tests toggling and rendering, not dispatching a hook event or reloading a live Gateway. No production service/channel, remote report, error-diagnostic, Windows/macOS or whole CI claim. Upstream required CI has not run before PR creation.

  • Product head: 2633b012684f8ba8dee340d1559f1d55ef2cb166; baseline: f4ae32fe1b035ce86561887e897d75c13557adbc. Linux, Node26.12.1, pnpm12.15.0; normal clean cliStartup build on each revision. Exact commands, captured outputs and independent readback are below.

  • Focused regression: pnpm test src/cli/hooks-cli.toggle.test.ts --maxWorkers=1 → Tests 25 passed (25); 24.03s measured wall time including native preparation. Existing owner controls remain in the suite.

  • Cold-run note: The first cold run took 136.252s and hit the existing Gateway-owner refusal case's 120s timeout; worker preparation alone took108.437s, and24 other cases passed. The unmodified full-file rerun passed all25 in 24.03s using retained compiler outputs; no test, timeout or assertion was changed.

  • 3 files; production +2/−2 LOC; tests +32/−0 LOC. Simplification: existing sanitizer and canonical owner retained, no new helper/state/test-only production seam.

  • Existing-solutions/sibling preflight: The existing terminal-core sanitizer is already used by read-only hook reports. fix(cli): prevent descriptor controls in skill and hook reports #172872 fixed those reports, and fix(hooks): stop executing escape sequences from hook manifest metadata #175978/fix(skills): stop executing escape sequences embedded in SKILL.md descriptions #175601 were closed as superseded; none covered the successful mutation acknowledgement. Full toggle owner and refusal/JSON/report siblings were inspected; no viable competing open PR or Alix/Leon production-file overlap was found.

  • Full base-to-candidate independent P0–P3 source review: pass, no findings. The explicitly authorized GPT6.1 Sol subagent fallback was used; this is not an official autoreview-helper success.

  • Isolation/cleanup: independent HOME/state/config and synthetic local data; no production service, credentials or channels touched. Fixtures retained for audit in their generated temporary directories and removable as those individual directories. No service started or deployment performed.

  • Limits: Isolated Linux local config and workspace hooks only. This tests toggling and rendering, not dispatching a hook event or reloading a live Gateway. No production service/channel, remote report, error-diagnostic, Windows/macOS or whole CI claim. Upstream required CI remains pending after creation.

Actual baseline and exact-head CLI output with independent readback

Streams are JSON-escaped for safe inspection; generated temporary roots are replaced with $FIXTURE.

{
  "phase": "red",
  "head": "f4ae32fe1b035ce86561887e897d75c13557adbc",
  "at": "2026-10-26T06:11:11.279Z",
  "runs": [
    {
      "label": "escape-hook-enable",
      "args": [
        "$CHECKOUT/openclaw.mjs",
        "hooks",
        "enable",
        "escape-hook",
        "--agent",
        "main"
      ],
      "code": 0,
      "signal": null,
      "stdout": "✓ Enabled hook: café\u001b[31m\noperator-forged\tend\rrow\u0007 café\u001b[31m\noperator-forged\tend\rrow\u0007\n",
      "stderr": "",
      "seconds": 8.058437974
    },
    {
      "label": "escape-hook-disable",
      "args": [
        "$CHECKOUT/openclaw.mjs",
        "hooks",
        "disable",
        "escape-hook",
        "--agent",
        "main"
      ],
      "code": 0,
      "signal": null,
      "stdout": "Disabled hook: café\u001b[31m\noperator-forged\tend\rrow\u0007 café\u001b[31m\noperator-forged\tend\rrow\u0007\n",
      "stderr": "",
      "seconds": 8.430883318
    },
    {
      "label": "escape-hook-json",
      "args": [
        "$CHECKOUT/openclaw.mjs",
        "hooks",
        "info",
        "escape-hook",
        "--agent",
        "main",
        "--json"
      ],
      "code": 0,
      "signal": null,
      "stdout": "{\n  \"name\": \"café\\u001b[31m\\noperator-forged\\tend\\rrow\\u0007\",\n  \"description\": \"Toggle an isolated synthetic hook without invoking its handler.\",\n  \"source\": \"openclaw-workspace\",\n  \"filePath\": \"$FIXTURE/workspace/hooks/escape-hook/HOOK.md\",\n  \"baseDir\": \"$FIXTURE/workspace/hooks/escape-hook\",\n  \"handlerPath\": \"$FIXTURE/workspace/hooks/escape-hook/handler.ts\",\n  \"hookKey\": \"escape-hook\",\n  \"emoji\": \"café\\u001b[31m\\noperator-forged\\tend\\rrow\\u0007\",\n  \"events\": [\n    \"command:new\"\n  ],\n  \"unknownEvents\": [],\n  \"always\": false,\n  \"enabledByConfig\": false,\n  \"requirementsSatisfied\": true,\n  \"loadable\": false,\n  \"blockedReason\": \"disabled in config\",\n  \"managedByPlugin\": false,\n  \"requirements\": {\n    \"bins\": [],\n    \"anyBins\": [],\n    \"env\": [],\n    \"config\": [],\n    \"os\": []\n  },\n  \"missing\": {\n    \"bins\": [],\n    \"anyBins\": [],\n    \"env\": [],\n    \"config\": [],\n    \"os\": []\n  },\n  \"configChecks\": [],\n  \"install\": [],\n  \"eligible\": false,\n  \"disabled\": true\n}\n",
      "stderr": "",
      "seconds": 6.292225198
    },
    {
      "label": "escape-no-emoji-enable",
      "args": [
        "$CHECKOUT/openclaw.mjs",
        "hooks",
        "enable",
        "escape-no-emoji",
        "--agent",
        "main"
      ],
      "code": 0,
      "signal": null,
      "stdout": "✓ Enabled hook: café\u001b[31m\noperator-forged\tend\rrow\u0007-plain\n",
      "stderr": "",
      "seconds": 8.533007392
    },
    {
      "label": "escape-no-emoji-disable",
      "args": [
        "$CHECKOUT/openclaw.mjs",
        "hooks",
        "disable",
        "escape-no-emoji",
        "--agent",
        "main"
      ],
      "code": 0,
      "signal": null,
      "stdout": "Disabled hook: café\u001b[31m\noperator-forged\tend\rrow\u0007-plain\n",
      "stderr": "",
      "seconds": 8.282131095
    },
    {
      "label": "escape-no-emoji-json",
      "args": [
        "$CHECKOUT/openclaw.mjs",
        "hooks",
        "info",
        "escape-no-emoji",
        "--agent",
        "main",
        "--json"
      ],
      "code": 0,
      "signal": null,
      "stdout": "{\n  \"name\": \"café\\u001b[31m\\noperator-forged\\tend\\rrow\\u0007-plain\",\n  \"description\": \"Toggle an isolated synthetic hook without invoking its handler.\",\n  \"source\": \"openclaw-workspace\",\n  \"filePath\": \"$FIXTURE/workspace/hooks/escape-no-emoji/HOOK.md\",\n  \"baseDir\": \"$FIXTURE/workspace/hooks/escape-no-emoji\",\n  \"handlerPath\": \"$FIXTURE/workspace/hooks/escape-no-emoji/handler.ts\",\n  \"hookKey\": \"escape-no-emoji\",\n  \"events\": [\n    \"command:new\"\n  ],\n  \"unknownEvents\": [],\n  \"always\": false,\n  \"enabledByConfig\": false,\n  \"requirementsSatisfied\": true,\n  \"loadable\": false,\n  \"blockedReason\": \"disabled in config\",\n  \"managedByPlugin\": false,\n  \"requirements\": {\n    \"bins\": [],\n    \"anyBins\": [],\n    \"env\": [],\n    \"config\": [],\n    \"os\": []\n  },\n  \"missing\": {\n    \"bins\": [],\n    \"anyBins\": [],\n    \"env\": [],\n    \"config\": [],\n    \"os\": []\n  },\n  \"configChecks\": [],\n  \"install\": [],\n  \"eligible\": false,\n  \"disabled\": true\n}\n",
      "stderr": "",
      "seconds": 5.952977191999999
    },
    {
      "label": "ordinary-hook-enable",
      "args": [
        "$CHECKOUT/openclaw.mjs",
        "hooks",
        "enable",
        "ordinary-hook",
        "--agent",
        "main"
      ],
      "code": 0,
      "signal": null,
      "stdout": "✓ Enabled hook: ordinary-hook\n",
      "stderr": "",
      "seconds": 8.486553697999996
    },
    {
      "label": "ordinary-hook-disable",
      "args": [
        "$CHECKOUT/openclaw.mjs",
        "hooks",
        "disable",
        "ordinary-hook",
        "--agent",
        "main"
      ],
      "code": 0,
      "signal": null,
      "stdout": "Disabled hook: ordinary-hook\n",
      "stderr": "",
      "seconds": 8.395312948000006
    },
    {
      "label": "ordinary-hook-json",
      "args": [
        "$CHECKOUT/openclaw.mjs",
        "hooks",
        "info",
        "ordinary-hook",
        "--agent",
        "main",
        "--json"
      ],
      "code": 0,
      "signal": null,
      "stdout": "{\n  \"name\": \"ordinary-hook\",\n  \"description\": \"Toggle an isolated synthetic hook without invoking its handler.\",\n  \"source\": \"openclaw-workspace\",\n  \"filePath\": \"$FIXTURE/workspace/hooks/ordinary-hook/HOOK.md\",\n  \"baseDir\": \"$FIXTURE/workspace/hooks/ordinary-hook\",\n  \"handlerPath\": \"$FIXTURE/workspace/hooks/ordinary-hook/handler.ts\",\n  \"hookKey\": \"ordinary-hook\",\n  \"events\": [\n    \"command:new\"\n  ],\n  \"unknownEvents\": [],\n  \"always\": false,\n  \"enabledByConfig\": false,\n  \"requirementsSatisfied\": true,\n  \"loadable\": false,\n  \"blockedReason\": \"disabled in config\",\n  \"managedByPlugin\": false,\n  \"requirements\": {\n    \"bins\": [],\n    \"anyBins\": [],\n    \"env\": [],\n    \"config\": [],\n    \"os\": []\n  },\n  \"missing\": {\n    \"bins\": [],\n    \"anyBins\": [],\n    \"env\": [],\n    \"config\": [],\n    \"os\": []\n  },\n  \"configChecks\": [],\n  \"install\": [],\n  \"eligible\": false,\n  \"disabled\": true\n}\n",
      "stderr": "",
      "seconds": 6.096037522000006
    }
  ],
  "observations": [
    {
      "label": "escape-hook-enable",
      "controls": 6,
      "forgedLine": true,
      "escapedLine": false,
      "unicode": true
    },
    {
      "label": "escape-hook-disable",
      "controls": 6,
      "forgedLine": true,
      "escapedLine": false,
      "unicode": true
    },
    {
      "label": "escape-no-emoji-enable",
      "controls": 3,
      "forgedLine": true,
      "escapedLine": false,
      "unicode": true
    },
    {
      "label": "escape-no-emoji-disable",
      "controls": 3,
      "forgedLine": true,
      "escapedLine": false,
      "unicode": true
    }
  ],
  "readback": {
    "escape-hook-enable": {
      "key": "escape-hook",
      "enabled": true,
      "envPreserved": true
    },
    "escape-hook-disable": {
      "key": "escape-hook",
      "enabled": false,
      "envPreserved": true
    },
    "escape-hook-raw": {
      "name": "café\u001b[31m\noperator-forged\tend\rrow\u0007",
      "emoji": "café\u001b[31m\noperator-forged\tend\rrow\u0007",
      "hookKey": "escape-hook",
      "enabledByConfig": false
    },
    "escape-no-emoji-enable": {
      "key": "escape-no-emoji",
      "enabled": true,
      "envPreserved": true
    },
    "escape-no-emoji-disable": {
      "key": "escape-no-emoji",
      "enabled": false,
      "envPreserved": true
    },
    "escape-no-emoji-raw": {
      "name": "café\u001b[31m\noperator-forged\tend\rrow\u0007-plain",
      "emoji": null,
      "hookKey": "escape-no-emoji",
      "enabledByConfig": false
    },
    "ordinary-hook-enable": {
      "key": "ordinary-hook",
      "enabled": true,
      "envPreserved": true
    },
    "ordinary-hook-disable": {
      "key": "ordinary-hook",
      "enabled": false,
      "envPreserved": true
    },
    "ordinary-hook-raw": {
      "name": "ordinary-hook",
      "emoji": null,
      "hookKey": "ordinary-hook",
      "enabledByConfig": false
    },
    "descriptorHashes": [
      "4b79eeae2e7f8070e533aa0f324d40eb3c9cc540f43677f2a14f7eb0722d80b2",
      "13604d6b79e9216e387871fa05d9dd288d728d5d12310e5baf1bf79e2a72bafa",
      "7d75bce1a8281b8921c2894cef81daac85b5b133e2f2adab8eb5e5ef8eb9e7f2"
    ],
    "metadataUnchanged": true,
    "handlerInvocationCount": 0
  },
  "result": "PASS"
}
{
  "phase": "green",
  "head": "2633b012684f8ba8dee340d1559f1d55ef2cb166",
  "at": "2026-10-26T06:34:13.171Z",
  "runs": [
    {
      "label": "escape-hook-enable",
      "args": [
        "$CHECKOUT/openclaw.mjs",
        "hooks",
        "enable",
        "escape-hook",
        "--agent",
        "main"
      ],
      "code": 0,
      "signal": null,
      "stdout": "✓ Enabled hook: café\\noperator-forged\\tend\\rrow café\\noperator-forged\\tend\\rrow\n",
      "stderr": "",
      "seconds": 10.215180133
    },
    {
      "label": "escape-hook-disable",
      "args": [
        "$CHECKOUT/openclaw.mjs",
        "hooks",
        "disable",
        "escape-hook",
        "--agent",
        "main"
      ],
      "code": 0,
      "signal": null,
      "stdout": "Disabled hook: café\\noperator-forged\\tend\\rrow café\\noperator-forged\\tend\\rrow\n",
      "stderr": "",
      "seconds": 10.741528057000002
    },
    {
      "label": "escape-hook-json",
      "args": [
        "$CHECKOUT/openclaw.mjs",
        "hooks",
        "info",
        "escape-hook",
        "--agent",
        "main",
        "--json"
      ],
      "code": 0,
      "signal": null,
      "stdout": "{\n  \"name\": \"café\\u001b[31m\\noperator-forged\\tend\\rrow\\u0007\",\n  \"description\": \"Toggle an isolated synthetic hook without invoking its handler.\",\n  \"source\": \"openclaw-workspace\",\n  \"filePath\": \"$FIXTURE/workspace/hooks/escape-hook/HOOK.md\",\n  \"baseDir\": \"$FIXTURE/workspace/hooks/escape-hook\",\n  \"handlerPath\": \"$FIXTURE/workspace/hooks/escape-hook/handler.ts\",\n  \"hookKey\": \"escape-hook\",\n  \"emoji\": \"café\\u001b[31m\\noperator-forged\\tend\\rrow\\u0007\",\n  \"events\": [\n    \"command:new\"\n  ],\n  \"unknownEvents\": [],\n  \"always\": false,\n  \"enabledByConfig\": false,\n  \"requirementsSatisfied\": true,\n  \"loadable\": false,\n  \"blockedReason\": \"disabled in config\",\n  \"managedByPlugin\": false,\n  \"requirements\": {\n    \"bins\": [],\n    \"anyBins\": [],\n    \"env\": [],\n    \"config\": [],\n    \"os\": []\n  },\n  \"missing\": {\n    \"bins\": [],\n    \"anyBins\": [],\n    \"env\": [],\n    \"config\": [],\n    \"os\": []\n  },\n  \"configChecks\": [],\n  \"install\": [],\n  \"eligible\": false,\n  \"disabled\": true\n}\n",
      "stderr": "",
      "seconds": 7.267616737
    },
    {
      "label": "escape-no-emoji-enable",
      "args": [
        "$CHECKOUT/openclaw.mjs",
        "hooks",
        "enable",
        "escape-no-emoji",
        "--agent",
        "main"
      ],
      "code": 0,
      "signal": null,
      "stdout": "✓ Enabled hook: café\\noperator-forged\\tend\\rrow-plain\n",
      "stderr": "",
      "seconds": 9.218923438999997
    },
    {
      "label": "escape-no-emoji-disable",
      "args": [
        "$CHECKOUT/openclaw.mjs",
        "hooks",
        "disable",
        "escape-no-emoji",
        "--agent",
        "main"
      ],
      "code": 0,
      "signal": null,
      "stdout": "Disabled hook: café\\noperator-forged\\tend\\rrow-plain\n",
      "stderr": "",
      "seconds": 9.479547767999996
    },
    {
      "label": "escape-no-emoji-json",
      "args": [
        "$CHECKOUT/openclaw.mjs",
        "hooks",
        "info",
        "escape-no-emoji",
        "--agent",
        "main",
        "--json"
      ],
      "code": 0,
      "signal": null,
      "stdout": "{\n  \"name\": \"café\\u001b[31m\\noperator-forged\\tend\\rrow\\u0007-plain\",\n  \"description\": \"Toggle an isolated synthetic hook without invoking its handler.\",\n  \"source\": \"openclaw-workspace\",\n  \"filePath\": \"$FIXTURE/workspace/hooks/escape-no-emoji/HOOK.md\",\n  \"baseDir\": \"$FIXTURE/workspace/hooks/escape-no-emoji\",\n  \"handlerPath\": \"$FIXTURE/workspace/hooks/escape-no-emoji/handler.ts\",\n  \"hookKey\": \"escape-no-emoji\",\n  \"events\": [\n    \"command:new\"\n  ],\n  \"unknownEvents\": [],\n  \"always\": false,\n  \"enabledByConfig\": false,\n  \"requirementsSatisfied\": true,\n  \"loadable\": false,\n  \"blockedReason\": \"disabled in config\",\n  \"managedByPlugin\": false,\n  \"requirements\": {\n    \"bins\": [],\n    \"anyBins\": [],\n    \"env\": [],\n    \"config\": [],\n    \"os\": []\n  },\n  \"missing\": {\n    \"bins\": [],\n    \"anyBins\": [],\n    \"env\": [],\n    \"config\": [],\n    \"os\": []\n  },\n  \"configChecks\": [],\n  \"install\": [],\n  \"eligible\": false,\n  \"disabled\": true\n}\n",
      "stderr": "",
      "seconds": 6.726077805000001
    },
    {
      "label": "ordinary-hook-enable",
      "args": [
        "$CHECKOUT/openclaw.mjs",
        "hooks",
        "enable",
        "ordinary-hook",
        "--agent",
        "main"
      ],
      "code": 0,
      "signal": null,
      "stdout": "✓ Enabled hook: ordinary-hook\n",
      "stderr": "",
      "seconds": 8.599397127999996
    },
    {
      "label": "ordinary-hook-disable",
      "args": [
        "$CHECKOUT/openclaw.mjs",
        "hooks",
        "disable",
        "ordinary-hook",
        "--agent",
        "main"
      ],
      "code": 0,
      "signal": null,
      "stdout": "Disabled hook: ordinary-hook\n",
      "stderr": "",
      "seconds": 9.082924941999991
    },
    {
      "label": "ordinary-hook-json",
      "args": [
        "$CHECKOUT/openclaw.mjs",
        "hooks",
        "info",
        "ordinary-hook",
        "--agent",
        "main",
        "--json"
      ],
      "code": 0,
      "signal": null,
      "stdout": "{\n  \"name\": \"ordinary-hook\",\n  \"description\": \"Toggle an isolated synthetic hook without invoking its handler.\",\n  \"source\": \"openclaw-workspace\",\n  \"filePath\": \"$FIXTURE/workspace/hooks/ordinary-hook/HOOK.md\",\n  \"baseDir\": \"$FIXTURE/workspace/hooks/ordinary-hook\",\n  \"handlerPath\": \"$FIXTURE/workspace/hooks/ordinary-hook/handler.ts\",\n  \"hookKey\": \"ordinary-hook\",\n  \"events\": [\n    \"command:new\"\n  ],\n  \"unknownEvents\": [],\n  \"always\": false,\n  \"enabledByConfig\": false,\n  \"requirementsSatisfied\": true,\n  \"loadable\": false,\n  \"blockedReason\": \"disabled in config\",\n  \"managedByPlugin\": false,\n  \"requirements\": {\n    \"bins\": [],\n    \"anyBins\": [],\n    \"env\": [],\n    \"config\": [],\n    \"os\": []\n  },\n  \"missing\": {\n    \"bins\": [],\n    \"anyBins\": [],\n    \"env\": [],\n    \"config\": [],\n    \"os\": []\n  },\n  \"configChecks\": [],\n  \"install\": [],\n  \"eligible\": false,\n  \"disabled\": true\n}\n",
      "stderr": "",
      "seconds": 6.461100876000011
    }
  ],
  "observations": [
    {
      "label": "escape-hook-enable",
      "controls": 0,
      "forgedLine": false,
      "escapedLine": true,
      "unicode": true
    },
    {
      "label": "escape-hook-disable",
      "controls": 0,
      "forgedLine": false,
      "escapedLine": true,
      "unicode": true
    },
    {
      "label": "escape-no-emoji-enable",
      "controls": 0,
      "forgedLine": false,
      "escapedLine": true,
      "unicode": true
    },
    {
      "label": "escape-no-emoji-disable",
      "controls": 0,
      "forgedLine": false,
      "escapedLine": true,
      "unicode": true
    }
  ],
  "readback": {
    "escape-hook-enable": {
      "key": "escape-hook",
      "enabled": true,
      "envPreserved": true
    },
    "escape-hook-disable": {
      "key": "escape-hook",
      "enabled": false,
      "envPreserved": true
    },
    "escape-hook-raw": {
      "name": "café\u001b[31m\noperator-forged\tend\rrow\u0007",
      "emoji": "café\u001b[31m\noperator-forged\tend\rrow\u0007",
      "hookKey": "escape-hook",
      "enabledByConfig": false
    },
    "escape-no-emoji-enable": {
      "key": "escape-no-emoji",
      "enabled": true,
      "envPreserved": true
    },
    "escape-no-emoji-disable": {
      "key": "escape-no-emoji",
      "enabled": false,
      "envPreserved": true
    },
    "escape-no-emoji-raw": {
      "name": "café\u001b[31m\noperator-forged\tend\rrow\u0007-plain",
      "emoji": null,
      "hookKey": "escape-no-emoji",
      "enabledByConfig": false
    },
    "ordinary-hook-enable": {
      "key": "ordinary-hook",
      "enabled": true,
      "envPreserved": true
    },
    "ordinary-hook-disable": {
      "key": "ordinary-hook",
      "enabled": false,
      "envPreserved": true
    },
    "ordinary-hook-raw": {
      "name": "ordinary-hook",
      "emoji": null,
      "hookKey": "ordinary-hook",
      "enabledByConfig": false
    },
    "descriptorHashes": [
      "4b79eeae2e7f8070e533aa0f324d40eb3c9cc540f43677f2a14f7eb0722d80b2",
      "13604d6b79e9216e387871fa05d9dd288d728d5d12310e5baf1bf79e2a72bafa",
      "7d75bce1a8281b8921c2894cef81daac85b5b133e2f2adab8eb5e5ef8eb9e7f2"
    ],
    "metadataUnchanged": true,
    "handlerInvocationCount": 0
  },
  "result": "PASS"
}
Replay scripts and validation receipts

Save both scripts together outside the product checkouts. CHECKOUT is the absolute clean checkout of either recorded SHA; PHASE=red for baseline or green for head. Build normally; do not copy dist or modify build stamps.

cd "$CHECKOUT"
pnpm install --frozen-lockfile
node --import ./scripts/tsx.mjs scripts/build-all.mts cliStartup
cd "$HARNESS_DIR"
node proof-hooks.mjs "$CHECKOUT" "$PHASE"

proof-common.mjs:

import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import {createHash} from 'node:crypto';
import {execFileSync, spawn} from 'node:child_process';

export const unusual = 'café\x1b[31m\noperator-forged\tend\rrow\x07';

export function fixture(name) {
 const checkout=path.resolve(process.argv[2]);
 const phase=process.argv[3];
 assert.ok(['red','green'].includes(phase));
 const head=execFileSync('git',['rev-parse','HEAD'],{cwd:checkout,encoding:'utf8'}).trim();
 assert.equal(execFileSync('git',['status','--porcelain'],{cwd:checkout,encoding:'utf8'}).trim(),'');
 const stamp=JSON.parse(fs.readFileSync(path.join(checkout,'dist/.buildstamp')));
 assert.equal(stamp.head,head);
 assert.equal(stamp.inputsClean,true);
 const root=fs.mkdtempSync(path.join(os.tmpdir(),`alix-escape-${name}-`));
 for(const leaf of ['home','state','workspace','tmp'])fs.mkdirSync(path.join(root,leaf));
 const configPath=path.join(root,'openclaw.json');
 const config={agents:{ownership:'explicit',defaults:{systemAgent:{agentId:'main'}},entries:{main:{workspace:path.join(root,'workspace')}}},tools:{profile:'minimal'},plugins:{allow:[],slots:{memory:'none'}},logging:{level:'warn',consoleLevel:'warn',file:path.join(root,'runtime.log')}};
 const writeConfig=()=>fs.writeFileSync(configPath,JSON.stringify(config),{mode:0o600});
 writeConfig();
 const env={PATH:`${path.dirname(process.execPath)}:/usr/bin:/bin`,HOME:path.join(root,'home'),TMPDIR:path.join(root,'tmp'),LANG:'C.UTF-8',TZ:'UTC',TERM:'dumb',NO_COLOR:'1',COLUMNS:'320',CI:'1',DO_NOT_TRACK:'1',OPENCLAW_CONFIG_PATH:configPath,OPENCLAW_STATE_DIR:path.join(root,'state'),OPENCLAW_NO_RESPAWN:'1',OPENCLAW_DISABLE_BONJOUR:'1'};
 const receipt={name,phase,head,at:new Date().toISOString(),root,runs:[],observations:[],readback:{}};
 const save=()=>fs.writeFileSync(path.join(root,'receipt.json'),JSON.stringify(receipt,null,2));
 async function command(label, executable, args, options={}){
  const started=performance.now();
  const row=await new Promise((resolve,reject)=>{
   const child=spawn(executable,args,{cwd:checkout,env:{...env,...options.env},stdio:['ignore','pipe','pipe']});
   let stdout='',stderr='';
   const timer=setTimeout(()=>child.kill('SIGKILL'),90000);
   child.stdout.setEncoding('utf8').on('data',x=>{stdout+=x;});
   child.stderr.setEncoding('utf8').on('data',x=>{stderr+=x;});
   child.on('error',reject);
   child.on('close',(code,signal)=>{clearTimeout(timer);resolve({label,args,code,signal,stdout,stderr,seconds:(performance.now()-started)/1000});});
  });
  receipt.runs.push(row);save();
  assert.equal(row.signal,null,`${label}: setup/timeout is not product RED`);
  assert.equal(row.code,options.exit??0,`${label}: ${row.stderr}`);
  return row;
 }
 const run=async(label,args,options)=>command(label,process.execPath,[path.join(checkout,'openclaw.mjs'),...args],options);
 function text(label,output,options={}){
  const controls=[...output.matchAll(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g)].length;
  const forgedLine=output.includes('\noperator-forged');
  const observation={label,controls,forgedLine,escapedLine:output.includes('\\noperator-forged'),unicode:output.includes('café')};
  receipt.observations.push(observation);save();
  assert.equal(controls>0,phase==='red',`${label}: control result`);
  if(!options.table)assert.equal(forgedLine,phase==='red',`${label}: injected report row`);
  assert.equal(observation.unicode,true,`${label}: Unicode control`);
  if(phase==='green')assert.equal(observation.escapedLine,true,`${label}: retain visible escaped line`);
 }
 function finish(){receipt.result='PASS';save();console.log(JSON.stringify({name,phase,head,result:'PASS',receipt:path.join(root,'receipt.json'),observations:receipt.observations,readback:receipt.readback}));}
 return {checkout,root,configPath,config,writeConfig,env,receipt,run,command,text,save,finish,hash:bytes=>createHash('sha256').update(bytes).digest('hex')};
}

proof-hooks.mjs:

import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import net from 'node:net';
import {fixture,unusual} from './proof-common.mjs';
const f=fixture('hooks');
const server=net.createServer();await new Promise(resolve=>server.listen(0,'127.0.0.1',resolve));
const port=server.address().port;await new Promise(resolve=>server.close(resolve));
f.config.gateway={mode:'local',port};
const cases=[{key:'escape-hook',name:unusual,emoji:unusual},{key:'escape-no-emoji',name:unusual+'-plain'},{key:'ordinary-hook',name:'ordinary-hook'}];
const marker=path.join(f.root,'handler-invoked');
f.config.hooks={internal:{enabled:true,entries:{}}};
const metadata=[];
for(const item of cases){
 const dir=path.join(f.root,'workspace','hooks',item.key);fs.mkdirSync(dir,{recursive:true});
 const file=path.join(dir,'HOOK.md');
 const descriptor={openclaw:{events:['command:new'],hookKey:item.key,...(item.emoji?{emoji:item.emoji}:{})}};
 fs.writeFileSync(file,'---\nname: '+JSON.stringify(item.name)+'\ndescription: Toggle an isolated synthetic hook without invoking its handler.\nmetadata: '+JSON.stringify(descriptor)+'\n---\n\nFixture hook.\n');
 fs.writeFileSync(path.join(dir,'handler.ts'),'import fs from "node:fs";\nexport default async function handle() { fs.writeFileSync('+JSON.stringify(marker)+', "invoked"); }\n');
 metadata.push({file,hash:f.hash(fs.readFileSync(file))});
 f.config.hooks.internal.entries[item.key]={env:{PROOF_SENTINEL:'preserved'}};
}
f.writeConfig();
for(const item of cases){
 for(const action of ['enable','disable']){
  const row=await f.run(item.key+'-'+action,['hooks',action,item.key,'--agent','main']);
  const output=row.stdout+row.stderr;
  assert.ok(output.includes(action==='enable'?'Enabled hook:':'Disabled hook:'));
  if(item.key.startsWith('escape-'))f.text(item.key+'-'+action,output);
  else{assert.ok(output.includes('ordinary-hook'));assert.doesNotMatch(output,/[\x00-\x08\x0b-\x1f\x7f-\x9f]/);}
  const config=JSON.parse(fs.readFileSync(f.configPath,'utf8'));
  assert.equal(config.hooks.internal.entries[item.key].enabled,action==='enable');
  assert.equal(config.hooks.internal.entries[item.key].env.PROOF_SENTINEL,'preserved');
  f.receipt.readback[item.key+'-'+action]={key:item.key,enabled:config.hooks.internal.entries[item.key].enabled,envPreserved:true};
 }
 const result=await f.run(item.key+'-json',['hooks','info',item.key,'--agent','main','--json']);
 const info=JSON.parse(result.stdout);assert.equal(info.name,item.name);assert.equal(info.emoji,item.emoji);assert.equal(info.hookKey,item.key);assert.equal(info.enabledByConfig,false);
 f.receipt.readback[item.key+'-raw']={name:info.name,emoji:info.emoji??null,hookKey:info.hookKey,enabledByConfig:info.enabledByConfig};
}
for(const source of metadata)assert.equal(f.hash(fs.readFileSync(source.file)),source.hash);
assert.equal(fs.existsSync(marker),false);
f.receipt.readback.descriptorHashes=metadata.map(x=>x.hash);f.receipt.readback.metadataUnchanged=true;f.receipt.readback.handlerInvocationCount=0;
f.finish();

Frozen source hashes and measured validation receipts:

{
  "sourceReview": {
    "verdict": "pass",
    "findings": [],
    "base": "f4ae32fe1b035ce86561887e897d75c13557adbc",
    "scope": "Independent P0-P3 adversarial source review of complete frozen hooks diff, complete hooks-cli owner and toggle tests, report/selection/commit/acknowledgment flow and neighboring refusal/JSON contracts, terminal-core safe-text/decorative helpers, docs, TASK competition analysis and real normal-built CLI baseline proof scripts/receipts. Reused unchanged contribution/testing/test-audit instructions from prior batch as documented in TASK. No product edits, builds/tests, auth attempts or external actions by reviewer.",
    "sha256": {
      "src/cli/hooks-cli.ts": "04f5505ca10fd503f2b0ffaf970576c2b7fa2ab7ef8ca367af45fef545cad137",
      "src/cli/hooks-cli.toggle.test.ts": "858f0cfbf88519e78ae7787567196bd5da29584ee5c6bd1984059bcc6a6ffcb5",
      "docs/cli/hooks.md": "7e22b762570a070862a13807de2d9c5b13a30dd142b20d8e8598a404fa7a5afe"
    }
  },
  "hashes": {
    "src/cli/hooks-cli.ts": "04f5505ca10fd503f2b0ffaf970576c2b7fa2ab7ef8ca367af45fef545cad137",
    "src/cli/hooks-cli.toggle.test.ts": "858f0cfbf88519e78ae7787567196bd5da29584ee5c6bd1984059bcc6a6ffcb5",
    "docs/cli/hooks.md": "7e22b762570a070862a13807de2d9c5b13a30dd142b20d8e8598a404fa7a5afe"
  },
  "focusedCheck": {
    "command": "pnpm test src/cli/hooks-cli.toggle.test.ts --maxWorkers=1",
    "tests": "Tests  25 passed (25)",
    "seconds": 24.03,
    "exit": 0
  },
  "gates": {
    "format-check": {
      "command": "node-or-pnpm --import ./scripts/tsx.mjs scripts/run-format.mts --check src/cli/hooks-cli.ts src/cli/hooks-cli.toggle.test.ts docs/cli/hooks.md",
      "seconds": 0.494,
      "exit": 0
    },
    "lint": {
      "command": "node-or-pnpm scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/cli/hooks-cli.ts src/cli/hooks-cli.toggle.test.ts",
      "seconds": 28.754,
      "exit": 0
    },
    "types": {
      "command": "node-or-pnpm scripts/run-tsgo.mjs -p $BATCH/hooks.tsconfig.json",
      "seconds": 102.028,
      "exit": 0
    },
    "build": {
      "command": "node-or-pnpm --import ./scripts/tsx.mjs scripts/build-all.mts cliStartup",
      "seconds": 302.137,
      "exit": 0
    }
  }
}
status: PASS
product_sha: 2633b012684f8ba8dee340d1559f1d55ef2cb166
base_sha: f4ae32fe1b035ce86561887e897d75c13557adbc
claims: C1=Successful hook enable/disable acknowledgements safely render names and custom emoji without changing raw metadata or config-key writes.
covered_by: C1=Same normally built CLI scenario before/after, captured streams and independent actual-state readback below.
entry: hooks enable / hooks disable through normal built openclaw.mjs
owner: src/cli/hooks-cli.ts executed unmocked
boundary: subprocess,disk
readback: Normal-built CLI discovers three actual workspace hooks from HOOK.md, commits enable/disable config changes, then prints the acknowledgement. Separate hooks info --json processes return original metadata; direct config and descriptor hash readback verifies exact keys, preserved env fields and unchanged source files.
proof_command: node proof-hooks.mjs "$CHECKOUT" "$PHASE"
harness: proof-common.mjs sha256=8a6d2e48b1b076878e98641b0791f7fb064f44bbff9522fe43d1d34c6ffb007f; proof-hooks.mjs sha256=0c27781d6201b121bd900ee67029ece46d3f4ac929d86bdc61ed0721c4598c75
before: RED escape-hook-enable: controls=6, forgedRow=true, escapedNewline=false; escape-hook-disable: controls=6, forgedRow=true, escapedNewline=false; escape-no-emoji-enable: controls=3, forgedRow=true, escapedNewline=false; escape-no-emoji-disable: controls=3, forgedRow=true, escapedNewline=false
after: GREEN escape-hook-enable: controls=0, forgedRow=false, escapedNewline=true; escape-hook-disable: controls=0, forgedRow=false, escapedNewline=true; escape-no-emoji-enable: controls=0, forgedRow=false, escapedNewline=true; escape-no-emoji-disable: controls=0, forgedRow=false, escapedNewline=true
negative_claim: yes
control: Authoritative captured CLI control counts: baseline [6,6,3,3], head [0,0,0,0]. Ordinary same-entry command controls succeed with exit0; independent original-value JSON/disk checks pass. Both actions, with and without custom emoji, succeed with correct persisted enabled bits. The ordinary hook succeeds unchanged. All six commands preserve per-hook env metadata; all descriptors remain byte-identical. A marker-capable synthetic handler has zero invocations. Unicode retained; GREEN acknowledgements contain no embedded action controls or forged rows.
consumers: Affected human output owner and raw JSON/readback siblings inspected. Existing terminal-core sanitizer reused; no new input validation, storage, backend policy or protocol.
tests: pnpm test src/cli/hooks-cli.toggle.test.ts --maxWorkers=1 => Tests  25 passed (25); exit 0
tests_changed: yes
test_cost: 24.03 seconds measured command wall time, including native wrapper/worker preparation and artifact verification; not just assertion duration. The first cold run took 136.252s and hit the existing Gateway-owner refusal case's 120s timeout; worker preparation alone took108.437s, and24 other cases passed. The unmodified full-file rerun passed all25 in 24.03s using retained compiler outputs; no test, timeout or assertion was changed.
visual: no
screenshots: N/A: CLI text only; inspectable JSON-escaped streams below
published: pr-body
not_tested: Isolated Linux local config and workspace hooks only. This tests toggling and rendering, not dispatching a hook event or reloading a live Gateway. No production service/channel, remote report, error-diagnostic, Windows/macOS or whole CI claim. Upstream required CI has not run before PR creation.
reuse: Focused tests/static checks ran before commit against exactly the reviewed manifest bytes; hashes verified before commit. GREEN uses a fresh normal build of the exact clean committed product head. No prior-head CI reused.

@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.

@Alix-007
Alix-007 marked this pull request as ready for review October 26, 2026 06:41
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes size: XS labels Oct 26, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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

This PR sanitizes hook names and custom emoji before printing enable and disable confirmations.

Example: Run openclaw hooks enable escape-hook for a hook named café followed by a newline and operator-forged.

  • Before: The confirmation prints operator-forged on a separate terminal line.
  • After: The confirmation displays café\noperator-forged on one line while preserving the original metadata.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A narrow, useful rendering repair with supplied shipped-entry-point proof, preserved data semantics, green exact-head gates, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Supplied captured output exercises the normally built openclaw.mjs hooks enable and disable commands on pinned base and head in isolated Linux state, with real descriptor discovery and config writes; injected controls disappear in both emoji branches, while JSON and disk readback preserve original metadata, keys, and environment fields.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A hook's name or custom emoji can execute terminal controls or forge extra confirmation lines after a successful toggle.
Reason: The repair extends the established terminal-output contract to a demonstrably exposed confirmation path without adding policy, options, or state.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: current main still exposes terminal controls in successful hook toggle confirmations, and this focused fix has no actionable introduced defects.

Priority: P2
Reviewed head: 2633b012684f8ba8dee340d1559f1d55ef2cb166

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No changed-path end-to-end gap remains; a failing-base run of the added automated test is not supplied, although the built-CLI baseline demonstrates the defect.
Agent review details

How this fits together

The hooks CLI discovers hook metadata, commits enablement through the existing config owner, and renders the committed result as a terminal confirmation.

flowchart LR
  A[Hook descriptors] --> B[Hook discovery and selection]
  B --> C[Config mutation owner]
  C --> D[Committed hook metadata]
  D --> E[Terminal text sanitizer]
  E --> F[Trusted styling and confirmation]
Loading

Technical review

Best possible solution:

Land the existing sanitizer calls at the confirmation boundary while preserving raw metadata and config mutation semantics.

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

Current-main interpolation directly explains the supplied failing-base built-CLI traces; this read-only review executed no target code.

Is this the best way to solve the issue?

The patch is the smallest complete fix: it reuses the established sanitizer in the existing output owner and adds focused coverage for both commands and emoji branches.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Hook toggle confirmation rendering changes intended behavior with a stated reason (1fb7766: This refactor localized existing single-consumer preparation and output without intended user-visible changes; the underlying raw rendering predates that move.)
  • Existing terminal-safe hook report convention keeps the original intent (fix(cli): prevent descriptor controls in skill and hook reports #172872: Neutralize descriptor controls before trusted styling while preserving original hook metadata and JSON values.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Pinned introduced fix: Both confirmation branches sanitize the hook name, and the custom-emoji branch also sanitizes emoji before styling; mutation and selection logic are unchanged. (src/cli/hooks-cli.ts:554, 2633b012684f)
  • Current main still needs the repair: Fetched main directly interpolates selectedHook.emoji and selectedHook.name into successful toggle confirmations. (src/cli/hooks-cli.ts:554, bb3df792e23f)
  • Existing sanitizer contract: The reused terminal-core owner strips ANSI sequences and other control characters while visibly escaping carriage returns, newlines, and tabs. (packages/terminal-core/src/safe-text.ts:11, 2633b012684f)
  • Supplied shipped CLI proof: The full PR body supplies replay scripts and captured built-CLI output on pinned base and head: enable and disable, with and without custom emoji, lose injected controls and forged rows; independent JSON, config, and descriptor readback preserves original values. Captured body identity: SHA-256 5b9134454a9451f9f5b599a832cec22e0cbd666e2c90cd215a9712cea17f533c. (2633b012684f)
  • Earlier repair covers a different surface: fix(cli): prevent descriptor controls in skill and hook reports #172872 merged the read-only skill and hook report repair; its scope and current source leave successful toggle acknowledgements uncovered. The author of fix(hooks): stop executing escape sequences from hook manifest metadata #175978 credits that broader report repair when closing their overlapping branch. (src/cli/hooks-cli.ts:151, 1d4ef25a2993)
  • Ownership and provenance: History across current and retired hook CLI helpers identifies Peter Steinberger's repeated ownership refactors and Alix-007's merged terminal-rendering repair. The recent localization moved existing confirmation behavior without intending a user-visible change; it does not establish the original introduction. A deeper content-history search encountered an unavailable promisor blob, while current source and relevant refactor hunks remained readable. (src/cli/hooks-cli.ts:550, 1fb7766685a5)

Likely related people:

  • Peter Steinberger: Raw commit 1fb7766 adds src/cli/hooks-cli.ts:538 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1fb7766685a5; files: src/cli/hooks-cli.ts)
  • Alix-007: Raw commit 1d4ef25 adds src/cli/hooks-cli.ts:151 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1d4ef25a2993; files: src/cli/hooks-cli.ts)

PR surface

Source 0, Tests +32, Docs +4. Total +36 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 2 2 0
Tests 1 32 0 +32
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 38 2 +36

Labels

Label changes:

  • add P2: Descriptor-controlled bytes can manipulate terminal output during hook toggles; the demonstrated impact is confined to CLI confirmations.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Descriptor-controlled bytes can manipulate terminal output during hook toggles; the demonstrated impact is confined to CLI confirmations.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • 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, 2:55 AM ET / 06:55 UTC.

obviyus added a commit that referenced this pull request Oct 27, 2026
fix(cli): escape terminal controls in untrusted values through one owner

CLI human-readable output printed user-controlled values such as config paths, names, directories, binding descriptions, plugin metadata and dead-letter scopes without neutralizing terminal control sequences, so a crafted value could inject ANSI, OSC 8 or C1 sequences into the terminal. Earlier fixes wrapped one call site at a time. A single owner now does this: `terminalText` in terminal-core's safe-text escapes interpolated values before styling, and the display-only `displayPath` delegates to it. Raw path shortening, JSON output and the trusted styling of `renderTable` are unchanged, and the per-site wrapping is replaced.

This absorbs #184685, #184666, #184324, #184303, #176763, #176773 and #172873 by @Alix-007 and #184861 by @qingminglong, whose original commits are kept, and moves the earlier merged per-site fixes onto the same owner.

Evidence: built CLI in a secretless container, with ESC/CSI, OSC 8 and C1 sequences injected into values for eleven commands across eight families. Main printed the raw sequences; this change printed them neutralized, normal colored output and JSON values were unchanged, and dead-letter errors keep their stderr and JSON contracts. Raw-byte captures: #185927 (comment). Production +81.

Co-authored-by: Alix-007 <[email protected]>
Co-authored-by: qingminlong <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Thanks @Alix-007. This is now fixed at the root in #185927 (2d2b465): one terminalText owner in terminal-core's safe-text escapes untrusted values for all CLI human output, replacing the per-site wrapping. Your commit from this PR is kept in that merge and you're credited as co-author, so I'm closing this one as covered. For future output sites, please route values through terminalText (or displayPath for paths) instead of opening a PR per call site.

@obviyus obviyus closed this Oct 27, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
fix(cli): escape terminal controls in untrusted values through one owner

CLI human-readable output printed user-controlled values such as config paths, names, directories, binding descriptions, plugin metadata and dead-letter scopes without neutralizing terminal control sequences, so a crafted value could inject ANSI, OSC 8 or C1 sequences into the terminal. Earlier fixes wrapped one call site at a time. A single owner now does this: `terminalText` in terminal-core's safe-text escapes interpolated values before styling, and the display-only `displayPath` delegates to it. Raw path shortening, JSON output and the trusted styling of `renderTable` are unchanged, and the per-site wrapping is replaced.

This absorbs openclaw#184685, openclaw#184666, openclaw#184324, openclaw#184303, openclaw#176763, openclaw#176773 and openclaw#172873 by @Alix-007 and openclaw#184861 by @qingminglong, whose original commits are kept, and moves the earlier merged per-site fixes onto the same owner.

Evidence: built CLI in a secretless container, with ESC/CSI, OSC 8 and C1 sequences injected into values for eleven commands across eight families. Main printed the raw sequences; this change printed them neutralized, normal colored output and JSON values were unchanged, and dead-letter errors keep their stderr and JSON contracts. Raw-byte captures: openclaw#185927 (comment). Production +81.

Co-authored-by: Alix-007 <[email protected]>
Co-authored-by: qingminlong <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
@Alix-007

Copy link
Copy Markdown
Contributor Author

Thanks @obviyus for the shared fix and the clear guidance!

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

Labels

cli CLI command changes docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS 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