Skip to main content
envtrap

Prerequisites

  • Node.js 18.0.0 or later (ESM customization hooks require Node 18+)
  • npm or pnpm

Step 1 — Install

Install envtrap globally:
Or use via npx without installing:
Or install as a dev dependency:

Step 2 — Run your app through envtrap

Prefix your existing start command with envtrap run:
That’s it. envtrap now:
  • Starts a native-RSA in-memory MITM TLS proxy and routes all outbound HTTP/HTTPS through it
  • Automatically sets NO_PROXY for loopback addresses so local Redis, Docker, and sidecar services are never proxied
  • Scans stdout and stderr streams for secrets in real time
  • Intercepts all child_process spawns to check if secrets are passed via options.env
  • Intercepts all DNS lookups for exact secret matches and high-entropy subdomain patterns
  • Wraps process.env to detect and broadcast runtime-rotated credentials to the ESM loader thread

Step 3 — Read the startup output

On every run, envtrap prints a startup banner and configuration summary to stderr:
When a leak is detected:
After your app exits, envtrap prints a summary:

Step 4 — (Optional) Create a config file

Create envtrap.json in your project root for fine-grained control:
Domains listed in exclusions.domains are automatically added to NO_PROXY so they also bypass the MITM proxy without any extra configuration.
Validate your config:
Use "warn" on all channels during development to observe traffic patterns. Switch network and dns to "block" before deploying to production.

Step 5 — Add to package.json scripts

What Happens on Detection?

Framework Compatibility

envtrap hooks Node.js core modules, not your application layer — so it works with any framework:
Next.js and other frameworks that compile or bundle client-side code are covered only for server-side execution. Browser runtime code is not in scope.

Next Steps

How It Works

Deep-dive into MITM proxy, ESM hooks, and CJS patching.

Configuration

Full reference for every envtrap.json field.

Attack Surfaces

Understand the five channels envtrap monitors.

CLI Reference

All CLI commands and flags.