Hardcoded Secrets
Hardcoded secrets are one of the most common causes of security breaches in self-hosted and cloud-hosted applications. When credentials appear in docker-compose.yml, .env files committed to version control, or application config files, they are often accidentally exposed through public repositories, log files, or build artifacts.
The Docker Compose pattern is particularly dangerous because environment: blocks with literal values are frequently committed to public GitHub repositories. GitHub's secret scanning catches some patterns, but custom API keys and database passwords are not always detected.
What Counts as a Hardcoded Secret
Direct credential values in environment: blocks (DB_PASSWORD=mypassword). API keys embedded in config files. Private keys committed to repositories. Connection strings with embedded credentials (postgresql://user:password@host/db). Any credential that doesn't use an environment variable reference or secrets manager.
The Safe Pattern: Variable References
Use ${{DB_PASSWORD}} in docker-compose.yml and define the actual value only in .env files that are listed in .gitignore. For production, use Docker Secrets, HashiCorp Vault, AWS Secrets Manager, or equivalent.