fix(tools): run no repository or package code in Node and .NET lockfile tools

SW
1h ago
+1585-724

Stacked on #345 (fix/tools-sandbox).

Rule: code a repository or one of its packages chose never runs on the Count's machine. The threat model now says so with no exception and lists the guard for each tool. When a lock can't be regenerated without running such code, the update is skipped with a standing reason, and maintenance is held the same way.

Refusal path

patchula_lockfiles::Failure::Refused(reason) is a refusal that the lockfile layer returns. Plan::lockfiles_failed turns it into Hold::Blocked(reason), the same skipped-with-reason path the dashboard and CLI report already show. Nothing is written. The type is deliberately small and generic. The sibling PR fix/no-exec-python-ruby may build the same thing, and whichever lands second reconciles.

Per tool

npm (native engine: npmEngine = "npm" or format v1 locks)

  • How it works: before npm starts, node/sources.rs checks against an allowlist every package.json in the tree (dependencies, devDependencies, optionalDependencies, peerDependencies, overrides) and the lock (resolved/version git sources, plus nested dependency specs at any depth, v1 and v3). Anything outside the allowlist is refused: git URLs, github:/gitlab:/bitbucket:/gist:, owner/repo, forge URLs and archives. The allowlist: registry ranges and tags, npm: aliases, jsr:, workspace:, catalog:, local paths, and .tgz/.tar.gz files on a host that is not a forge. A regenerated lock that records a git source is thrown away (Refused). The run gets GIT_ALLOW_PROTOCOL=none, plus NODE_OPTIONS=--require=<guard>. The guard exits any Node process that has _PACOTE_NO_PREPARE_ set, which is how pacote starts git-dependency preparation.
  • Flags verified: the pinned node 26.13.0 ships npm 11.20.0 with pacote 21.5.1, below 22, read on the VM. In pacote's lib/git.js, #prepareDir spawns npm install --force with _PACOTE_NO_PREPARE_ in its environment and never checks ignoreScripts. A hosted dependency with a full SHA goes through #clone with tarballOk and arrives as a codeload tarball through RemoteFetcher, so GIT_ALLOW_PROTOCOL doesn't stop it. That is why the guard exists. In lib/dir.js, #prepareDir does honour ignoreScripts. --ignore-scripts and NPM_CONFIG_IGNORE_SCRIPTS=true are kept.
  • Canaries: the direct dependency is Skipped with the reason, npm never starts, and no marker appears. The transitive case (canary-mid-gitplus → git+http://…/evil.git) runs npm, fails on the Git transport, and leaves no marker. real_npm_prepare_guard_stops_git_dependency_preparation shows the real node exits 97 under the guard with _PACOTE_NO_PREPARE_ set and nothing runs; an ordinary process runs normally.
  • Refused: git, forge and other non-allowlisted sources in any manifest, override or the lock.

Yarn Berry

  • How it works: the same refusal, applied to manifests (with resolutions), yarn.lock (descriptors, resolution, dependencies; :: binding params and patch: inner sources decoded), and every .yarnrc.yml from the project up to the tree root (catalog, catalogs, packageExtensions). exec: is refused. The run gets GIT_ALLOW_PROTOCOL=none and YARN_ENABLE_SCRIPTS=0. The run's user .yarnrc.yml is now always written and closes github.com and codeload.github.com (networkSettings.<host>.enableNetwork: false). The sanitized project rc copies drop networkSettings, so a project can't reopen those hosts.
  • Flags verified, from the 4.18.1 bundle on the VM: the GitFetcher (cloneFromRemote) and the GithubFetcher (fetchFromNetwork, https://github.com/<u>/<r>/archive/<treeish>.tar.gz) both call scriptUtils.prepareExternalProject. networkSettings is matched per hostname and enableNetwork === false throws ("has been blocked because of your configuration settings"). Experiment: with enableScripts: 0, a git:// dependency still ran its postinstall and prepack markers, and with GIT_ALLOW_PROTOCOL=none it failed with "transport 'git' not allowed". Transitive exec: from a registry package is rejected by Yarn itself ("only workspaces can depend on exec: packages"), so exec: is only a direct-dependency concern, and that is refused.
  • Canaries: in the canary repo's .yarnrc.yml, approvedGitRepositories: ["**"] turns off Yarn's own guard, as a hostile repository would. The direct dependency is Skipped and Yarn never starts. Transitive canary-mid-dotgit (http .git) fails with "not allowed" and leaves no marker. Transitive canary-mid-github (github:…#<sha>) fails with "blocked because of your configuration settings" and leaves no marker. Control: the same transitive dependency with Git reachable does write evil-* markers (the canary works), and its lock is thrown away as "the regenerated yarn.lock …".
  • Refused: as for npm, plus exec:, catalogs and packageExtensions.

aube (aube-lock.yaml, pnpm-lock.yaml), Bun

  • How it works: --ignore-scripts, as before. They are not refused.
  • Canaries, with Git reachable (GIT_ALLOW_PROTOCOL=http in the test) and blockExoticSubdeps: false in pnpm-workspace.yaml: the direct git+http dependency and the transitive one through canary-mid-gitplus both reach Planned. The lock records canary-evil and no marker appears, for aube-lock, pnpm-lock and bun.lock. Note: by default aube 2.9.0 itself refuses exotic transitive specs (blockExoticSubdeps).

dotnet

  • How it works: packages.lock.json is refused outright (dotnet::refused), and no dotnet process runs. Removed along with it: the restore code, the NuGet tool credentials (nuget_env/nuget_sources), Bin::Dotnet cache wiring, the dotnet pin (defaults.toml, test:tools, mise.lock), roxmltree from patchula-tools, the image's DOTNET_SYSTEM_GLOBALIZATION_INVARIANT, and the image smoke restore.
  • Test: packages_lock_json_is_refused_without_running_dotnet, for both maintenance and update. Status is Skipped with the MSBuild reason and no dotnet call.

uv, Poetry, Bundler: the guards land in the sibling PR (fix/no-exec-python-ruby). The threat model and the lockfiles guide in this PR already describe them as the brief specifies: uv --no-build/UV_NO_BUILD; Poetry under a launcher with its build entry points disabled, refused otherwise; Bundler on a Count-rendered Gemfile in a scratch directory, refusing gemspec, path:, git:/forge keys, git_source, plugin, eval_gemfile, install_if, unread lines and GIT/PATH/PLUGIN SOURCE lock sections.

Docs

  • internals/threat-model.md: the rule now covers dependency package code. There is no exception section. A new "How each tool keeps to it" section lists every tool. This fixes the contradiction with guide/lockfiles.md.
  • guide/lockfiles.md: the danger box is replaced by a note saying no tool runs repository or package code. A new "What is refused" section is added. The partitions paragraph is rewritten (the "every installation is trusted" and "lockfile tools run repository code anyway" wording is gone). The private-registry text, the Yarn rc sanitizing, and the .NET rows and mentions are updated.
  • renovate/compatibility.md lockfile table and a new renovate/departures.md entry, "Lockfiles that need repository or package code are refused". guide/managers.md, guide/server.mdx and reference/environment.md lose dotnet restore.

Tests run (boat VM)

cargo test -p patchula-tools -p patchula-engine -p patchula-update -p patchula-lockfiles (real tool tests included) and clippy -D warnings on those crates: green. The extract, files, config, config-files, catalog and catalog-controls state versions are bumped for the plan.rs, lockfiles/src and engine edits.

Follow-ups

  • The npm/Yarn refusal scans every package.json in the tree, not only the run's reach (workspaces and local paths). Narrowing it would refuse less in monorepos with unrelated Node projects.
  • dotnet: an allowlist approach (e.g. projects with no targets, props or package build assets) to regenerate some packages.lock.json safely.
  • The npm commit-pinned GitHub path, which arrives over HTTPS from codeload, is proven by the guard canary and by reading the pacote source, not end to end. An end-to-end canary would need a TLS CONNECT proxy for codeload.github.com.
  • Reconcile Failure::Refused with the sibling PR's skip path.