Skip to content

zeemscript/shieldx

Repository files navigation

πŸ›‘οΈ ShieldX

ShieldX is a blazing-fast CLI tool to compare, sync, validate, 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
  • βœ… Validate: Ensure .env files have all required variables
  • πŸ“Š 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: 28+ 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

πŸ”§ 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
  • 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

Releases

No releases published

Packages

No packages published