Skip to content

npm: Warn when install scripts change between versions#14069

Open
JamieMagee wants to merge 1 commit intomainfrom
jamiemagee/npm-install-script-changes
Open

npm: Warn when install scripts change between versions#14069
JamieMagee wants to merge 1 commit intomainfrom
jamiemagee/npm-install-script-changes

Conversation

@JamieMagee
Copy link
Member

@JamieMagee JamieMagee commented Feb 1, 2026

What are you trying to accomplish?

npm lifecycle scripts run automatically during npm install with 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 version adds postinstall script that runs during installation. Review the package contents before updating.

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_changes pattern. I added install_script_changes as an overridable method on MetadataFinders::Base (returns nil by default) and implemented it in the npm_and_yarn ecosystem.

Only the scripts that run during installation are checked1: preinstall, install, postinstall, prepublish, preprepare, prepare, and postprepare. Other scripts like test or build are 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:

  • No previous version (returns nil)
  • Script added (returns notification)
  • Script modified (returns notification)
  • Non-install script changed (returns nil)
  • Multiple scripts changed (lists all)

Checklist

  • I have run the complete test suite to ensure all tests and linters pass.
  • I have thoroughly tested my code changes to ensure they work as expected, including adding additional tests for new functionality.
  • I have written clear and descriptive commit messages.
  • I have provided a detailed description of the changes in the pull request, including the problem it addresses, how it fixes the problem, and any relevant details about the implementation.
  • I have ensured that the code is well-documented and easy to understand.

Footnotes

  1. https://docs.npmjs.com/cli/v11/using-npm/scripts#npm-install

@JamieMagee JamieMagee requested a review from a team as a code owner February 1, 2026 18:45
@JamieMagee
Copy link
Member Author

Smoke test failures are because the new warning triggered on the upgrade of form-data and its new prepublish script: form-data/form-data@c4bbb13

@JamieMagee JamieMagee force-pushed the jamiemagee/npm-install-script-changes branch from eb74ec4 to 9ec0d57 Compare February 1, 2026 19:24
@JamieMagee JamieMagee force-pushed the jamiemagee/npm-install-script-changes branch from 9ec0d57 to a16b0ec Compare February 2, 2026 21:28
@dependabot dependabot deleted a comment from yeikel Feb 2, 2026
@JamieMagee JamieMagee force-pushed the jamiemagee/npm-install-script-changes branch from a16b0ec to 8d78e6f Compare February 2, 2026 23:17
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.
@JamieMagee JamieMagee force-pushed the jamiemagee/npm-install-script-changes branch from 8d78e6f to a3ae889 Compare February 4, 2026 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Notify users when npm install scripts change between versions

2 participants