Repository navigation
fix(agents): preserve whitespace in node-host exec workdir paths - #172814
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs changes before merge. What this changesThis PR preserves working-directory whitespace through node execution, executable lookup, approval plans, and reusable grants. Example: A node command targets
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: it fixes a current working-directory identity bug, with no actionable correctness findings; the enforced security review remains pending. Priority: P2 Before merge
FindingsNone. Agent review detailsHow this fits togetherThe exec tool forwards a working directory through Gateway approval recording and replay to the node host, which resolves executables, validates current authorization, and launches the process. flowchart LR
A[Exec tool] --> B[Gateway approval owner]
B --> C[Stored execution plan]
C --> D[Node host]
D --> E[Executable and grant resolution]
E --> F[Final authorization check]
F --> G[Process spawn]
Technical reviewBest possible solution: Preserve literal cwd identity through the existing execution and approval owners while retaining current directory-binding and final authorization checks. Do we have a high-confidence way to reproduce the issue? Current-main source visibly trims cwd before node planning and execution; the contributor also supplies before/after Gateway results, which were inspected without executing target code. Is this the best way to solve the issue? The patch uses the existing string reader and approval owners to preserve one directory identity across the affected boundaries without adding another policy or storage mechanism. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 01fe067c9d17. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +22, Tests +222. Total +244 across 16 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (25 earlier review cycles; latest 8 shown)
Reviewed October 20, 2026, 3:01 AM ET / 07:01 UTC (Revision 26). |
774a6c1 to
08c56d4
Compare
|
🦞👀 Re-review progress:
|
1bb2809 to
7afa927
Compare
✅ Maintainer security changes approvedA maintainer approved this revision with an explicit security approval comment.
A later push requires a fresh approval comment for an external contributor's PR. |
7afa927 to
6caebdb
Compare
|
🦞👀 Re-review progress:
|
a892552 to
2fbaead
Compare
|
🦞👀 Re-review progress:
|
2fbaead to
b0ed11f
Compare
|
🦞👀 Re-review progress:
|
b0ed11f to
50f4f98
Compare
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
Rebuild of PR openclaw#172814 onto latest main. Preserve whitespace in node-host exec workdir cwd values by reading non-blank strings instead of trimming via normalizeOptionalString. Covers exec-workdir resolution, system.run approval planning, and invoke matching. Whitespace tests moved to a sibling isolated test file to keep the grandfathered approval-plan test under its line cap.
22ca500 to
6f26987
Compare
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
/allow-security-sensitive-change |
What Problem This Solves
Running a
system.runcommand on a node host with aworkdirwhose name legitimately ends in whitespace (e.g./srv/data) silently executed the command in a different directory (/srv/data).normalizeXxxStringcalls that trim whitespace. The plan normalizer, approval binding/context resolvers,resolveExecutablePathCandidate, andcollectAllowAlwaysPatternsall re-trimmed cwd, so a preserved-whitespace value was trimmed before reachingchild_process.spawn'soptions.cwd, and the plan-match check broke.readNonBlankString(preserves whitespace, rejects blank). Files:bash-tools.exec-workdir.ts,invoke-system-run-plan.ts,invoke-system-run.ts,system-run-approval-plan.ts,system-run-approval-binding.ts,system-run-approval-context.ts,system-run-normalize.ts,executable-path.ts,exec-approvals-allowlist.ts.Why This Change Was Made
Fixing only the cwd read sites was cancelled out by downstream trimming.
resolveExecutablePathCandidatetrimmed cwd before pinning./tool.collectAllowAlwaysPatternstrimmed cwd for grant hashing, scoping persisted authorization to the wrong directory — a security concern where approval for/srv/datacould authorize/srv/dataor vice versa.User Impact
Commands on a node host whose working directory name contains leading or trailing whitespace now execute in the intended directory. Relative executables resolve correctly. Approval bindings and reusable grants distinguish whitespace-distinct paths, preventing cross-directory approval reuse. Non-whitespace paths are unaffected.
Evidence
Gateway-level proof (running Gateway kernel + real
child_process.spawn)dataallowlist miss❌ok: true, stdout:from-space-dir✅data, launchdata)ok: true❌ (cross-dir)allowlist miss✅miss❌ok: true→allowlist miss✅ok: true❌approval requires matching plan✅RED on main: all 5 fail. GREEN after fix: all 5 pass.
Cancelled approval replayed through node.invoke (terminal output)
A previously allowed, unconsumed approval is cancelled via
forceDenyDetailed(cancelled), then replayed through the productionnode.invoke(system.run)guard (sanitizeSystemRunParamsForForwarding);consumeAllowOncereturns false, no process spawns.Recorded-approval revocation + sibling-redirection (running Gateway)
Data-model compatibility (v2026.10.5 → candidate)
Swapped stable v2026.10.5 (1b58cb9) → candidate (this PR, 6f26987) on the same SQLite state; candidate runs its normal
doctor --fixcredential migration, then loads the same store.Regression tests
Follow-up validation (
18f2d02ba690)The shell-script argument-boundary lookup now preserves cwd too. The existing regression now exercises production grant creation and matching: relative/absolute replay succeeds, changed arguments are rejected, and the whitespace-distinct sibling cwd cannot reuse the grant.
pnpm test src/infra/exec-approvals-allow-always.test.ts --maxWorkers=1: 44 passed, 28.00 s wall time including compiler preparation; the regression itself took 5 ms.git diff --checkpassed. Fresh AutoReview found no P0/P1 issues in the follow-up delta.gateway-roothas 726 roots andplugins-platformhas 727, above 720. This follow-up changes no test roots, imports, typegraph configuration, or budget tooling.