Skip to content

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

Open
sweepies wants to merge 1 commit into
fix/tools-sandboxfrom
fix/no-exec-node-dotnet
Open

sweepies wants to merge 1 commit into
fix/tools-sandboxfrom
fix/no-exec-node-dotnet

Conversation

@sweepies

@sweepies sweepies commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

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.

View guided diff Turn on auto-fix

…le tools

- A lockfile run can now be refused: Failure::Refused, which the plan
  turns into a skipped update (Hold::Blocked) with a standing reason, so
  no PR is opened or updated with a stale lock. Maintenance is held the
  same way.
- npm (native) and Yarn Berry are refused before they start when any
  package.json, its overrides or resolutions, a Yarn catalog or
  packageExtensions entry, or the lock names a source outside an
  allowlist of registry versions, local paths and plain tarballs: git
  URLs, forge shorthands, owner/repo, forge archive URLs and exec: all
  fail it. A regenerated lock that records such a source is thrown away.
- npm and Yarn runs get GIT_ALLOW_PROTOCOL=none. npm runs load a guard
  that stops pacote's git-dependency preparation process (pacote 21.5.1
  in the pinned npm prepares whatever --ignore-scripts says, and a
  commit-pinned GitHub dependency arrives over HTTPS). Yarn runs with
  enableScripts off, project networkSettings dropped and github.com and
  codeload.github.com closed in the run's user configuration, which
  stops its GitHub fetcher.
- packages.lock.json is never regenerated: dotnet restore evaluates
  MSBuild code. The restore path, NuGet tool credentials, the dotnet pin,
  cache wiring, image ICU setting and image smoke restore are removed.
- Real-tool canaries over a loopback registry and Git host: npm and Yarn
  direct (refused, tool never starts) and transitive (fails, no marker),
  a Yarn control proving packing would run the scripts, and aube (aube
  and pnpm locks) and Bun locking git deps directly and transitively
  with no marker, with each tool's own git guard turned off.
- Threat model states the rule with dependency code and no exception,
  and lists the guard per tool; the lockfiles guide, compatibility and
  departures pages follow.
- Bump the extract, files, config, config-files, catalog and
  catalog-controls state versions.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
count-patchula 1f4943a Commit Preview URL

Branch Preview URL
Nov 16 2026, 03:03 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant