npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

env-vault-guard

v1.0.0

Published

Compile-time and runtime environment variable auditor and leak prevention shield.

Readme

🛡️ env-vault-guard

A compile-time and runtime environment variable auditor and leak prevention shield for JavaScript/TypeScript projects. It protects your application against accidental exposure of secrets (like database URLs, private API keys, JWT secrets) in client-side bundles, unapproved logging destinations, and outbound HTTP requests.


Features

  • 🧬 Runtime Proxy Guard: Intercepts process.env lookups. Automatically errors if secret keys are accessed in client-side/browser environments.
  • 🔍 Zero-Config Auto-detection: Automatically registers keys containing keyword patterns like SECRET, KEY, TOKEN, PASSWORD, DATABASE, PASS, AUTH, PWD, DSN as secrets.
  • 📡 Leak Prevention Interceptors: Monkey-patches outbound network calls (fetch, XMLHttpRequest, Node.js http/https requests) and logging utilities (console.*, process.stdout.write, process.stderr.write) to detect and block secret data leakages.
  • 🛠️ Customizable Actions: Configure individual or global actions for detected leaks:
    • throw: Terminate the operation immediately with a security error.
    • warn: Report the leak with a safe console warning without exposing the actual secret value.
    • mask: Replace secret values in payloads/logs in-place with [REDACTED_SECRET_KEY] and continue safely.
  • 🔗 Whitelisted Destinations: Permit specific secrets to be sent to designated domains or API endpoints (e.g. Stripe credentials to api.stripe.com).
  • 🏗️ Compile-time Bundler Plugins: Vite, Rollup, and Webpack plugins that fail build steps if secret references or literal secret values are discovered inside your frontend bundle.

Installation

npm install env-vault-guard --save-dev

Quick Start (Zero Config)

Simply import and activate the guard at the absolute entry point of your application (before any other code or HTTP requests are made):

import { guardEnv } from 'env-vault-guard';

// Initializes the shield and auto-detects secrets in process.env
guardEnv();

Detailed Usage & Configuration

Runtime Configuration

You can customize exactly which variables are secrets, public-facing, whitelisted destinations, and the default actions to take on detection:

import { guardEnv } from 'env-vault-guard';

guardEnv({
  // Specify explicit secrets and customized configurations
  secrets: {
    STRIPE_SECRET_KEY: {
      action: 'mask', // Redact this secret in logs instead of throwing
      allowedUrls: ['https://api.stripe.com'], // Only allow fetch/http to Stripe API
    },
    DATABASE_URL: {
      action: 'throw', // Always block database URL leaks
      allowedUrls: [], // Cannot be sent over any network request
    }
  },
  
  // Variables explicitly allowed anywhere
  public: [
    'NEXT_PUBLIC_API_URL',
    'VITE_APP_ENV'
  ],

  // Default action when a leak is detected: 'throw' | 'warn' | 'mask'
  defaultAction: 'throw',

  // Custom callback for telemetry/alerts
  onLeakDetected: (context) => {
    console.warn(`[Audit Log] Leak attempted! key=${context.key} sink=${context.sink}`);
    // return 'mask'; // Optionally override default action dynamically
  }
});

Compile-time Bundler Plugins

Prevent secrets from being packaged into client bundles at compile-time by adding bundler plugins to your build configs.

⚡ Vite / Rollup

Add the plugin to your vite.config.ts or rollup.config.js:

import { defineConfig } from 'vite';
import { envVaultGuardVite } from 'env-vault-guard';

export default defineConfig({
  plugins: [
    envVaultGuardVite({
      // Explicit secrets to block, defaults to auto-detected secrets from .env
      secrets: ['STRIPE_SECRET_KEY', 'JWT_SECRET'],
      // Exclude files from source reference scanning (output chunks are always scanned)
      excludeFiles: [/node_modules/],
      // Fail the build if a leak is detected (otherwise warns)
      errorOnLeak: true,
    })
  ]
});

📦 Webpack

Add the plugin to your webpack.config.js:

const { EnvVaultGuardWebpack } = require('env-vault-guard');

module.exports = {
  plugins: [
    new EnvVaultGuardWebpack({
      secrets: ['STRIPE_SECRET_KEY', 'DATABASE_URL'],
      errorOnLeak: true,
    })
  ]
};

Development and Testing

Run unit tests using Vitest:

npm run test

Build the package (generates both CommonJS and ESM outputs under dist/):

npm run build

License

MIT