- Check .gitignore: Ensure
.gitignoreis properly configured (already done) - Never commit .env: The
.envfile contains sensitive keys and is ignored by git - Use .env.example: Share configuration structure without exposing secrets
.env- Contains API keys, secrets, and tokens*.db- Database files with encrypted tokensinstance/- Flask instance folder with databaselogs/- May contain sensitive information*.pem,*.key- Certificate and key files
The following sensitive values MUST be in .env and NEVER in code:
- API_KEY - Your Twitter Manager API key
- TWITTER_CLIENT_ID - From Twitter Developer Portal
- TWITTER_CLIENT_SECRET - From Twitter Developer Portal
- ENCRYPTION_KEY - For encrypting stored tokens
-
Copy the example file:
cp .env.example .env
-
Generate an encryption key:
python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"
-
Generate an API key:
import secrets print(secrets.token_hex(32))
-
Fill in your Twitter API credentials from the Developer Portal
- Token Encryption: All OAuth tokens are encrypted before database storage
- API Key Authentication: All endpoints (except health) require API key
- PKCE OAuth Flow: Enhanced security for OAuth 2.0
- No Hardcoded Secrets: All sensitive values from environment
Before committing, always check:
# Check what will be committed
git status
# Check if .env is ignored
git check-ignore .env
# View files that would be added
git add --dry-run .
# If you accidentally staged .env
git rm --cached .env- Immediately revoke the exposed credentials
- Generate new API keys and tokens
- Remove from history:
git filter-branch --force --index-filter \ "git rm --cached --ignore-unmatch .env" \ --prune-empty --tag-name-filter cat -- --all - Force push to remote (coordinate with team)
- ✅ Always use environment variables for secrets
- ✅ Rotate API keys periodically
- ✅ Use different keys for development/production
- ✅ Review files before committing
- ❌ Never hardcode credentials in source code
- ❌ Never commit .env files
- ❌ Never log sensitive information
Run this to verify your security setup:
# Should return: .env
git check-ignore .env
# Should NOT show .env in output
git ls-files
# Check for exposed secrets in code
grep -r "TWITTER_CLIENT_SECRET\|API_KEY.*=" --include="*.py" .Remember: When in doubt, don't commit!