npm-security-best-practices

Harden npm, pnpm, and Bun installs against supply-chain attacks.

11|1|Updated May 16, 2026
One-click install
npx skills add https://github.com/Aradotso/security-skills --skill npm-security-best-practices
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: npm-security-best-practices
Source: https://github.com/Aradotso/security-skills/tree/main/skills/npm-security-best-practices
Command: npx skills add https://github.com/Aradotso/security-skills --skill npm-security-best-practices

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

npm package installs are frequently abused through malicious lifecycle scripts, dependency confusion, and compromised or newly published packages, which can lead to supply-chain compromise in Node.js projects.

Core Features & Use Cases

  • Secure npm/pnpm/Bun install configuration: Provides hardened defaults such as disabling lifecycle scripts, blocking git-based dependencies, enforcing minimum release age, and applying pnpm trust policies.
  • Mitigate common supply-chain attack patterns: Covers dependency confusion prevention via scoped registries and publish configuration, and reduces risk from typosquatting via safer npx usage.
  • Security tooling integration: Recommends practical scanners and workflow tools (e.g., Snyk, npq, and Socket CLI) to identify vulnerabilities and issues before and during installs.

Quick Start

Configure your project to disable npm lifecycle scripts, block git dependencies, and enforce a minimum package release age using .npmrc (and then validate with an automated vulnerability scan before running installs).

Frequently Asked Questions about npm-security-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I disable npm lifecycle scripts to prevent supply chain attacks?

Disabling npm lifecycle scripts blocks malicious postinstall hooks from executing during package installs. Configure your project environment to restrict executable scripts, preventing supply chain compromise in Node.js workflows.

What is dependency confusion and how do I secure npm installs against it?

Dependency confusion is a supply chain attack targeting internal packages. Secure npm installs against it by enforcing scoped registries and strict publish configurations to ensure packages are fetched from trusted, verified sources.

How can I enforce a minimum release age for npm packages?

Enforce a minimum package release age by applying hardened trust policies in your package manager configuration. This mitigates risk from newly published compromised packages by delaying installs until they mature past initial publication.

Does this supply chain hardening approach work with pnpm and Bun?

Yes, this supply chain hardening applies to pnpm and Bun. It enforces trust settings, lockfile validation, and vulnerability scanning across Node.js package managers to secure CI/CD pipelines and local development environments.

What is the best way to run npx securely without typosquatting risks?

The best way to run npx securely is to use safer npx usage practices and integrate supply chain scanning tools. This reduces typosquatting risks by verifying package provenance and restricting execution before running scaffolding commands.

Why should I block git-based dependencies in my npm configuration?

Block git-based dependencies in your npm configuration to prevent supply chain compromise from unverified repository sources. Restricting installs to registry-published packages with provenance metadata ensures a hardened, trusted dependency tree.