Skip to content

zeemscript/shieldx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

13 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ›ก๏ธ ShieldX

ShieldX is a blazing-fast CLI tool to compare, sync, validate, audit, and scan your environment/config files. It helps developers avoid missing variables, catch hardcoded secrets in code, and keep configs consistent across environments.

Short. Secure. Smart. โ€” That's ShieldX.

npm version License: MIT CI/CD


๐Ÿš€ Features

  • ๐Ÿ” Compare: Check differences between .env files (e.g., .env vs .env.production)
  • โšก Generate: Create a .env.example automatically from an existing .env
  • ๐Ÿ›ก๏ธ Scan: Detect hardcoded secrets (API keys, tokens, DB URLs) with severity levels
  • ๐Ÿ”ง Fix: Interactively move hardcoded secrets to .env and replace them in code
  • โœ… Validate: Ensure .env files have all required variables
  • ๐Ÿ”Ž Audit: Run a full security health check with a scored report
  • ๐Ÿ“Š JSON Output: Perfect for CI/CD pipelines
  • ๐Ÿšซ Smart Ignoring: Use .shieldxignore to skip files
  • ๐ŸŽฏ Exit Codes: Non-zero exit on issues for CI/CD integration
  • ๐Ÿ“ฆ Lightweight: Zero bloat
  • ๐Ÿ”’ Security-first: 30+ secret pattern detectors with severity levels

๐Ÿ“ฆ Installation

Use it instantly with npx (no install required):

npx shieldx compare .env .env.example

Or install globally:

npm install -g shieldx

๐Ÿ–ฅ๏ธ Usage

1. Compare two .env files

Compare files and see missing/extra variables:

shieldx compare .env .env.production

Options:

  • -j, --json - Output in JSON format
  • -v, --verbose - Show detailed output

Example output:

๐Ÿ“Š Comparison: .env vs .env.production

โŒ Missing in .env.production (2):
   - SECRET_KEY
   - API_TOKEN

โš ๏ธ  Extra in .env.production (1):
   + NEW_FEATURE_FLAG

Total: 10 keys in .env, 9 keys in .env.production

CI/CD Integration:

# Exit code 1 if files don't match
shieldx compare .env .env.example --json > comparison.json

2. Generate .env.example

Create a template file with keys only (no sensitive values):

shieldx generate .env

Options:

  • -o, --output <file> - Custom output path (default: .env.example)
  • -f, --force - Overwrite existing file
  • -j, --json - Output in JSON format
  • -v, --verbose - List all generated keys

Examples:

# Generate with custom output
shieldx generate .env -o .env.template

# Force overwrite
shieldx generate .env --force

# See what keys were generated
shieldx generate .env --verbose

3. Scan project for hardcoded secrets

Detect hardcoded API keys, passwords, tokens, and more:

shieldx scan ./src

Options:

  • -j, --json - Output in JSON format for parsing
  • -v, --verbose - Show skipped files
  • -q, --quiet - Only show errors

Security Patterns Detected:

  • โœ… Stripe API keys (live & test)
  • โœ… AWS credentials
  • โœ… GitHub tokens
  • โœ… Google API keys
  • โœ… Database connection strings
  • โœ… JWT tokens
  • โœ… Private keys (RSA, PEM, SSH)
  • โœ… OAuth tokens (Slack, Facebook, Google)
  • โœ… Bearer tokens
  • โœ… And 20+ more patterns!

Severity Levels:

  • ๐Ÿ”ด CRITICAL - Private keys, credentials with immediate risk
  • ๐ŸŸ  HIGH - API keys, tokens, passwords
  • ๐ŸŸก MEDIUM - Session IDs, JWTs
  • ๐Ÿ”ต LOW - Potential secrets, long strings

Example output:

๐Ÿ” Scanning ./src for hardcoded secrets...

๐Ÿšจ [HIGH] Stripe Live Key in src/payment.js:15
    const key = "sk_live_abcd1234..."
    ๐Ÿ’ก Move this to .env file

โš ๏ธ  Security Report:
   Total issues: 3
   Files scanned: 47

 CRITICAL: 1
   High: 2

Use .shieldxignore: Create a .shieldxignore file to skip certain paths:

# ShieldX Ignore Patterns
**/test/**
*.test.js
docs/

4. Validate required variables

Ensure .env files have all required keys:

shieldx validate .env --keys "DATABASE_URL,API_KEY,SECRET"

Options:

  • -k, --keys <keys> - Comma-separated required keys
  • -c, --config <file> - Load required keys from file
  • -j, --json - Output in JSON format
  • -v, --verbose - Show all present keys

Using a config file: Create required-keys.txt:

DATABASE_URL
API_KEY
SECRET_KEY

Then run:

shieldx validate .env --config required-keys.txt

Example output:

๐Ÿ” Validating .env

โŒ Missing 2 required variable(s):

  โœ— API_KEY
  โœ— SECRET_KEY

๐Ÿ’ก Add the missing variables to .env

5. Fix hardcoded secrets

Interactively move secrets from your code to .env:

shieldx fix ./src

Options:

  • --auto - Move all High/Critical secrets automatically
  • --dry-run - Preview changes without modifying files
  • --env-file <file> - Target .env file (default: .env)

Example: ShieldX will find a secret: const KEY = "sk_live_12345";

And replace it with: const KEY = process.env.STRIPE_LIVE_KEY;

While adding the following to your .env: STRIPE_LIVE_KEY="sk_live_12345"


6. Full Security Audit

Run a comprehensive security health check across your entire project:

shieldx audit

Options:

  • -j, --json - Output in JSON format for CI/CD
  • -s, --strict - Fail on any issue (even warnings)
  • -d, --dir <path> - Directory to scan (default: .)
  • --env-file <file> - Path to .env file (default: .env)

What it checks:

Check Description
๐Ÿ”’ Gitignore Safety Ensures .env is in .gitignore
๐Ÿ“„ Env Files Exist Verifies .env and .env.example are present
๐Ÿ”„ Env Sync Compares .env vs .env.example for drift
๐Ÿ›ก๏ธ Secret Scan Scans codebase for hardcoded secrets
๐Ÿ“‹ Empty Values Flags .env keys with no value

Example output:

  โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
  โ•‘   ๐Ÿ›ก๏ธ  ShieldX Security Audit          โ•‘
  โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚  CHECK RESULTS                                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ โ— PASS  ๐Ÿ”’ Gitignore Safety                           โ”‚
โ”‚         .env is protected in .gitignore                โ”‚
โ”‚ โ— PASS  ๐Ÿ“„ Env Files Exist                             โ”‚
โ”‚         .env and .env.example both present              โ”‚
โ”‚ โ— WARN  ๐Ÿ”„ Env Sync                                    โ”‚
โ”‚         2 keys not in .env.example                      โ”‚
โ”‚ โ— FAIL  ๐Ÿ›ก๏ธ  Secret Scan                                โ”‚
โ”‚         3 issue(s) found (1 critical, 2 high)           โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  SECURITY SCORE                                        โ”‚
โ”‚  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘  C 55/100              โ”‚
โ”‚  NEEDS ATTENTION                                       โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

CI/CD Integration:

# Fail pipeline on any critical/high issues
shieldx audit --json > audit-report.json

# Strict mode: fail on ANY issue
shieldx audit --strict

๐Ÿ”ง Advanced Usage

CI/CD Integration

ShieldX returns exit code 1 on issues, perfect for CI/CD:

# GitHub Actions example
- name: Validate environment
  run: |
    shieldx compare .env.example .env.production --json
    shieldx scan ./src
    shieldx validate .env.production --keys "DATABASE_URL,API_KEY"

Pre-commit Hook

Add to .git/hooks/pre-commit:

#!/bin/bash
shieldx scan ./src --quiet
if [ $? -ne 0 ]; then
  echo "โŒ Secrets detected! Fix them before committing."
  exit 1
fi

JSON Output for Automation

All commands support --json flag:

# Get JSON output for parsing
shieldx scan ./src --json > security-report.json

# Parse with jq
shieldx scan ./src --json | jq '.issuesFound'

๐Ÿ“… Roadmap

  • Compare .env files
  • Generate .env.example
  • Scan for secrets with severity levels
  • Validate required keys
  • JSON output for CI/CD
  • .shieldxignore support
  • Exit codes for automation
  • GitHub Actions integration
  • Auto-fix suggestions
  • Full project security audit with scoring
  • Sync configs across environments
  • VSCode plugin integration
  • AI-powered secret detection (v2)
  • Encrypt/decrypt .env files

๐Ÿ› ๏ธ Development

Clone and run locally:

git clone https://github.com/zeemscript/shieldx.git
cd shieldx
npm install
npm link

Run tests:

npm test
npm run test:watch

Now you can run:

shieldx compare .env .env.example

๐Ÿงช Testing

ShieldX includes a comprehensive test suite:

# Run all tests
npm test

# Run with coverage
npm test -- --coverage

# Watch mode
npm run test:watch

๐Ÿค Contributing

Contributions, issues, and feature requests are welcome!

  1. Fork the repo
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Check issues for ideas!


๐Ÿ“œ License

MIT ยฉ 2025 zeemscript


๐Ÿ’ก Tips

Best Practices:

  • โœ… Run shieldx scan before every commit
  • โœ… Use shieldx validate in deployment pipelines
  • โœ… Keep .env.example updated with shieldx generate
  • โœ… Never commit .env files (add to .gitignore)
  • โœ… Use .shieldxignore for test fixtures

Common Workflows:

# Setup new project
shieldx generate .env
git add .env.example

# Before deploying
shieldx validate .env.production --keys "DATABASE_URL,API_KEY"
shieldx compare .env.example .env.production

# Security audit
shieldx scan ./src --verbose

Made with โค๏ธ by developers, for developers.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors