feat: add no-downgrade package trust policy - #9902
Conversation
|
Additional validation against npm's current
The clean local review commit was also reconstructed from current upstream |
|
This is a terrible idea. First of all, provenance is NOT a security indicator. Second, it's perfectly legitimate for a maintainer to decide to start using provenance, and then decide to stop. Third, pnpm's implementation of it has (or at least, had, I'm not sure) a bug (semver v7 is published with provenance, v6 is not, but pnpm was keying on dates, not release lines, to mark a "downgrade"), and that highlights some of the flaws in even attempting to use provenance in this manner (this PR seems to do the same). Provenance's only value whatsoever is post-incident forensics, and it should never be used as part of an install gate of any kind. This should simply be closed. |
|
Thanks for calling out the cross-release-line case. I agree that comparing a maintenance release in one major line against trust evidence introduced on another major line would create false positives. |
What / Why
Adds opt-in
trust-policy=no-downgradeenforcement for registry dependencies, addressing #9242.When enabled, npm rejects a selected package version when an earlier-published version in the same major release line established stronger trust evidence:
trusted publisher provenance > provenance attestation > no trust evidenceThe policy runs before reification for
npm install,npm update, andnpm ci, so a detected downgrade is blocked before files are written tonode_modules.Configuration
trust-policy-excludeaccepts package names, exact versions, and semver ranges.trust-policy-ignore-afterskips selected versions older than the configured number of minutes. This follows the current pnpm selected-version age behavior used as prior art in [Feature Request] Support trustPolicy to reject packages with provenance downgrade at install time #9242.Security model
This detects a credential-theft pattern where an attacker can publish with a stolen npm token but cannot reproduce the project's trusted CI/provenance path. A version that drops from trusted-publisher or provenance evidence to weaker or absent evidence is rejected.
To avoid comparing independent maintenance lines, trust history is evaluated only within the selected version's semver major release line. Publish chronology is still used to determine which versions are earlier within that line. For example, a later v6 maintenance release is not judged against trust evidence first introduced on v7.
The implementation:
npm ciinstalls;ETRUSTDOWNGRADEorETRUSTPOLICYMETADATA, with actionable exclusion remediation.A key
npm cidetail is that Arborist may receive policy settings in constructor options and callbuildIdealTree()without method arguments. The preflight therefore verifies using Arborist's effective options, with regression coverage.Testing
Focused coverage includes:
Validation performed:
All focused tests passed, touched-file lint passed, and the final fork tree was verified byte-for-byte against the tested local tree.
Addresses #9242
References