JavaScript & Vite Supply-Chain Security Checklist (npm, Lockfiles & CI)
Defend JavaScript, TypeScript, and Vite apps against npm supply-chain attacks: disable install scripts, lock down Vite dev servers, pin GitHub Actions by SHA, and audit lockfile SBOMs.
// key takeaways
- Disable arbitrary lifecycle scripts by default (--ignore-scripts) in CI and developer workstations, explicitly allowlisting only packages that truly compile native addons.
- Never expose a Vite dev server (--host 0.0.0.0) directly to untrusted networks; enforce server.fs.strict and server.allowedHosts in vite.config.ts.
- Pin third-party GitHub Actions to full 40-character commit SHAs, enforce minimal GITHUB_TOKEN permissions, and switch npm publishing to OIDC Trusted Publishing / provenance.
- Enforce lockfile-only installs (--frozen-lockfile / npm ci), add release cooldown windows for non-security upgrades, and generate an SBOM on every release.
How JavaScript supply-chain compromises actually happen
Frontend and Node.js applications routinely pull 500 to 1,500 transitive packages from npm. Attackers rarely bother writing complex browser zero-days when a single phished maintainer token or hijacked GitHub Action lets them push a patch release containing a 12-line postinstall script that exfiltrates ~/.aws, ~/.npmrc, .env files, and CI secrets the instant npm install runs.
Effective JS supply-chain defense focuses on cutting blast radius across four choke points: package installation, local build/dev servers (like Vite), CI/CD release pipelines, and runtime browser boundaries (CSP + SRI).
Lock down npm, pnpm, and Bun installs against malicious lifecycle scripts
Lifecycle hooks (preinstall, install, postinstall) execute arbitrary shell commands during dependency installation — before tests run and before a human ever inspects a diff. Modern package managers give you strong guardrails if you turn them on explicitly:
# CI deterministic install without executing arbitrary package install scripts
npm ci --ignore-scripts && npm audit --audit-level=high
# Inspect which dependencies even request install scripts
npm query ":attr([scripts], [postinstall])"
# pnpm: enforce frozen lockfile + minimum release cooldown (in minutes, e.g. 2 days = 2880)
# In .npmrc or pnpm-workspace.yaml:
# ignore-scripts=true
# minimumReleaseAge=2880
pnpm install --frozen-lockfile
# Bun: trustedDependencies allowlist in package.json (Bun blocks unknown lifecycle scripts by default)
bun install --frozen-lockfileHardening Vite dev servers, middleware, and third-party plugins
Vite is built for fast local iteration, and historical Vite security advisories have repeatedly centered on filesystem boundary bypasses (server.fs.allow / @fs raw file serving), WebSocket CSRF, and overly permissive host headers when developers bind the dev server beyond localhost.
Keep Vite strictly on 127.0.0.1 during normal development, restrict server.allowedHosts if tunneling through a preview proxy, keep server.fs.strict: true, and treat every Vite plugin as full build-time code execution — because plugins run directly inside Node.js with access to your filesystem and environment variables.
import { defineConfig } from "vite";
export default defineConfig({
server: {
host: "127.0.0.1", // never expose 0.0.0.0 on untrusted Wi-Fi or public VMs
strictPort: true,
allowedHosts: ["localhost"],
fs: {
strict: true,
deny: [".env", ".env.*", "*.pem", "*.key", ".git/**"],
},
},
});Lock down GitHub Actions workflows and ship browser CSP + SRI
Supply-chain attackers increasingly target CI workflows instead of individual developer laptops because a single workflow hijack can steal npm publish tokens or poison production artifacts for thousands of downstream users.
In .github/workflows/*.yml, pin every third-party action to a full 40-character commit SHA (not mutable @v4 tags), declare permissions: { contents: read } at the workflow top level, eliminate long-lived NPM_TOKEN secrets in favor of OIDC Trusted Publishing with npm provenance attestations, and ship strict Content-Security-Policy headers + SHA-384 Subresource Integrity hashes on your built production app so a compromised external script cannot silently siphon session cookies.
// actionable engineering checklist
Block untrusted lifecycle scripts in CI and developer environments
Use npm ci --ignore-scripts, pnpm's allowlist, or Bun's trustedDependencies so random transitive packages cannot run shell code on install.
Harden vite.config.ts filesystem and host boundaries
Keep server.host bound to localhost, server.fs.strict enabled, and sensitive dotfiles explicitly denied.
Pin GitHub Actions to commit SHAs and scope GITHUB_TOKEN to read-only
Enable npm provenance / OIDC publishing and remove static long-lived registry tokens from repo secrets.
Generate an npm SBOM and enforce strict production CSP headers
Track /t/vite, /t/npm, /t/node, and /t/github-actions feeds so ecosystem advisories reach your team immediately.
// connected pwn.watch tools & live trackers
SBOM Viewer (npm / CycloneDX) →
Inspect resolved npm dependency trees, PURLs, and licenses locally without uploading private manifests.
CSP & SRI Header Generator →
Lock down script-src and generate SHA-384 Subresource Integrity hashes for third-party scripts.
Stack & Tag CVE Trackers
Security Hubs & Feeds
Frequently Asked Questions
- Does npm audit catch malicious supply-chain packages immediately?
- No — npm audit relies on published advisories, which often lag behind a freshly uploaded malicious version by hours. Combine --ignore-scripts, release cooldowns, lockfile diff review, and supply-chain incident feeds (/c/supply-chain) to catch attacks before advisories propagate.
- Why does Vite have CVEs if Vite is only a build tool?
- Vite's dev server runs an HTTP server with filesystem access during local development (and sometimes inside cloud dev boxes or misconfigured staging servers). Vulnerabilities in its dev middleware can expose source code or .env files to malicious browser tabs or network peers.
- Is pinning package versions in package.json enough without a lockfile?
- No. Pinning direct dependencies in package.json still leaves transitive sub-dependencies floating on caret (^) ranges. Always commit your lockfile and install with frozen-lockfile mode in CI.
Get an email when a new major security incident drops. No spam, unsubscribe any time.