Sentinel · security scanner
dotenv-sentinel
Validate .env files against .env.example or a schema, catch weak and default secrets, and keep .env files out of git, including its history.
npm i -D @mrlouiswright/dotenv-sentinelPublished to GitHub Packages: add @mrlouiswright:registry=https://npm.pkg.github.com to .npmrc first (installing needs a token with read:packages).
What it checks
- Against
.env.example(or.env.sample,.env.template,.env.dist,<file>.example, or--example): missing variables, undocumented extras. - Against a schema(
--schema env.schema.json): required, empty, type (string,number,integer,boolean,url,email,port,json,enum),pattern,enum,minLength,secret. - Secretsvariables named like secrets (
*_SECRET,*_TOKEN,*_PASSWORD,API_KEY,APP_KEY…) holding well-known defaults or placeholders, or shorter than--min-secret-length(16). Example files holding real-looking credentials (AWS, GitHub… - Production files(
*prod*):DEBUG=true,NODE_ENV=development,http://URLs to remote services. - Syntaxinvalid lines, unterminated quotes, duplicate keys, unquoted values with spaces,
${VAR}references to undefined variables. - Gittracked env files with values (
committed-env), env files not matched by.gitignore, and env files added in any commit of any branch (env-in-history; rotate those secrets).
Quick usage
CLI
npx dotenv-sentinel # current directory, including git checks
npx dotenv-sentinel apps/api --schema apps/api/env.schema.json
npx dotenv-sentinel .env.production --example .env.example --fail-on medium
API
import { check, lintEnv, parseEnv } from 'dotenv-sentinel';
const report = check(['.'], { schema: 'env.schema.json' });
Every option is documented in the dotenv-sentinel docs.
CI / GitHub Action
permissions:
contents: read
security-events: write # only for the SARIF upload
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with: { persist-credentials: false }
- uses: MrLouisWright/dotenv-sentinel@v1
with:
targets: '.'
fail-on: high
sarif: dotenv-sentinel.sarif
- uses: github/codeql-action/upload-sarif@v3
if: always()
with: { sarif_file: dotenv-sentinel.sarif }