npm v12 hardens the default enhanced security scripts that could break your build if you don't authorize each script

Author: Published 3 min de lectura 294 reading

The images in this article were generated with artificial intelligence. How we publish

GitHub and the npm team have decided to tighten the default behavior of the package installer: in npm v12 The installation scripts will be deactivated by default and the resolution of units from remote Git or URLs repositories shall be restricted unless explicitly authorized by the developer. The measure seeks to close one of the most exploited routes in attacks to the supply chain: the automatic execution of code during "npm install" by means of life cycle hooks (pre-install, install, post-install and prepare).

The change responds to a real and common risk: a committed package at any point in the transitional chain can run code on the developer machine or in a CI runner. Many projects, libraries and tools depend on scripts that run automatically when installing dependencies, and that default trust is what attackers have used to insert back doors or run malicious payloads in development and deployment environments.

npm v12 hardens the default enhanced security scripts that could break your build if you don't authorize each script
Image generated with IA.

The practical implications are dual. On the one hand, improving safety by requiring the explicit approval of the execution of scripts and the resolution of unregistered sources; on the other hand, it may break up building and development flows which today depend on automatic native compilations (node-gyp), prepare scripts from Git references, or packages installed from remote tarballs. Equipment and projects using units with native compilation or direct references to repositories will have to be adapted.

GitHub recommends preparing already by updating to npm 11.16.0 or more, running a normal installation and reviewing the warnings that npm shows. The tool offers an approval flow with npm approved, which allows to review, approve the trust scripts and compromise the changes to the package.json so that only the approved ones continue to run after going up to npm v12. It's an opportunity to consciously audit which packages really need to run code locally.

As practical measures to reduce the impact and improve the security of your supply chain, consider the following: test changes in an isolated branch and in CI runners before migrating; update CI images or containers to include the new version of npm; avoid Git or remote dependencies without justification and, if needed, explicitly authorize them; prioritize the use of lockfiles and fixed versions; and treat with special care the packages that make native compilation (node-gyp), as npm can block implicit rebuildings.

npm v12 hardens the default enhanced security scripts that could break your build if you don't authorize each script
Image generated with IA.

In addition, it integrates complementary controls: it enables the analysis of dependencies and alerts (for example, Dependabot or Snyk) to detect suspicious changes, it requires human verification for relevant pull requests, it enables 2FA and publishing policies in the npm register for the maintainers, and it retains evidence of origin with SBOM and signatures where possible. GitHub's good practice documentation on supply chain security is a good starting point: https: / / docs.github.com / en / code-security / supply-chain-security.

To understand exactly which scripts and behaviors will be affected it is appropriate to read the official npm documentation on scripts and lifecycle hooks; this helps to identify in your tree of dependencies where scripts are run and which ones you need to explicitly approve: https: / / docs.npmjs.com / cli / v12 / using-npm / scripts. Adjust the pre-launch window to audit and reduce the attack surface: less reliable default scripts = less unauthorised execution risk.

In short, npm v12 represents a significant advance in protecting the JavaScript supply chain by converting an extension of tacit confidence into an explicit permit. The teams that take these measures with additional planning, testing and control will reduce their exposure to supply-chain attacks while avoiding unexpected interruptions in their construction and deployment processes.

Coverage

Related

More news on the same subject.