Repository navigation
fix(infra): prevent $-pattern injection in home directory tilde expansion - #122991
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs real behavior proof before merge. Reviewed August 23, 2026, 6:40 PM ET / 22:40 UTC. ClawSweeper reviewWhat this changesThe PR makes tilde expansion preserve literal dollar sequences in core home resolution, daemon state paths, launcher config lookup, and Control UI local-media preview checks, with regression tests. Merge readiness⛔ Blocked until real behavior proof from a real setup is added - 4 items remain Keep open: current main still uses string replacement values at all four affected owners, while the PR’s callback form correctly preserves literal dollar sequences. The patch has no concrete correctness finding, but this external PR still needs real-behavior proof and a rebase/green exact-head CI refresh before merge. Priority: P2 Review scores
Verification
Live VerificationCommand: Result: FAIL (partial) — step 2 Assertions:
How this fits togetherOpenClaw expands home-relative inputs before resolving config and state locations, deciding launcher help behavior, and authorizing local-media previews. Those expanded paths then control which files are read and whether the UI can fetch an attachment. flowchart LR
A[Environment or path input] --> B[Home directory lookup]
B --> C[Tilde expansion]
C --> D[Core config and state paths]
C --> E[Daemon state directory]
C --> F[Launcher config lookup]
C --> G[Control UI media policy]
D --> H[Runtime behavior]
E --> H
F --> H
G --> H
Before merge
Agent review detailsSecurityNone. PR surfaceSource +3, Tests +147, Other 0. Total +150 across 10 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the callback substitutions as the single canonical literal-expansion behavior, then attach a redacted after-fix launcher or built Control UI/Gateway trace and merge only after a clean rebase with green exact-head checks. Do we have a high-confidence way to reproduce the issue? Yes. Current main contains string replacement values at the affected tilde boundaries, and the direct Node reproduction changes Is this the best way to solve the issue? Yes. Returning the home path from the replacement callback fixes the producer-side language behavior without changing tilde matching, configuration shape, or downstream consumers. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 78826458e384. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
94c8a1f to
8b0fefb
Compare
8b0fefb to
8bc419b
Compare
…sions String.replace interprets dollar-amp/dollar-1/dollar-backtick in the replacement string. Eight call sites across extensions and memory-host-sdk expanded ~ using .replace(/^~/, homeVariable), which corrupts the path when the home directory contains these sequences. Switch each to a function replacement (() => homeVariable) so the home path is treated literally. Same fix as the core home-dir resolver (PR openclaw#122991) and terminal-core/display-string (openclaw#111398). Affected: voice-call utils + doctor, browser config, migrate-claude, migrate-hermes, memory-lancedb doctor, memory-host-sdk config-utils.
String.replace interprets dollar-amp/dollar-1/dollar-backtick in the replacement string. When the home directory contains these sequences (e.g. a username with a dollar sign), tilde expansion via .replace(/^~/, fallbackHome) corrupts the path silently. Use a function replacement so the home path is treated literally, matching the pattern already fixed in terminal-core/display-string (openclaw#111398). Two call sites: resolveRawHomeDir and expandHomePrefix.
…nsion Address review rank-up: the daemon state-path expansion deliberately does not use the core helper and still passed home as a string replacement. Apply the callback form here too and add a literal-dollar regression to the existing service-env suite (fails on the string form, passes with the callback).
8bc419b to
31c7546
Compare
…#123004) * fix: prevent dollar-pattern injection in tilde expansion across extensions String.replace interprets dollar-amp/dollar-1/dollar-backtick in the replacement string. Eight call sites across extensions and memory-host-sdk expanded ~ using .replace(/^~/, homeVariable), which corrupts the path when the home directory contains these sequences. Switch each to a function replacement (() => homeVariable) so the home path is treated literally. Same fix as the core home-dir resolver (PR #122991) and terminal-core/display-string (#111398). Affected: voice-call utils + doctor, browser config, migrate-claude, migrate-hermes, memory-lancedb doctor, memory-host-sdk config-utils. * fix: cover iMessage and 1Password tilde expansion owners Address review: iMessage CLI path expansion and both 1Password state-path expansions (OPENCLAW_HOME and OPENCLAW_STATE_DIR) also passed resolved home as a string replacement. Apply the callback form so a literal-dollar home path is preserved. * test(voice-call): add literal-dollar tilde expansion regression Address review rank-up: mock os.homedir to a literal-dollar path and assert the resolved path preserves dollar-amp verbatim (fails on the string replacement form, passes with the callback). * test(extensions): cover literal-dollar tilde expansion at every changed owner * test(onepassword): cover tilde OPENCLAW_HOME literal-dollar expansion
Resolve the existing unrelated hovercard CI failure and align the contributor branch with the current markdown-it contract while preserving all original contributor commits. Co-authored-by: liyuanbin <[email protected]>
…ntract Preserve the current authenticated metadata and ticket-scoped download behavior while exercising the real Chromium Control UI under a literal-dollar home. Co-authored-by: liyuanbin <[email protected]>
|
Maintainer real-behavior and current-main integration proof for final head
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
…openclaw#123004) * fix: prevent dollar-pattern injection in tilde expansion across extensions String.replace interprets dollar-amp/dollar-1/dollar-backtick in the replacement string. Eight call sites across extensions and memory-host-sdk expanded ~ using .replace(/^~/, homeVariable), which corrupts the path when the home directory contains these sequences. Switch each to a function replacement (() => homeVariable) so the home path is treated literally. Same fix as the core home-dir resolver (PR openclaw#122991) and terminal-core/display-string (openclaw#111398). Affected: voice-call utils + doctor, browser config, migrate-claude, migrate-hermes, memory-lancedb doctor, memory-host-sdk config-utils. * fix: cover iMessage and 1Password tilde expansion owners Address review: iMessage CLI path expansion and both 1Password state-path expansions (OPENCLAW_HOME and OPENCLAW_STATE_DIR) also passed resolved home as a string replacement. Apply the callback form so a literal-dollar home path is preserved. * test(voice-call): add literal-dollar tilde expansion regression Address review rank-up: mock os.homedir to a literal-dollar path and assert the resolved path preserves dollar-amp verbatim (fails on the string replacement form, passes with the callback). * test(extensions): cover literal-dollar tilde expansion at every changed owner * test(onepassword): cover tilde OPENCLAW_HOME literal-dollar expansion
…sion (openclaw#122991) * fix(infra): prevent dollar-pattern injection in home dir tilde expansion String.replace interprets dollar-amp/dollar-1/dollar-backtick in the replacement string. When the home directory contains these sequences (e.g. a username with a dollar sign), tilde expansion via .replace(/^~/, fallbackHome) corrupts the path silently. Use a function replacement so the home path is treated literally, matching the pattern already fixed in terminal-core/display-string (openclaw#111398). Two call sites: resolveRawHomeDir and expandHomePrefix. * fix(daemon): prevent dollar-pattern injection in state dir tilde expansion Address review rank-up: the daemon state-path expansion deliberately does not use the core helper and still passed home as a string replacement. Apply the callback form here too and add a literal-dollar regression to the existing service-env suite (fails on the string form, passes with the callback). * fix(launcher): keep literal $ patterns when expanding tilde OPENCLAW_HOME * fix(ui): keep literal $ patterns in local media tilde expansion * test(ui): prove literal-$ tilde local media preview through Control UI e2e * test(ui): align literal-dollar media proof with compact attachment contract Preserve the current authenticated metadata and ticket-scoped download behavior while exercising the real Chromium Control UI under a literal-dollar home. Co-authored-by: liyuanbin <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
src/infra/home-dir.tsandsrc/daemon/paths.tsexpand leading~/~//~\usingString.prototype.replace(regex, replacement). When the replacement string (the resolved home directory) contains$&,$1–$9,$`, or$', JavaScript interprets these as special replacement patterns — silently corrupting the path. For example, withHOME=/home/$&user, expanding~/stateyields/home/~user/stateinstead of/home/$&user/state(the$&becomes the entire match~).Same bug class already fixed in
packages/terminal-core/src/display-string.ts(#111398). That fix covered the terminal display path but left the core home-dir resolver (resolveRawHomeDir+expandHomePrefix— the two paths every OpenClaw module uses for home-relative config/state/credential paths), the independent daemon state-dir resolver, and the published launcher (openclaw.mjs, theopenclawbinary) unguarded.Why This Change Was Made
String.replace(regex, () => value)treats the return value literally. The fix switches all five call sites (resolveRawHomeDir,expandHomePrefix, daemonresolveGatewayStateDir's tilde branch, launcherresolveLauncherHomeDir's tilde branch, Control UIisLocalAttachmentPreviewAllowed's tilde-source expansion) from the string form to the function form — minimal, established pattern, zero behavioral change for normal (non-$) home paths.User Impact
When a user's home directory (or
OPENCLAW_HOME) contains$characters — e.g. a CI runner, a test harness, or a username with special characters — OpenClaw silently resolves config, state, and credential paths (and the managed-service daemon'sOPENCLAW_STATE_DIR) to the wrong location. This can cause missing config, lost state, or credentials not found, with no error indicating the path was mangled. The launcher variant additionally makesopenclaw --helpread configuration candidates at the wrong path, so a configured plugin slot is missed and precomputed help is served instead of the runtime entry. The Control UI variant expands~/...attachment sources against home candidates inferred fromlocalMediaPreviewRoots; a$-containing home corrupts the comparison and the preview is denied with "Outside allowed folders".Evidence
Reproduction (node 26.5.0; CI Node 24 has identical replace semantics):
Owner-boundary regressions (all red-green verified — fail with the old string form, pass with the callback):
src/infra/home-dir.test.ts: 2 new cases —$&in HOME forresolveEffectiveHomeDir(OPENCLAW_HOME~/statepath) and$&in home forexpandHomePrefix.src/daemon/service-env.test.ts: 1 new case —$&in HOME when expanding~inOPENCLAW_STATE_DIR.ui/src/pages/chat/components/chat-message-local-media.test.ts: 1 new case —isLocalAttachmentPreviewAllowed("~/media/report.png", ["/home/us$&r/media"])must allow the preview (red pre-fix:expected false to be true); a non-matching root still denies.test/openclaw-launcher.e2e.test.ts: 1 new case — spawns the realopenclaw.mjswithHOME=<fixture>/home$&dandOPENCLAW_HOME=~/oc; a config with a plugin slot exists at the literal-$path. Post-fix the launcher defers to the runtime entry (RUNTIME ENTRY); pre-fix it served precomputed help.Red example (pre-fix run):
AssertionError: expected '/home/~user/openclaw-state' to be '/home/$&user/openclaw-state'.Launcher red example (pre-fix run):
AssertionError: expected 'PRECOMPUTED memory help\n' to be 'RUNTIME ENTRY\n'— the$&-corrupted home made the launcher miss the config and serve precomputed help.Tests (rebased onto latest
mainincl. the node-host/runtime changes, exact heade29765fd28a):node scripts/run-vitest.mjs src/infra/home-dir.test.ts→ 31 passednode scripts/run-vitest.mjs src/daemon/service-env.test.ts→ 83 passednode scripts/run-vitest.mjs test/openclaw-launcher.e2e.test.ts→ 38 passed | 1 skippednode scripts/run-vitest.mjs ui/src/pages/chat/components/chat-message-local-media.test.ts→ 1 passed (red pre-fix)node scripts/run-vitest.mjs ui/src/pages/chat/components/chat-message.test.ts→ 185 passed (incl. new literal-$case; new case also verified failing pre-fix via-t literal)node scripts/run-vitest.mjs packages/memory-host-sdk/src/host/config-utils.test.ts→ passed (memory-host owner covered in companion PR fix: prevent $-pattern injection in tilde expansion across extensions #123004)git diff --check→ cleanCI attribution (exact head
e29765fd28a)checks-ui-e2e (2/12)failed atsession-management.sidebar.e2e.test.ts > expands and manages child sessions inline before opening a child chat--TimeoutError: locator.click: Timeout 30000ms exceeded. That file is untouched by this diff, the same shard was green on the previous head (9f5e7e67, 259 checks 0 failing), and this head's newchat-flow.local-media-dollar-home.e2e.test.tspassed in its shard (checks-ui-e2e (5/12), pass 1.3s). Runner/flaky-specific; no code change included.openclaw/ci-gateis the aggregate of that shard.Production LOC: net 0 (5 lines changed in 5 files: home-dir ×2, daemon ×1, launcher ×1, Control UI ×1). Test LOC: +85.