Skip to main content

Overview

envtrap’s detection engine has two stages:
  1. Startup: Load active secret candidates from the environment
  2. Runtime: Scan intercepted content for exact matches of those candidates

Stage 1 — Loading Active Secrets

When envtrap run starts, it builds an in-memory secret registry by scanning two sources:

Source 1: process.env

Every environment variable present in the current shell is evaluated. Variables in a built-in blocklist of non-sensitive system variables are skipped automatically:
For each remaining variable, the value is tested against the looksLikeSecret gate (see below).

Source 2: .env file

If a .env file exists (or a custom path was provided via --env-file), it is parsed with dotenv. Variables that are already loaded from process.env are not duplicated — process.env takes precedence.

Stage 2 — The looksLikeSecret Gate

Every candidate value must pass this filter before being registered:

Built-in Deterministic Patterns

These patterns always match regardless of entropy score. They are compiled once at startup:

Shannon Entropy Analysis

Shannon entropy measures character randomness — the more evenly distributed the characters, the higher the score (range 0 to 8 bits per character). Configure the entropy gate in envtrap.json:
Raise threshold to 4.04.5 in environments with many short config values to reduce false positives. Lower it only if you need to protect short secrets.

Runtime Scanning

During execution, every intercepted payload is scanned for exact substring matches of all registered secret values. There are no regex scans at runtime — only direct string inclusion checks. This makes scanning extremely fast even for large payloads.

1 MB Backpressure Cap

To protect the Node.js event loop, content chunks larger than 1 MB are clamped — only the first 1 MB is scanned. Secrets almost always appear at the beginning of HTTP headers, log lines, or JSON payloads.

TTL Deduplication Cache

To prevent alert flooding, duplicate detections of the same secret + channel combination within a 1.5-second window are silently suppressed. Only the first occurrence within the window triggers an alert and is recorded.

Secret Fingerprinting (AI-Safe Redaction)

envtrap never logs the raw value of a secret. Instead, it prints a SHA-256 fingerprint:
This means:
  • Terminal output is safe to share or paste into AI coding tools
  • The fingerprint uniquely identifies the secret without exposing it
  • Consistent hashing allows you to correlate the same secret across multiple channels

Leak Report File

After the process exits, envtrap writes .envtrap-report.json to the current working directory: