5.1 KiB
5.1 KiB
Security Policy and Best Practices
Credential Management
Current Security Measures
- Environment variables for sensitive credentials (Discord token, API keys)
- Git pre-commit hooks to prevent credential exposure
- .gitignore rules for sensitive files
- Test environment using mock credentials
Cleaning Git History of Credentials
If you need to remove sensitive data from git history, follow these steps carefully:
Prerequisites
- Install git-filter-repo:
# macOS
brew install git-filter-repo
# Linux
pip3 install git-filter-repo
# Windows
pip install git-filter-repo
- Create a backup of your repository:
cp -r your-repo your-repo-backup
Cleaning Process
- Prepare Your Repository
# Change to your repository directory
cd your-repo
# Create a fresh clone (recommended for cleaning)
git clone --mirror git@github.com:username/your-repo.git repo-mirror
cd repo-mirror
- Create a Pattern File
Create a file named
patterns.txtcontaining patterns of credentials to remove:
# Discord tokens (common patterns)
['"](N[a-zA-Z0-9]{23}\.[a-zA-Z0-9]{6}\.[a-zA-Z0-9_-]{27})['"]
# API keys
['"](sk-[a-zA-Z0-9]{48}|pk-[a-zA-Z0-9]{48})['"]
# Generic tokens/keys
['"]([a-zA-Z0-9_-]{32,64})['"]
# Add more patterns as needed
- Clean the Repository
# Remove files containing credentials
git filter-repo --invert-paths --paths-from-file patterns.txt
# Clean all refs
git reflog expire --expire=now --all
git gc --prune=now --aggressive
- Verify the Cleaning
# Check for any remaining credentials
git log -p | grep -i -f patterns.txt
- Update Remote Repository
# Force push all branches
git push origin --force --all
# Force push all tags
git push origin --force --tags
- Update All Local Clones For each local clone of the repository:
# In each local clone
git fetch origin
git reset --hard origin/main # or your default branch
Important Notes
- This process is irreversible and rewrites git history
- All collaborators must re-clone the repository after cleaning
- Immediately revoke and rotate any exposed credentials
- Old credentials may still exist in:
- GitHub Actions logs
- Issue comments
- Pull request descriptions
- Cached views on GitHub
- Other users' local clones
Setting Up Environment Variables
- Create a
.envfile in the project root (this file is automatically ignored by git) - Add your credentials using this format:
DISCORD_TOKEN=your_discord_token_here
OPENROUTER_API_KEY=your_openrouter_api_key_here
- Never commit the
.envfile to version control
Development Guidelines
DO
- Use environment variables for all sensitive data
- Keep the
.envfile secure and local to your development environment - Use mock/fake data for tests
- Review code for credential exposure before committing
- Use the pre-commit hook to catch potential credential leaks
DON'T
- Hardcode credentials in source code
- Commit
.envfiles to version control - Share credentials through insecure channels
- Disable the pre-commit hook
- Log sensitive information
Secure Credential Storage
For production environments:
- Use a secrets management service or secure environment variable storage
- Rotate credentials regularly
- Use the principle of least privilege
- Monitor for unauthorized access
- Keep backup copies of credentials in a secure location
What to Do If Credentials Are Exposed
If credentials are accidentally committed:
- Immediately invalidate and rotate the exposed credentials
- Use tools like
git-filter-repoto remove the credentials from git history - Force push the cleaned history
- Notify relevant team members/security personnel
- Review access logs for potential unauthorized use
Pre-commit Hook
The project includes a pre-commit hook that scans for potential credentials. The hook:
- Checks staged files for common credential patterns
- Excludes test files and dependencies
- Provides clear error messages if potential credentials are found
To bypass the hook in exceptional cases (NOT RECOMMENDED):
git commit --no-verify
Continuous Integration
For CI/CD pipelines:
- Use secure environment variables in CI configuration
- Never display environment variables in build logs
- Rotate CI/CD credentials regularly
- Limit CI/CD service permissions to only what's necessary
Security Checks
Regular security maintenance:
- Update dependencies regularly
- Run security audits (
npm audit) - Review access logs
- Verify environment variable usage
- Check git history for any exposed credentials
Reporting Security Issues
If you discover a security vulnerability:
- Do NOT open a public issue
- Contact the maintainers directly
- Provide detailed information about the vulnerability
- Allow time for the issue to be addressed before public disclosure