npm: Warn when install scripts change between versions#14069
Open
JamieMagee wants to merge 1 commit intomainfrom
Open
npm: Warn when install scripts change between versions#14069JamieMagee wants to merge 1 commit intomainfrom
JamieMagee wants to merge 1 commit intomainfrom
Conversation
Member
Author
|
Smoke test failures are because the new warning triggered on the upgrade of |
eb74ec4 to
9ec0d57
Compare
yeikel
reviewed
Feb 2, 2026
9ec0d57 to
a16b0ec
Compare
a16b0ec to
8d78e6f
Compare
npm lifecycle scripts (preinstall, install, postinstall, prepare) run automatically during package installation. This is a known attack vector for supply chain compromises. Dependabot already warns when the npm maintainer changes. This adds a similar warning when install scripts are added or modified between the previous and target versions. The warning appears in a collapsible 'Install script changes' section in PR descriptions, with a link to review the package contents on npm.
8d78e6f to
a3ae889
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What are you trying to accomplish?
npm lifecycle scripts run automatically during
npm installwith the user's privileges. Attackers have exploited this for supply chain attacks by injecting malicious code into these scripts on compromised packages.Dependabot already notifies users when an npm package has a new maintainer. This PR adds a similar notification when install scripts are added or modified between the previous version and the target version.
When triggered, users see an "Install script changes" section in their PR description with a message like:
This gives users visibility into a high-risk change before they merge.
Anything you want to highlight for special attention from reviewers?
The implementation follows the existing
maintainer_changespattern. I addedinstall_script_changesas an overridable method onMetadataFinders::Base(returnsnilby default) and implemented it in thenpm_and_yarnecosystem.Only the scripts that run during installation are checked1:
preinstall,install,postinstall,prepublish,preprepare,prepare, andpostprepare. Other scripts liketestorbuildare ignored since they don't execute automatically.Closes #14066
How will you know you've accomplished your goal?
All tests pass.
New test cases cover:
Checklist
Footnotes
https://docs.npmjs.com/cli/v11/using-npm/scripts#npm-install ↩