Skip to content

fix(plugins): restrict npm project cleanup to owned roots - #124608

Merged
steipete merged 7 commits into
mainfrom
fix/plugin-uninstall-canonical-root-ownership
Aug 16, 2026
Merged

steipete merged 7 commits into
mainfrom
fix/plugin-uninstall-canonical-root-ownership

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #123972
Related: #123973

What Problem This Solves

Fixes an issue where uninstalling an npm-managed plugin could either leave its isolated OpenClaw npm project behind or, after the partial repair in #123973, widen recursive cleanup without proving that the selected project root was owned by that package.

Why This Change Was Made

The plugin lifecycle owner now records whether an npm match came from the exact legacy shared root or the isolated projects topology, and validates that fact again before filesystem or npm mutation. Whole-project deletion is limited to the package's exact ordinary root or an exact lowercase-hex generation root. Every noncanonical project falls back to exact package-leaf removal without running npm in the enclosing project.

The accepted ownership matrix is:

Root/path state Result
Exact ordinary package project root Remove the complete owned project
Exact <package-prefix>__openclaw-generation__g-[a-f0-9]{16} root Remove the complete owned generation
Legacy shared npm root Run shared-root npm cleanup, then remove only the exact package
Arbitrary sibling, lookalike, malformed generation, or cross-package root Remove only the exact validated package leaf; never mutate the enclosing project
Traversal or outside managed topology Refuse removal
Symlinked npm root, projects directory, project root, package leaf, or project manifest Refuse removal
Active or explicit --keep-files retained generation Preserve it
Missing package target Keep cleanup retryable through the canonical existing ancestor
Bundled plugin Reject uninstall; disable instead
git, path, ClawHub, and marketplace installs Existing behavior unchanged

Peter explicitly approved the reviewed +154 production baseline. Fresh security review found three additional ownership gaps in that form: package/manifest symlink acceptance, npm mutation inside noncanonical fallback projects, and inference of legacy-root ownership from directory shape. The final patch is +185/-9 production (net +176); the extra net +22 records the planner-owned root kind, validates missing leaves through canonical existing ancestors, and applies universal manifest/package checks. Removing those paths reproduces the accepted P1 findings.

Alternatives tried and rejected:

  • The earlier +59 form validated names but not the full real-path ownership chain.
  • Always deleting only the package leaf avoids widening deletion but preserves the original project-level archive/lockfile/dependency leak.
  • Inferring a legacy shared root from “parent is not named projects” remained forgeable; ownership is now recorded at the exact planner match site and cross-checked against topology.
  • Node's recursive rm is path-based and does not expose descriptor-anchored recursive deletion. Hostile same-user swaps between adjacent filesystem syscalls remain outside the documented single-user trusted-host threat model; every stable pre-plan and post-plan substitution we can revalidate is covered.

No config, schema, protocol, Plugin SDK, dependency, release, or migration contract changes.

User Impact

Ordinary uninstall removes all files in an OpenClaw-owned isolated npm project. Shared and noncanonical projects keep unrelated manifests, lockfiles, dependencies, and sibling packages intact. Retained update generations and --keep-files continue to work, and failed or missing cleanup targets remain retryable.

Evidence

  • OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree node scripts/run-vitest.mjs src/plugins/management-service.test.ts src/plugins/management-service.install-compensation.test.ts src/plugins/uninstall.test.ts src/plugins/install-record-commit.test.ts src/plugins/install-record-commit.retention.test.ts src/plugins/managed-npm-retention.test.ts src/plugins/install-persistence.test.ts — 167/167 passed. This includes the requested 135-test owner/sibling set plus retention, compensation, rollback/failure/retry, missing-target, and hostile symlink/root matrices.
  • Blacksmith Testbox tbx_01m05atf16x2w15abd90c82jch, run 31948837818 — exact-head source-absent packed Docker lifecycle passed: full build and tarball integrity, tgz/local/file/npm/git/marketplace install and update, malformed npm rejection, explicit restart visibility, retained reinstall, and uninstall. Hermetic ClawHub block was intentionally offline.
  • Blacksmith Testbox tbx_01m05b7wcfetgp6x0ke1h0f29m, run 31949170366 — check:changed, full pnpm check, test types, full format, core/extensions/scripts lint, both cycle guards, plugin boundary and SDK surface checks, dead-code/dependency checks, high-severity production dependency audit, OpenGrep rule metadata, and diff hygiene passed. The OpenGrep binary was unavailable on the runner, so no binary OpenGrep scan is claimed.
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main --stream-engine-output — final whole-branch general review clean; no accepted/actionable P0 finding (0.98 confidence).
  • Dedicated whole-branch P1 filesystem-security autoreview — clean; no accepted/actionable P0/P1 finding (0.91 confidence).
  • TruffleHog exact-bundle scan — clean in both final reviews.
  • Direct sibling Codex source inspection confirmed this plugin lifecycle path does not change Codex CLI/app-server protocol or runtime contracts (../codex/codex-rs/cli/src/main.rs, ../codex/codex-rs/core/src/lib.rs).

Tests and test support: +508/-78 (net +430).

No CHANGELOG.md edit. AI-assisted, maintainer-owned, and explicitly approved for full repair landing.

@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added size: L maintainer Maintainer-authored PR labels Aug 16, 2026
@steipete steipete self-assigned this Aug 16, 2026
@steipete
steipete marked this pull request as ready for review August 16, 2026 13:42
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. 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 Aug 16, 2026
@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 16, 2026, 9:48 AM ET / 13:48 UTC.

ClawSweeper review

What this changes

The PR limits npm plugin cleanup to canonical OpenClaw-owned project roots and otherwise removes only the exact plugin package leaf.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for maintainer review: the patch correctly closes the ownership gap left by the earlier project-root cleanup, but this maintainer-owned filesystem-deletion change should wait for its exact-head safety checks.

Priority: P2
Reviewed head: 58b8aee4d9be9813ae43c35ca711c2ddc5f35d59
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-boundary hardening with broad destructive-path regression coverage and no actionable review finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The author is a repository member, so the external-contributor proof gate does not apply; the PR body nevertheless links packaged Docker lifecycle evidence.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The author is a repository member, so the external-contributor proof gate does not apply; the PR body nevertheless links packaged Docker lifecycle evidence.
Evidence reviewed 6 items Current-main gap: Current main reconstructs a managed project root from the install-path segments and returns that root without proving it is the package's canonical root.
Ownership boundary repair: The PR defines canonical ordinary/generation project shapes and rechecks real-path containment before allowing whole-project deletion.
Mutation-time revalidation: The apply path validates the planned root kind, manifest, and exact package target before recursive removal; shared-root npm mutation is limited to the recorded legacy branch.
Findings None None.
Security None None.

How this fits together

The plugin lifecycle turns an installed plugin record into a filesystem cleanup plan during uninstall and failed-install compensation. That plan may invoke npm cleanup or recursive deletion, so it must distinguish OpenClaw-owned npm projects from adjacent operator-owned paths.

flowchart LR
  A[Plugin install record] --> B[Uninstall planner]
  B --> C[Classify shared or isolated npm root]
  C --> D[Canonical path ownership check]
  D --> E[Shared npm package cleanup]
  D --> F[Owned project deletion]
  D --> G[Noncanonical package-leaf deletion]
Loading

Decision needed

Question Recommendation
Should this maintainer-owned filesystem-cleanup hardening land once exact-head checks complete? Land after exact-head validation: Merge once the current head retains the source-absent lifecycle and safety coverage described in the PR.

Why: The protected maintainer label and recursive-deletion security boundary require explicit owner judgment even though no patch defect was found.

Before merge

  • Resolve merge risk (P1) - Recursive deletion now depends on 176 net new production lines of ownership checks; exact-head safety validation should complete before landing.
Agent review details

Security

None.

PR surface

Source +176, Tests +430. Total +606 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 3 185 9 +176
Tests 4 508 78 +430
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 693 87 +606

Review metrics

Metric Value Why it matters
Production versus test delta production +185/-9 (net +176); tests +508/-78 (net +430) The production growth centralizes two-phase filesystem ownership checks, while the added tests exercise the destructive-path matrix.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #123972
Summary: This PR is the candidate hardening for the canonical isolated npm-project uninstall defect.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Complete exact-head safety validation (recommended)
    Require the current PR head to finish its filesystem ownership and packaged lifecycle checks before merge.

Technical review

Best possible solution:

Keep the planner-to-apply ownership revalidation as the canonical cleanup boundary; no net-neutral alternative was found because safe deletion requires both a shared path verifier and its use at planning and mutation time.

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

Yes—source inspection shows the current planner widens an npm project target from install-path shape alone; the PR’s focused tests encode the failing ownership cases.

Is this the best way to solve the issue?

Yes. Carrying root classification from the planner and revalidating it at mutation time is the narrowest owner-boundary repair; package-leaf-only cleanup would retain known managed-project debris.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 2ceb18118ced.

Labels

Label changes:

  • add P2: This is a bounded plugin-uninstall correctness and filesystem-safety repair with limited operator blast radius.
  • add merge-risk: 🚨 security-boundary: The patch changes the predicate that permits npm mutation and recursive filesystem deletion.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The author is a repository member, so the external-contributor proof gate does not apply; the PR body nevertheless links packaged Docker lifecycle evidence.

Label justifications:

  • P2: This is a bounded plugin-uninstall correctness and filesystem-safety repair with limited operator blast radius.
  • merge-risk: 🚨 security-boundary: The patch changes the predicate that permits npm mutation and recursive filesystem deletion.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The author is a repository member, so the external-contributor proof gate does not apply; the PR body nevertheless links packaged Docker lifecycle evidence.

Evidence

What I checked:

  • Current-main gap: Current main reconstructs a managed project root from the install-path segments and returns that root without proving it is the package's canonical root. (src/plugins/uninstall.ts:217, 2ceb18118ced)
  • Ownership boundary repair: The PR defines canonical ordinary/generation project shapes and rechecks real-path containment before allowing whole-project deletion. (src/plugins/install-paths.ts:139, 58b8aee4d9be)
  • Mutation-time revalidation: The apply path validates the planned root kind, manifest, and exact package target before recursive removal; shared-root npm mutation is limited to the recorded legacy branch. (src/plugins/uninstall.ts:464, 58b8aee4d9be)
  • Caller and lifecycle coverage: Plugin management passes the planner result into the removal owner and keeps a failed removal retryable, so the new invariant covers normal uninstall and compensation. (src/plugins/management-service.ts:1698, 58b8aee4d9be)
  • Behavioral regression coverage: Tests cover ordinary and generation roots, malformed/lookalike roots, projects-directory and package symlinks, plan-to-apply substitution, manifest substitution, and retention cleanup. (src/plugins/uninstall.test.ts:1244, 58b8aee4d9be)
  • Prior cleanup provenance: The prior merged cleanup established full isolated-project deletion; this PR hardens that path rather than duplicating it. (src/plugins/uninstall.ts:230, d6e6d67adc6f)

Likely related people:

  • steipete: Authored the earlier merged isolated-project cleanup and the current ownership hardening. (role: feature owner and recent area contributor; confidence: high; commits: d6e6d67adc6f, 58b8aee4d9be; files: src/plugins/uninstall.ts, src/plugins/install-paths.ts, src/plugins/managed-npm-retention.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready on exact head 58b8aee4d9be9813ae43c35ca711c2ddc5f35d59.

The original defect was an incomplete ownership boundary: ordinary uninstall needed to remove a complete package-owned isolated npm project, while malformed or stale install records must never widen deletion or npm mutation to a sibling/noncanonical project. The final planner records legacy-shared versus isolated-project at the exact match site; apply cross-validates that fact against the canonical real-path topology before and after mutation. Exact ordinary/lowercase-hex generation roots are removed as units. Noncanonical roots remove only the exact package leaf without invoking npm.

Fresh security review findings were all accepted and repaired: package/manifest symlink rejection, no npm mutation in noncanonical fallback projects, and no directory-shape inference for legacy-root ownership. Final general and dedicated P1 security autoreviews are clean; TruffleHog is clean.

Proof:

Production LOC: +185/-9 (net +176). Peter explicitly approved the reviewed +154 baseline; the final net +22 closes the three subsequent P1 ownership gaps. Removing it recreates those findings.

ClawSweeper exact-head run https://github.com/openclaw/clawsweeper/actions/runs/31950657018 completed successfully and applied rating: 🦞 diamond lobster plus status: 👀 ready for maintainer look. Its publisher left the start placeholder instead of a detailed body, so there are no visible Rank-up moves: to apply or skip; proceeding under the repository rule not to block landing on the publisher after a clean exact-head review.

No config/schema/protocol/Plugin SDK/dependency/release change and no changelog edit.

@steipete
steipete merged commit 7f842da into main Aug 16, 2026
308 checks passed
@steipete
steipete deleted the fix/plugin-uninstall-canonical-root-ownership branch August 16, 2026 13:56
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 17, 2026
…24608)

* fix(plugins): validate npm project root ownership

Restrict recursive managed npm project deletion to canonical ordinary or exact generation roots. Preserve noncanonical sibling roots while retaining package-leaf cleanup and valid generation lifecycle behavior.\n\nFixes openclaw#123972

* fix(plugins): reject substituted npm project roots

* fix(plugins): pin managed npm root identity

* fix(plugins): revalidate npm package removals

* fix(plugins): validate npm cleanup descendants

* fix(plugins): reject npm cleanup symlink aliases

* fix(plugins): bind npm cleanup to planned root kind
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: L 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.

[Bug]: Plugin uninstall leaves isolated npm project root behind

1 participant