Cyber Security News

GitHub Introduces Automatic Controls to Prevent Malicious npm Install Scripts

GitHub has announced a major security-focused overhaul of npm with the upcoming release of npm v12, introducing stricter default controls designed to mitigate software supply chain attacks and prevent unauthorized code execution during package installation.

The changes, currently available as opt-in warnings in npm version 11.16.0 and later, are expected to become the default behavior when npm v12 is officially released in July 2026.

Automatic Controls to Prevent Malicious npm

At the core of this update is a fundamental shift in how npm handles install-time scripts, a long-standing attack vector frequently abused by threat actors to execute malicious code.

In npm v12, the allowScripts configuration will be turned off by default, meaning that lifecycle scripts such as preinstall, install, and postinstall will no longer run automatically for dependencies unless explicitly approved by developers.

This change also impacts implicit script execution, including native module builds powered by node-gyp, which will now be blocked unless permitted.

Additionally, npm will restrict the execution of prepare scripts from Git, local files, and linked dependencies under the same policy. Developers can audit affected packages using the npm approve-scripts –allow-scripts-pending command, which identifies dependencies attempting to run scripts.

Trusted packages can then be explicitly allowlisted using npm approve-scripts. In contrast, untrusted ones can be blocked with npm deny-scripts. The resulting policy is stored within the package.json file, enabling version-controlled enforcement across development environments.

Another significant change involves Git-based dependencies. The –allow-git flag will default to “none,” preventing npm from resolving Git dependencies unless explicitly enabled.

This measure addresses a previously identified risk: malicious .npmrc configurations within Git repositories could override the Git executable path, enabling arbitrary command execution even when script execution is turned off via –ignore-scripts.

Similarly, npm v12 introduces a default restriction on remote dependency sources via the –allow-remote flag, which defaults to “none.”

This prevents installations from remote tarball URLs unless explicitly authorized, further reducing exposure to unverified or tampered packages delivered outside the official registry. Notably, related flags such as –allow-file and –allow-directory will retain their current behavior.

Key npm v12 security changes

Control / FlagNew Default in v12What Changes for DevelopersSecurity Benefit
allowScriptsOff (scripts blocked by default)preinstall, install, postinstall, and prepare scripts from dependencies do not run unless explicitly allowlisted in package.json. Reduces risk of malicious or hijacked install scripts executing arbitrary code during npm install.
npm approve-scriptsExplicit allowlist per projectTeams must run npm approve-scripts --allow-scripts-pending, review packages with scripts, approve trusted ones, and commit the updated package.json. Enforces explicit trust for script execution and makes script-related risk visible and auditable in version control.
--allow-gitnoneGit dependencies (direct or transitive) are not resolved unless --allow-git is set, even when previously used. Closes a path where a Git dependency’s .npmrc could override the Git executable and achieve code execution.
--allow-remotenoneRemote URL dependencies (for example, HTTPS tarballs) are blocked unless explicitly permitted with --allow-remote. Limits exposure to unverified artifacts hosted outside the npm registry, reducing chances of supply chain compromise.
--allow-file, --allow-directoryNo default changeLocal file and directory dependencies continue to work under current defaults. Keeps existing local workflows stable while tightening only higher‑risk remote and Git-based paths.
Preparation pathUse npm ≥ 11.16.0Upgrade to npm 11.16.0+, run normal installs, review warnings, approve or deny scripts, and commit the resulting allowlist before moving to v12. Smooth migration to stricter defaults without breaking builds, while progressively hardening supply chain defenses.

To prepare for these breaking changes, GitHub recommends upgrading to npm 11.16.0 or later and running standard installation workflows to surface warnings.

Developers should review flagged packages, approve trusted scripts, and commit the updated configuration to ensure a smooth transition. Once npm v12 is adopted, only explicitly approved scripts will execute, effectively eliminating implicit trust in dependency behavior.

These changes reflect GitHub’s broader push toward strengthening supply chain security within the JavaScript ecosystem. By shifting from implicit execution to explicit trust, npm v12 aims to significantly reduce the risk of dependency-based attacks, which have increasingly targeted developers through malicious packages, compromised maintainers, and obfuscated install scripts.

Follow us on Google News, LinkedIn, and X to Get Instant Updates and Set GBH as a Preferred Source in Google.

Divya

Divya is a Senior Journalist at GBhackers covering Cyber Attacks, Threats, Breaches, Vulnerabilities and other happenings in the cyber world.

Recent Posts

Hackers Use ConnectWise SkyKick Credentials to Access Microsoft 365, Halting Cloud Backups

Attackers abused compromised ConnectWise Cloud Backup credentials to access Microsoft 365 customer environments, prompting ConnectWise…

1 day ago

Anthropic’s Claude AI Uncovers Origins of NSA-Provided Cryptographic Keys After 25 Years

Anthropic says an internal Claude research model reconstructed how the National Security Agency generated seeds…

1 day ago

Critical WordPress Flaws Allow Attackers to Execute Remote Code Without Authentication

Two WordPress Core vulnerabilities can be chained to execute remote code without authentication, according to…

1 day ago

OpenBSD Kernel Flaw Dating Back 37 Years Enables Local Privilege Escalation to Root

A newly disclosed OpenBSD kernel exploitation chain combines a shared memory accounting flaw with a…

1 day ago

GhostAction Hackers Hide Credential-Stealing Malware in Fake Font Files Across 94 GitHub Repositories

GhostAction attackers have expanded their GitHub credential theft campaign with a second stage that disguises…

2 days ago

SideCopy Hackers Target Indian Organizations With ReverseRAT Malware to Steal Data

Indian authorities have warned that SideCopy hackers are targeting Indian organizations, including academic institutions, with…

2 days ago