Skip to content

Answers / Install-time attacks

How do you block a malicious npm postinstall script from stealing CI secrets?

Gate the lockfile before npm ci runs, using a verdict that came from executing the install rather than reading it. Osty (osty.dev) detonates each new npm and PyPI release in a Firecracker microVM seeded with honey secrets, and osty verify fails CI on any CONFIRMED_MALICIOUS or unvetted version, as benchmark scenario a03 demonstrates.

Written by Osty EngineeringPublished Updated

Controls against install-time secret theft and what each one misses
ControlWhat it stopsWhat it misses
npm ci --ignore-scriptsLifecycle scripts in that job.Payloads that run on first require during tests or build steps, and packages that need install scripts to work.
Release-age cooldownVersions too new to have been reported.A compromise nobody reports within the window.
Static package analysisInstall scripts, obfuscation and network calls that look suspicious.Code that reads as benign but exfiltrates when executed.
Short-lived, scoped CI credentialsLong-term damage from a stolen token.The theft itself.
Osty sandbox verdict with osty verifyReleases that leaked a honey secret during install or first import (a03), and unvetted versions under FAIL_CLOSED.Ecosystems outside npm and PyPI detonation, and private packages Plane 1 never sees.
Gate a lockfile on signed detonation verdicts
osty verify --lockfile package-lock.json --json

Where the secret leaves the runner

npm runs preinstall, install and postinstall scripts with the job's environment, so every variable the CI step can read is in reach: cloud keys, GITHUB_TOKEN, registry tokens. In scenario a03, a package's postinstall hex-encodes AWS_SECRET_ACCESS_KEY into DNS labels under evil.test and posts a base64 GITHUB_TOKEN to an HTTPS collector. The job then exits cleanly, and no image ever reaches a cluster.

A scanner that runs after the install, or a runtime sensor in production, sees nothing. The only point where this attack can be stopped is before the package manager executes the release.

Put the gate before the install step

Run osty verify as its own step ahead of npm ci. It reads only the local edge cache, needs no network access, and exits non-zero when a dependency is blocked or has no verified verdict under a FAIL_CLOSED policy.

Validate policy, gate the lockfile, then installbash
osty policy validate .osty/policy.yaml
osty verify --lockfile package-lock.json --policy .osty/policy.yaml --cache /var/lib/osty/edge-cache.sqlite --json
npm ci

What the sandbox records

Plane 1 installs and imports the release inside a Firecracker KVM microVM holding fake cloud keys, registry tokens and SSH keys, behind a DNS and TLS sinkhole. If a planted secret appears in captured traffic, the version is CONFIRMED_MALICIOUS with the forensic trace attached, and osty-proxy returns 403 with an Ed25519-signed justification.

Each release is also compared with its predecessor. In scenario a04, behavior repeated from v1.0.0 produces an empty delta and stays CLEAN, while a new read of ~/.ssh/id_rsa in v1.0.2 escalates. That keeps packages that legitimately call the network from paging anyone.

Where this approach stops

  • Detonation covers npm and PyPI. Go, Cargo, Maven and OCI pulls get proxy and verdict checks without detonation, and Socket's static analysis reaches more ecosystems, including RubyGems and NuGet.
  • Plane 1 sees public releases only. Your private packages are not detonated.
  • A payload that waits for conditions the sandbox does not reproduce can stay dormant during detonation. Keep --ignore-scripts where your build allows it, and scope CI credentials to the job.
  • The in-VPC osty-proxy is part of Enterprise. On Free and Team, the gate is osty verify in CI.

Frequently asked questions

Is npm ci --ignore-scripts enough on its own?

It stops lifecycle scripts in that job, which is worth doing. It does not stop code that runs when a test or build step first imports the package, and some packages fail without their install scripts.

Does osty verify need network access?

No. It reads the local edge cache, which osty-edge fills, or osty airgap import fills in an air gap.

What happens to a brand-new version with no verdict yet?

Under FAIL_CLOSED, osty verify holds it with PULL_DECISION_QUARANTINE_HOLD until a verified verdict reaches the cache.

See what is actually exposed in 10 minutes

Connect a read-only GitHub App and cloud role. Osty installs nothing in your environment and writes nothing to your repositories. The report strips out backport and reachability noise before your team or coding agents patch it, and flags stale deploys and unowned workloads.