How Malware Abuses npm Lifecycle Scripts and VS Code Tasks

· Original article ↗

Summary

The article explains how malicious packages and repositories abuse automatic npm scripts and VS Code tasks to run malware, then outlines ways to reduce risk, including disabling scripts or task autoruns by default and reviewing untrusted repositories.

Key points

  • npm preinstall, install, and postinstall hooks can execute automatically during package installation.
  • VS Code tasks configured with runOn: folderOpen can execute commands when a project is opened, potentially without visible terminal output.
  • The article describes campaigns using these mechanisms to steal credentials and secrets, deploy remote-access malware, and spread through repositories.
  • Use npm --ignore-scripts or a package manager configuration that disables lifecycle scripts by default, then opt in when needed.
  • The article notes that --ignore-scripts does not block payloads in package entry points or all malicious git-dependency behavior; it cites npm CLI v11.10.0's --allow-git=none option.
  • Set VS Code task.allowAutomaticTasks to off or prompt, and review the .vscode/ directory before opening untrusted repositories.
  • The article recommends layered controls such as vetted internal registries, supply-chain firewalls, and endpoint detection, while noting that no single mitigation eliminates the risk.

Article Details

Defense Focus
Reduce the risk of automatic code execution from malicious npm packages and VS Code workspace tasks through safer defaults, repository review, and layered supply-chain and endpoint defenses.
Detection Methods
  • Review package lifecycle scripts and dependencies for unexpected install-time execution.
  • Inspect the .vscode/ directory and tasks.json before opening an external repository.
  • Use endpoint security to detect anomalous behavior associated with package installation or workspace tasks.
  • Use real-time package analysis and blocking to identify prohibited or malicious packages.
Data Sources
  • package.json lifecycle scripts and dependency declarations
  • .vscode/tasks.json and workspace settings
  • Endpoint behavior monitored by EDR
Platforms
  • Endpoint security products
  • Internal package registries
  • Supply chain firewalls
  • EDR
Defensive Actions
  • Disable npm lifecycle scripts by default where feasible; deliberately opt in for packages that require them.
  • Use lifecycle-script allow lists when the organization can maintain them.
  • Use --ignore-scripts for installs where appropriate, while accounting for payloads outside lifecycle hooks.
  • Set --allow-git=none in npm install commands or .npmrc to restrict git dependencies; do not assume the default setting blocks them.
  • Disable VS Code automatic tasks or configure them to prompt before running folder-open tasks, including in organizational baselines.
  • Treat external repositories as untrusted and review their .vscode/ directory before opening them.
  • Use vetted packages from internal registries and consider real-time supply-chain firewall controls.
  • Use EDR as a detection layer for anomalous behavior, not as a guarantee of prevention.

Indicators of compromise

TypeIndicatorContext
DOMAINaudit[.]checkmarx[.]cxCheckmarx lookalike domain identified as the destination for exfiltration of credentials stolen by the Bitwarden CLI malware.

MITRE ATT&CK

Threat Actors

Malware

Products

Countries

Related Articles