When installing dependencies, some package managers will automatically execute scripts distributed along with the source code of packages. Post-install scripts, for example, are a common way to execute malicious code at install time whenever a package is compromised.

Why is this an issue?

When package managers execute installation scripts, they run arbitrary code distributed with third-party packages. A compromised package can use this mechanism to execute malicious code on the build system, potentially stealing credentials, injecting backdoors, or otherwise compromising the supply chain.

What is the potential impact?

If a dependency is compromised and its scripts are executed, an attacker can run arbitrary code with the permissions of the process performing the installation. This can lead to credential theft from the build environment, introduction of backdoors into the application, or lateral movement within CI/CD infrastructure.

How to fix it in npm

Code examples

Noncompliant code example

steps:
  - run: npm install  # Noncompliant

Compliant solution

steps:
  - run: npm install --ignore-scripts

How to fix it in Yarn

Code examples

Noncompliant code example

steps:
  - run: yarn install  # Noncompliant

Compliant solution

steps:
  - run: |
      yarn install --ignore-scripts
      # for yarn 2.x and later
      YARN_ENABLE_SCRIPTS=false yarn install

How to fix it in PNPM

In versions prior to v10, pnpm runs lifecycle scripts by default. Starting from pnpm v10, lifecycle scripts are blocked by default, making pnpm install safe without additional flags. Adding packages to onlyBuiltDependencies in pnpm-workspace.yaml explicitly opts them in to script execution and should be avoided for unaudited packages.

Code examples

Noncompliant code example

steps:
  - run: pnpm install  # Noncompliant (pnpm < v10)

Compliant solution

steps:
  - run: pnpm install --ignore-scripts

How to fix it in Bun

Bun blocks lifecycle scripts by default for most packages (opt-in model), but still executes them for a built-in list of popular npm packages.

Code examples

Noncompliant code example

steps:
  - run: bun install  # Noncompliant

Compliant solution

steps:
  - run: bun install --ignore-scripts

Resources

Articles & blog posts

Standards