feat: add allowBuildsOfTrustedDeps setting (true by default)#11078
Conversation
Add a new `use-default-trusted-deps` setting (default: true) that automatically loads a curated list of known-good packages into `allowBuilds` from @pnpm/plugin-trusted-deps. User-configured allowBuilds entries take precedence over the defaults. Set `use-default-trusted-deps=false` to disable.
The package uses Object.defineProperty for DEFAULT_ALLOW_BUILDS, which Node.js/Jest ESM interop can't detect as a named export. Switch to a default import to fix test failures.
The package now ships an ESM entry point with proper named exports, so we can use a clean named import instead of the default import workaround.
Uses static JSON import attributes in ESM entry, fixing the bundle issue where createRequire resolved paths relative to the bundle output instead of the original package.
The tests assert exact allowBuilds contents, so the default trusted list must be disabled to avoid polluting the expected values.
Track the user's original allowBuilds separately as userAllowBuilds before merging the default trusted list. Use userAllowBuilds when writing back to pnpm-workspace.yaml to avoid persisting the ~370 default entries from @pnpm/plugin-trusted-deps.
There was a problem hiding this comment.
Pull request overview
Adds a new config setting that enables a bundled “trusted deps” allowlist to automatically populate allowBuilds by default, while ensuring only user-provided allowBuilds entries are written back to workspace config.
Changes:
- Introduces
allowBuildsOfTrustedDeps(defaulttrue) and wires it into config parsing/defaults. - Merges
@pnpm/plugin-trusted-deps’sDEFAULT_ALLOW_BUILDSintoallowBuildswhile preserving the pre-mergeuserAllowBuildsfor write-back. - Updates
approve-buildsand ignored-build handling to avoid persisting the default trusted list intopnpm-workspace.yaml.
Reviewed changes
Copilot reviewed 13 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pnpm/artifacts/exe/pn | Adds blank placeholder executable artifact file. |
| pnpm/artifacts/exe/pnx | Adds blank placeholder executable artifact file. |
| pnpm/artifacts/exe/pnpx | Adds blank placeholder executable artifact file. |
| pnpm-workspace.yaml | Adds @pnpm/plugin-trusted-deps to the workspace catalog. |
| pnpm-lock.yaml | Locks @pnpm/plugin-trusted-deps@0.3.0-2. |
| installing/commands/src/handleIgnoredBuilds.ts | Writes back allowBuilds using userAllowBuilds to avoid persisting defaults. |
| config/reader/src/types.ts | Registers allow-builds-of-trusted-deps config schema type. |
| config/reader/src/index.ts | Defaults allow-builds-of-trusted-deps to true and merges trusted defaults into allowBuilds. |
| config/reader/src/configFileKey.ts | Allows allow-builds-of-trusted-deps in global config files. |
| config/reader/src/Config.ts | Adds allowBuildsOfTrustedDeps and userAllowBuilds to the Config type. |
| config/reader/package.json | Adds dependency on @pnpm/plugin-trusted-deps. |
| building/commands/test/policy/approveBuilds.test.ts | Disables trusted defaults in tests to preserve prior expectations. |
| building/commands/src/policy/approveBuilds.ts | Uses userAllowBuilds as the base for persisted allowBuilds updates. |
| typings/local.d.ts | Adds local typings for @pnpm/plugin-trusted-deps. |
| .changeset/use-default-trusted-deps.md | Changeset documenting the new setting and default behavior. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (pnpmConfig.allowBuildsOfTrustedDeps) { | ||
| // Save the user-configured allowBuilds before merging defaults. | ||
| // This is used when writing back to pnpm-workspace.yaml to avoid | ||
| // persisting the default trusted list. | ||
| pnpmConfig.userAllowBuilds = pnpmConfig.allowBuilds | ||
| // User-configured allowBuilds take precedence over the defaults. | ||
| pnpmConfig.allowBuilds = { ...DEFAULT_ALLOW_BUILDS, ...pnpmConfig.allowBuilds } | ||
| } |
There was a problem hiding this comment.
The new allowBuildsOfTrustedDeps behavior (capturing userAllowBuilds and merging DEFAULT_ALLOW_BUILDS into allowBuilds) isn’t covered by config reader tests. Please add coverage that asserts: (1) default is enabled and allowBuilds includes trusted defaults, (2) user allowBuilds overrides defaults, (3) setting allow-builds-of-trusted-deps=false disables the merge, and (4) userAllowBuilds preserves the pre-merge values used for write-back.
Without this, userAllowBuilds wasn't passed through to handleIgnoredBuilds, causing the default trusted list to be written to pnpm-workspace.yaml during e2e tests.
When the user has no allowBuilds configured, userAllowBuilds was undefined, causing handleIgnoredBuilds to fall back to the merged allowBuilds (with defaults). Use empty object instead so the fallback doesn't trigger.
Instead of tracking userAllowBuilds separately (which gets stale when other code writes to pnpm-workspace.yaml mid-install), read the current allowBuilds directly from pnpm-workspace.yaml before writing. This avoids persisting the default trusted list and preserves entries written by --allow-build earlier in the flow. Also update e2e test expectation: esbuild is now in the default trusted list, so it builds instead of being ignored.
The execPnpmInstall helper runs the bundled CLI which picks up the default allowBuildsOfTrustedDeps=true. This causes extra placeholder entries in pnpm-workspace.yaml that break assertions.
approveBuilds.handler should use opts.allowBuilds from getConfig() (which excludes trusted deps defaults when disabled) rather than reading the workspace manifest. The handler's job is to write approve/deny decisions, not merge with auto-populated placeholders.
Cover: (1) default enabled with trusted defaults merged, (2) user allowBuilds overrides defaults, (3) setting allow-builds-of-trusted-deps=false disables the merge.
|
This is probably a convenience vs. security tradeoff, but this seems to put quite a lot of trust in the vetting of the list of trusted packages, and that they won't become malicious in the future. Maybe this should be an opt-in feature? |
|
62% of the pnpm users want this to be the default: https://x.com/pnpmjs/status/1960322324999098403 |
|
Created a new poll: https://x.com/pnpmjs/status/2037119638748696924 |
|
The changes has been reverted 0e8042e |
Summary
allowBuildsOfTrustedDepssetting (default:true) that automatically loads a curated list of ~370 known-good packages from@pnpm/plugin-trusted-depsintoallowBuildsallowBuildsentries take precedence over the defaultspnpm-workspace.yaml— only user-configured entries are written backallowBuildsOfTrustedDeps: falseto opt outTest plan
approveBuildstests pass with default list disabledallowBuildsconfigallowBuildsOfTrustedDeps: false— should behave as before