The security_check.sh script is a security tool that scans your codebase to detect and prevent accidentally committing sensitive credentials and API keys to version control.
Scans tracked files for:
- MongoDB connection strings with embedded credentials.
- API keys and secrets in various formats.
- Variables ending in
_API_KEY,_SECRET,_PASSWORD,_TOKEN, etc.
- Variables ending in
Note: The script respects .gitignore and only checks files that are tracked by git or staged for commit.
Verifies that essential security entries are present and active in .gitignore:
.env.venvenv/venv/ENV/env.bak/venv.bak/
Warns if entries are missing or commented out.
Before running the script, ensure it has execute permissions:
chmod +x security_check.sh# Basic check
./security_check.sh
# Verbose output (shows masked credentials)
./security_check.sh --verbose
# or
./security_check.sh -v# Basic check
make security_check
# Verbose output
make security_check_verbose- Pattern Matching: Uses regex patterns to detect credential patterns in code
- File Filtering: Only checks files tracked by git (respects
.gitignore) - Reporting: Provides clear error messages if issues are found
🔒 Running security check for credentials and API keys...
✅ All security checks passed!
🔒 Running security check for credentials and API keys...
❌ SECURITY ISSUE FOUND:
File: ./backend/your_script.py
Matches:
Line 8 (API Key/Secret): # KEY="****"
🚨 SECURITY CHECK FAILED!
⚠️ Credentials or API keys detected in source files.
⚠️ Please remove credentials and use environment variables instead.
🔒 Running security check for credentials and API keys...
❌ .gitignore security issues found:
Missing entries:
- .env
- venv/
Commented out entries (should be active):
- env.bak/
🚨 SECURITY CHECK FAILED!
⚠️ .gitignore file is missing essential entries or has them commented out.
- Use environment variables:
process.env.MONGODB_URIoros.getenv('MONGODB_URI') - Store secrets in
.envfiles: Already in.gitignore - Never commit credentials: Even in comments or test files
- Keep
.gitignoreupdated: Ensure all environment-related entries are active
The script checks these essential .gitignore entries by default. To add more entries, edit the essential_entries array in security_check.sh:
local essential_entries=(
".env"
".venv"
# Add your custom entries here
)Q: Script is too strict, catching false positives?
- The script only checks tracked files. Ensure sensitive files are in
.gitignore - Use
--verboseto see exactly what's being flagged
Q: Want to check before committing?
- Run
./security_check.shmanually before staging files - Or use
make security_checkfor convenience
security_check.sh- Main security check scriptmakefile- Containssecurity_checkandsecurity_check_verbosetargets
To automatically run the security check before each commit, you can set up a git pre-commit hook:
- Create
.git/hooks/pre-commit:
#!/bin/bash
REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
"$REPO_ROOT/security_check.sh"
exit $?- Make it executable:
chmod +x .git/hooks/pre-commitOnce configured, the security check will run automatically on git commit and block commits if issues are found.
Note: This feature is not currently implemented in the repository but can be added manually as shown above.