Repository navigation
fix: route path containment through one canonical spelling owner - #195061
Conversation
Containment checks across media, sandbox, plugins, config includes, hooks, and uninstall cleanup each canonicalized roots and candidates their own way (realpath-or-lexical, existing ancestor with lexical '..' folding, plain path.resolve). Under a symlinked prefix the two sides of a comparison disagreed. src/infra/path-containment.ts now owns that spelling: one walk (sync and async) over native realpath(3) that never folds '..' lexically, follows dangling links to the location they name, and reports unreadable or looping prefixes instead of guessing. Callers compare canonical root against canonical candidate, or re-spell a candidate under the caller's root spelling. Fixed through it: - openclaw uninstall --state dropped an aliased workspace from the keep list and deleted it. - A plugin reinstall recorded under another spelling of the same directory deleted the directory it had just installed. - Hook transforms accepted an in-root dangling link to an outside module. - Aliased absolute includes, managed media, tmp media, and exec workdirs were refused; npm uninstall cleanup skipped aliased roots. - Local media: an in-root broken link is named in the not-found error, and 'link/..' resolves where the kernel lands instead of lexically. Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
|
Codex review: needs maintainer review before merge. What this changesThis PR shares symlink-aware path canonicalization across cleanup, plugin installation, includes, hooks, sandbox media, and local media access. Example: Run uninstall --state with OPENCLAW_STATE_DIR=/data/real and workspace /data/.openclaw/workspace, where /data/.openclaw points to /data/real.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes concrete data-loss and path-containment defects still present on main. No actionable introduced bug was found, and the previous backend-workdir blocker is resolved by removing that change; exact-head CI remains pending. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherFilesystem consumers pass configured roots and requested paths through the shared canonicalizer, then retain their existing containment, ownership, and final file-access guards. flowchart TD
A[Configured roots and requested paths] --> B[Shared canonicalization walk]
B --> C[Native filesystem probes]
C --> D[Canonical path or unresolved result]
D --> E[Consumer containment policy]
E --> F[Guarded read import or cleanup]
Technical reviewBest possible solution: Land the shared canonicalization repair with existing final-access guards intact after the exact-head required checks complete. Do we have a high-confidence way to reproduce the issue? Source shows the mixed-spelling failures, and the author supplies matching base-versus-head CLI/Gateway results; this read-only review did not execute target code. Is this the best way to solve the issue? A shared spelling owner is appropriate: it removes inconsistent local resolution while leaving consumer-specific preservation, root policy, and final-access checks with their existing owners. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 60b66097c5a6. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +163, Tests +192, Other +3. Total +358 across 22 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. 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 (3 earlier review cycles)
Reviewed November 8, 2026, 3:15 AM ET / 08:15 UTC (Revision 4). |
Returning the alias spelling let a retargeted alias redirect the first import outside the transforms root. Also drop the unused canonical routing helper. Co-authored-by: obviyus <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Dropped the backend sandbox exec-workdir change ( @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…nclaw#195061) * fix: route path containment through one canonical spelling owner Containment checks across media, sandbox, plugins, config includes, hooks, and uninstall cleanup each canonicalized roots and candidates their own way (realpath-or-lexical, existing ancestor with lexical '..' folding, plain path.resolve). Under a symlinked prefix the two sides of a comparison disagreed. src/infra/path-containment.ts now owns that spelling: one walk (sync and async) over native realpath(3) that never folds '..' lexically, follows dangling links to the location they name, and reports unreadable or looping prefixes instead of guessing. Callers compare canonical root against canonical candidate, or re-spell a candidate under the caller's root spelling. Fixed through it: - openclaw uninstall --state dropped an aliased workspace from the keep list and deleted it. - A plugin reinstall recorded under another spelling of the same directory deleted the directory it had just installed. - Hook transforms accepted an in-root dangling link to an outside module. - Aliased absolute includes, managed media, tmp media, and exec workdirs were refused; npm uninstall cleanup skipped aliased roots. - Local media: an in-root broken link is named in the not-found error, and 'link/..' resolves where the kernel lands instead of lexically. Co-authored-by: obviyus <[email protected]> * fix: classify link loops without a type assertion Co-authored-by: obviyus <[email protected]> * chore: shrink hooks-mapping assertion baseline Co-authored-by: obviyus <[email protected]> * fix(hooks): import the checked canonical transform path Returning the alias spelling let a retargeted alias redirect the first import outside the transforms root. Also drop the unused canonical routing helper. Co-authored-by: obviyus <[email protected]> * fix(scripts): add path-containment to the PR wrapper inventory config/includes.ts is in the trusted PR wrapper closure and now imports the shared containment owner. Co-authored-by: obviyus <[email protected]> * test: cover the hook alias retarget regression in the line allocation Co-authored-by: obviyus <[email protected]> * revert(exec): keep sandbox workdir mapping out of this change The backend-sandbox workdir respelling widens command launch authority and has no end-to-end proof here; it is deferred to a follow-up with a real sandbox backend run. Drops the now-unused sync respell helper. Co-authored-by: obviyus <[email protected]> --------- Co-authored-by: obviyus <[email protected]>
Backport the install/cleanup containment subset of #195061 (ce840d8). Keep existing write authority and cleanup ownership unchanged. Co-authored-by: obviyus <[email protected]> Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit daee0888ec7fb62679c2e9c7b2f791260afffa76)
Follow-up to #195009 (#194406). That PR fixed one place where a path-containment check compared a root and a candidate spelled two different ways. A read-only audit of the 53 non-test files that combine a path-resolving helper with a containment comparison turned up the same bug class in several other subsystems, including two cases that delete user data.
Root cause
Containment code resolved paths with several different helpers:
fs.realpath, falling back to the lexical pathrealpathExistingAncestor, or fs-safe'sresolvePathViaExistingAncestor, which fold..lexically and treat a dangling link as a missing pathresolveRealpathOrAbsolute, plus local copies such assafeRealpathin config includes andcanonicalizePathForContainmentin backuppath.resolveWhen a prefix is a symlink (for example
~/.openclaw -> /Volumes/ssd/oc, or/tmp -> /private/tmpon macOS), the two sides of a comparison come out spelled differently.One owner:
src/infra/path-containment.tsThere is now one walk, shared by the sync and async entry points:
realpath(3)for both the sync and async walks. Node's JSfs.realpathSyncand callbackfs.realpathnormalize the string first, which foldslink/..lexically. That matters for the sync callers moved here (hooks, includes, plugins). The async media path was already native throughfs.promises.realpath...after a missing segment: such a path returnsparent-after-missing, and callers treat it as outside.ELOOP) come back asunreadableandlink-loop.The module exposes
canonicalizeForContainment(Sync),realpathViaExistingPrefix(Sync),canonicalizeContainmentRoot(Sync)andrespellUnderRoot.respellUnderRootmaps a canonical candidate back under the caller's spelling of the root, so the lexical checks and alias-escape walks that follow still see a single spelling. TherealpathViaExistingPrefixadded in #195009 moves here frompath-existence.ts. The local copies in backup and config includes now delegate to it.Fixed
Each regression below fails on base
df371f177f94and passes with this change.commands/cleanup-utils.ts:openclaw uninstall --state~/.openclaw/workspacewhile the state dir resolved to its real path was dropped from the keep list, then deleted along with the rest of state.preserves a workspace spelled through a state-dir aliasplugins/install-persistence.ts,install-record-commit.tskeeps a reinstall recorded under another spelling of the same directorygateway/hooks-mapping.ts.mjspassed, then imported the outside module once it was created. Wrong deny: an aliased absolute in-root module was refused.rejects transform module symlink escape … (target exists: false),accepts an aliased absolute in-root moduleconfig/includes.ts(read, write,isInternalIncludeWriteTarget)accepts an absolute include spelled through an alias of the config diragents/sandbox-paths.ts(managed media, tmp media)/private/tmpvs/tmp, was refused as "escapes sandbox root".allows managed media spelled through an alias of the config dirplugins/uninstall-package-config.tsmedia/local-media-access.ts<link> is a symbolic link to a target that does not exist. This happens only when the target is inside an allowed root, so nothing about outside paths is revealed.dangling in-root folder link(plain and symlinked),names an in-root broken link when the read finds nothing. Theoutward symlink then ..row was added as a guard and already passes on basePlus
path-containment.test.ts, which checks that the sync and async walks give the same result for: an alias with a missing tail, a followed dangling link,..through an existing folder,..after a missing folder, and a link loop.Deliberately not changed
agents/bash-tools.exec-workdir.tsbackend sandbox workdir. A workdir spelled through a workspace alias doesn't map into the container, which is a wrong deny. The fix would widen command launch authority, and proving it needs a real sandbox backend run, so it is deferred to a follow-up.media/read-capability.tsrouting (workspaceOwnsMediaPath, registered remote roots). I tried canonical routing, andread-capability.workspace-access.test.ts"isolates remote aliases from granted siblings" failed. Routing by the requested spelling is intentional: a local symlink must not redirect into a remote workspace's namespace. A real-spelled path under an alias-registered remote root therefore stays a deny. Reverted.commands/database-migration-capture.ts. The audit flagged the lexicalsourceStateDiragainst the identity-resolved check as a wrong deny under a symlinked state dir. The existing testscaptures … through a state-root aliasandrestores … through a state-root aliaspass on base, so I couldn't reproduce it and left it alone. Only the sharedcanonicalizePathForContainmentcutover inbackup-shared.tsapplies.infra/state-migrations.doctor.tsOAuth-dir check. It compares two lexical spellings, soOPENCLAW_OAUTH_DIRspelled through a state-dir alias is refused asoauth-dir-outside-snapshot. This is a minor wrong deny that fails closed. The one-line fix adds an import, and that file is over the line-cap ratchet (2805 lines, cap 700), which rejects any growth. Deferred to a follow-up that extracts a sibling module.Lower-priority notes from the audit, not changed:
update-rehearsal-paths.ts:60, where a dangling link inside a rehearsal copy has no realistic trigger, anddoctor-sqlite-maintenance-lock.ts:133, where a canonical spelling skips one symlink component check butresolveRootPathSyncstill bounds it to the state dir.Checks
src/media(all),path-containment,sandbox-paths,bash-tools.exec-workdir,openclaw-tools.media-workspace,image-tool,cleanup-utils*,database-migration-capture,backup-shared,backup-restore,install-persistence,install-record-commit*,uninstall*,hooks-mapping,config/includes*,include-write-boundary,mutate.agent-delete-include,reply-media-paths. All pass except two that also fail on base for environment reasons:src/media/store.redirect.test.ts›keeps redirect cancellation and cross-origin header stripping in the guard(file mode 420 vs 384)backup-sqlite.test.ts›rejects an unknown SQLite snapshot agent, whose expected text includes the shell'sOPENCLAW_PROFILEpnpm check:changed: typecheck, lint, format, import cycles and the SQLite, mock and timeout ratchets pass. The assertion-safety ratchet passed after removing one type assertion and shrinking thehooks-mapping.tsbaseline entry. The only remaining failure ischangelog attributions, which flags existingCHANGELOG/*lines this PR doesn't touch.oxlintare clean on touched files. The line-cap ratchet passes. The test-lines ratchet passes with the allocation inconfig/test-lines-allocations/containment-canonical-owner.txt.Not verified
runIf(!win32). The walk splits on both separators but has not been run on Windows.