You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# .env.example (Safe to commit!)API_KEY=your_api_key_hereDATABASE_URL=your_database_url_hereAWS_ACCESS_KEY_ID=your_access_key_hereAWS_SECRET_ACCESS_KEY=your_secret_key_hereSTRIPE_SECRET_KEY=sk_test_...TWILIO_AUTH_TOKEN=your_twilio_token
3. Use Secret Management Tools
Platform
Tool
Use Case
AWS
Secrets Manager, IAM Roles
Production secrets
Google Cloud
Secret Manager
GCP secrets
Kubernetes
Kubernetes Secrets
Container secrets
Docker
Docker Secrets
Docker Swarm secrets
HashiCorp
Vault
Enterprise secrets
Doppler
Doppler CLI
Simple secrets management
Infisical
Infisical
Self-hosted secrets
4. Set Up Pre-Commit Hooks
Create .git/hooks/pre-commit:
#!/bin/bashecho"π Checking for secrets in commit..."# Check for secret files
SECRET_PATTERNS=(
"\.env""\.env\.""*key""*secret""*token""*credential""*password""*auth""credentials""aws""gcp""azure""stripe""paypal""twilio""sendgrid""mailgun""slack""discord""github""gitlab""bitbucket""notion""intercom""zendesk""freshdesk""zoho""datadog""newrelic""sentry""bugsnag""rollbar""hound""coveralls""mixpanel""amplitude""segment""matomo""vault""terraform""cloudformation""ansible"
)
forpatternin"${SECRET_PATTERNS[@]}";do
git diff --cached --name-only | grep -iE "$pattern"&& {
echo"β ERROR: Found secret file matching pattern: $pattern"exit 1
}
doneecho"β No secrets found"
Make executable:
chmod +x .git/hooks/pre-commit
5. Configure .gitignore
# Environment Configuration.env.env.local.env.development.env.production.env.test.env.*.local.env.*.development.env.*.production# Database Files*.db*.sqlite*.sqlite3*.db-journal*.db-wal# Secret Keys and Tokens*.pem*.key*.p12*.keypair*.pkcs12*.csr*.crt*.der*.pfx*.cert*.pub*.cer*.p7b*.p7c*.p7s# Secrets Configuration Filessecrets.jsonsecrets.yamlsecrets.ymlconfig/secrets.jsconfig/secrets.pyconfig/secrets.phpsecrets/
# AWS Configuration.aws/credentials.aws/configaws-secretsaws_keys.txtaws-config.json# Google Cloud Configuration*.jsonservice-account.jsongcp-keys.txtgcp-config.jsoncredentials.json# API Keys and Secretsapi_keys.txtapi_keys.jsonapi_keys.yaml*.secret*.secret.json*.secret.yaml*.secret.ymlprivate-key.txtaccess-token.txtrefresh-token.txtauth-token.txtsession-token.txt# OAuth Tokens*.tokenoauth-token.txtrefresh-token.txtaccess-token.txtclient-secret.txt# Docker Secretsdocker-secrets/
secrets.d/
# Build Artifactsnode_modules/
npm-debug.log*yarn-debug.log*yarn-error.log*lerna-debug.log*# IDE and Editor Files.idea/
.vscode/
*.swp*.swo*~.project.classpath.settings/
*.sublime-project*.sublime-workspace.history/
# Build Outputdist/
build/
out/
target/
*.log# OS Generated.DS_StoreThumbs.dbdesktop.ini# Backups*.bak*.backup*.old*.orig# Data Files (Potentially Containing Secrets)data/secrets.csvdata/credentials.csvdata/api_keys.csvexports/
downloads/
uploads/
# SSH Keys*.pubknown_hostsknown_hosts.txtssh-keyscan.txt# SSL/TLS Certificates*.crt*.cer*.pem*.key*.der*.p12*.pfx*.p7b*.p7c*.p7s# SSL/TLS Configurationssl/
certs/
server.crtserver.keyclient.crtclient.key# Monitoring and Analytics Keysanalytics-key.txtanalytics-secret.jsonmixpanel-secret.txtamplitude-secret.txtsegment-secret.txtmatomo-token.txt# Third-Party Service Keystwilio-account-sid.txttwilio-auth-token.txtstripe-secret-key.txtstripe-publishable-key.txtpaypal-client-id.txtpaypal-secret.txtsendgrid-api-key.txtmailgun-api-key.txtslack-api-token.txtdiscord-token.txtgithub-token.txtgitlab-token.txtbitbucket-token.txtnotion-api-key.txtintercom-api-key.txtzendesk-api-key.txtfreshdesk-api-key.txtzoho-api-key.txtdatadog-api-key.txtnewrelic-license-key.txtsentry-auth-token.txtbugsnag-api-key.txtrollbar-api-key.txthound-ci-token.txtcoveralls.io-token.txt# Cloud Provider Configscloud-config.jsoncloud-config.yamlterraform.tfvarsterraform.tfstateterraform.tfstate.backupterraform-overrides.tfvarsansible-vars/
ansible-vault-password.txt# Kubernetes Secrets (Base64 encoded secrets)k8s-secrets/
kube-secrets/
secrets/k8s/
secrets/kube/
*.secret.k8s*.secret.kube# Deployment and CI/CD Secretscicd-secrets/
github-actions-secrets/
gitlab-ci-secrets/
bitbucket-pipelines-secrets/
# Application Configuration (Contains Secrets)config/production.jsonconfig/production.jsconfig/production.yamlconfig/production.ymlconfig/staging.jsonconfig/staging.jsconfig/staging.yamlconfig/staging.yml# Logging Files (May Contain Sensitive Info)logs/
*.lognpm-debug.log*yarn-debug.log*yarn-error.log*pnpm-debug.log*bun-debug.log*bun-error.log*# Testing Data (Contains Secrets)test-data/
tests/fixtures/secrets/
secrets-test-data/
# Docker Compose (Contains Secrets)docker-compose.override.ymldocker-compose.secrets.yml# HashiCorp Vault Secretsvault-secrets.jsonvault-secrets.yamlvault-secrets.ymlvault_tokens/
# AWS CloudFormation / IaC Secretscloudformation-parameters.jsonterraform.tfvarsterraform-overrides.tfvars# Azure Secretsazure-credentials.jsonazure-secrets.jsonaz-secrets.txt# Google Service Account Keysservice-account.jsonservice-account.keygcp-service-account.json# Database Migration Scripts (Contain DB URLs)migrations/secrets.sqlmigrations/db-credentials.sql# Data Export Filesexport/
exports/
backups/
snapshots/
# Temporary Filestmp/
temp/
*.tmp# Cache Filescache/
.cache/
*.cache# Lock Files (Contain API keys or secrets)package-lock.jsonyarn.lockpnpm-lock.yamlbun.lockb# Database Dump Files*.dump*.sql*.sql.gzpg_dump.sqlmysqldump.sql# Docker Ignore Patternsdocker-compose.override.yml.dockerignore
Special thanks to the security community and all contributors who help maintain these standards.
β οΈ Disclaimer
This document is for educational and reference purposes only. Always follow your organization's security policies and best practices for handling secrets. The creators and maintainers of this project are not responsible for any security incidents resulting from the use of this information.
Remember: Once a secret is committed to public git history, it can never truly be removed. Protect your secrets!
End of Document - Version 2.0.0Last Updated: 2026-02-12
About
π Comprehensive documentation of secrets that must never be committed to version control. Includes patterns, best practices, and detection commands.