Most teams rely on a CVE scanner in CI to secure npm and Python dependencies.
That workflow misses two attack classes that execute before any advisory exists: compromised packages published minutes before npm ci runs, and hallucinated package names ("slopsquatting") registered by attackers targeting AI coding assistants.
When a malicious postinstall hook executes during npm install or npm ci, it runs with the full privileges of the developer laptop or CI runner.
It can read .env files, ~/.ssh, ~/.aws/credentials, or GITHUB_TOKEN and exfiltrate them over DNS or HTTPS during the install step before your test suite even starts.
By the time a CVE or GHSA advisory is published hours later, those credentials are already compromised.
Comparison of pre-install controls
| Control | Stops brand-new postinstall malware | Stops slopsquatting | Breaks native addons (sharp, esbuild) | Works offline / air-gapped |
|---|---|---|---|---|
| CVE-only scanner (Trivy, Grype, OSV-Scanner) | No (requires prior advisory) | No | No | Partial (CVE DB sync) |
| Static AST heuristics (GuardDog, Socket) | Partial (bypassed by obfuscation) | Partial | No (can raise noisy alerts) | GuardDog yes; Socket SaaS no |
Global ignore-scripts=true | Yes | Partial (blocks install hooks, not import-time code) | Yes (requires manual allowlist) | Yes |
| Release-age cooldown (3-7 days) | Yes for auto-PRs; not manual installs | No (attacker ages package) | No | Yes |
| Behavioral detonation + signed lockfile gate | Yes (observes real egress and secret reads) | Yes | No (differential baseline) | Yes (signed local cache) |
Four pre-install controls for CI and laptops
1. Commit lockfiles, disable scripts where possible, and enforce release-age cooldowns
Never run bare npm install in CI.
Use npm ci --ignore-scripts on repositories that do not compile native addons, and set a release-age cooldown so automated dependency bots do not pull brand-new releases immediately.
In .npmrc for pure-JS repos:
ignore-scripts=true In renovate.json to enforce a 5-day cooldown across ecosystems (with a manual override path for CISA KEV fixes):
{ "minimumReleaseAge": "5 days" } 2. Isolate install steps from production secrets
Keep cloud deploy keys and registry publish tokens out of the job that runs npm ci or pip install.
In GitHub Actions, pin build and test jobs to permissions: contents: read and move OIDC cloud credentials into a separate deployment job that consumes only the built artifact:
jobs: test: runs-on: ubuntu-latest permissions: contents: read steps: - uses: actions/checkout@v4 - run: npm ci - run: npm test 3. Gate lockfiles against behavioral detonation verdicts before install
When your repository depends on native packages (esbuild, sharp, sqlite3) and cannot set ignore-scripts=true globally, static heuristics alone create noisy alerts while still missing obfuscated payloads.
Behavioral detonation installs each new package release inside an ephemeral microVM sandbox (such as Firecracker) seeded with planted honey-secrets (fake AWS keys, fake .npmrc tokens, fake SSH keys) and records actual DNS queries, HTTPS egress, and filesystem reads.
To avoid false positives on legitimate packages that already compile native code, each release's trace is diffed against the previous clean version (a differential baseline) so only new suspicious behavior escalates.
Consider a package-lock.json that includes a package with "hasInstallScript": true:
{ "node_modules/evil-postinstall-fixture": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/evil-postinstall-fixture/-/evil-postinstall-fixture-1.2.3.tgz", "hasInstallScript": true } } With the Apache 2.0 osty CLI and osty-dev/osty-action, you can gate package-lock.json, uv.lock, requirements.txt, go.sum, and go.mod against Ed25519-signed verdicts before npm ci executes:
name: supply-chain-gate on: pull_request: permissions: contents: read jobs: verify: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - id: osty uses: osty-dev/osty-action@v1 with: lockfile: package-lock.json cache: .osty/edge-cache.sqlite - run: npm ci osty verify reads Ed25519-signed verdicts from a local SQLite cache (or an imported osty airgap export archive), makes zero outbound network calls during verification, requires no SaaS API token or write permissions, and fails closed if a package has no signed verdict.
4. Guard coding agents against slopsquatting
AI coding assistants (Claude Code, Cursor, Codex, Antigravity) sometimes invent plausible package names that do not exist yet.
Attackers monitor common LLM hallucinations and register those names on npm and PyPI with credential-stealing install scripts.
Two rules close that gap:
- Require coding agents to run a lockfile gate (
osty verify --lockfile package-lock.json --json) before installing any newly added dependency. - Instruct the agent to treat a non-zero exit code as a hard stop instead of weakening
.osty/policy.yaml. The open-sourceosty-securityAgent Skill codifies those rules (npx skills add osty-dev/agent-skills).
Reproduce locally on a poisoned lockfile fixture
You can test the fail-closed lockfile gate locally in under a minute using the public benchmark repository (osty-dev/supply-chain-benchmark):
brew install osty-dev/tap/osty git clone https://github.com/osty-dev/supply-chain-benchmark.git cd supply-chain-benchmark scripts/verify-fixtures.sh fixtures/package-lock.json contains benign-fixture@2.0.0 alongside evil-postinstall-fixture@1.2.3.
With no signed verdict cached, osty verify exits 1 and quarantines both packages; once a signed intelligence archive is imported, evil-postinstall-fixture@1.2.3 is blocked as SUPPLY_CHAIN_VERDICT_CONFIRMED_MALICIOUS with the forensic reason in structured JSON.
Full CLI reference and threat model details live at osty.dev/guard and github.com/osty-dev/osty.
