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

Answers / Install-time attacks. Breadcrumb: [Home](https://osty.dev/) / [Answers](https://osty.dev/answers) / Block npm postinstall secret theft

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.

Table: Controls against install-time secret theft and what each one misses

| Control | What it stops | What it misses |
| --- | --- | --- |
| `npm ci --ignore-scripts` | Lifecycle 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 cooldown | Versions too new to have been reported. | A compromise nobody reports within the window. |
| Static package analysis | Install scripts, obfuscation and network calls that look suspicious. | Code that reads as benign but exfiltrates when executed. |
| Short-lived, scoped CI credentials | Long-term damage from a stolen token. | The theft itself. |
| Osty sandbox verdict with `osty verify` | Releases 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:

```bash
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 install:

```bash
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.

## Related pages

- [Guard](https://osty.dev/guard): Pre-install supply-chain firewall: Firecracker honey-secret detonation, artifact-vs-Git diffs, behavior baselines, VPC dependency-confusion defense and `osty-proxy`.
- [GitHub Actions integration](https://osty.dev/integrations/github-actions): Add the `osty verify` gate ahead of the install step in a workflow.
- [Best supply-chain firewalls](https://osty.dev/compare/best-supply-chain-firewalls): Install-time gates compared on detonation, outage behavior and lineage.
- [Benchmarks](https://osty.dev/benchmarks): The 15 adversarial scenarios `a01` to `a15` and the TLA+ models that Osty's code is held to.

## 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.

Get a free X-Ray: https://osty.dev/xray

Written by Osty Engineering. Published 2026-11-29. Updated 2026-11-29.

Canonical: https://osty.dev/answers/block-npm-postinstall-secret-exfiltration-ci
