The twelve-factor app methodology popularized using environment variables for configuration, especially secrets like API keys, database passwords, and encryption keys. The `.env` file format emerged as a convenient way to define these variables locally. But convenience can breed carelessness, and .env files are a common source of secret leaks.

The .env File Format

.env files contain key-value pairs: `DATABASE_URL=postgres://user:pass@host/db`. Most frameworks load them automatically during development. The format is simple, but there is no official standard — different tools handle quoting, multiline values, and variable expansion differently.

The Biggest Risk: Accidental Commits

The most common .env disaster is committing the file to version control. Once a secret is in git history, it persists even after deletion. Always add `.env` to `.gitignore` before creating the file. Use `.env.example` with placeholder values as a template that can be safely committed.

Secret Rotation

Secrets should be rotated regularly, but .env files make this operationally painful. Updating a secret means editing files on every developer machine and deployment target. This friction leads to secrets that never get rotated, increasing the window of vulnerability if a secret is compromised.

Better Alternatives for Production

For production environments, use your platform’s built-in secret management: AWS Secrets Manager, GCP Secret Manager, Azure Key Vault, or HashiCorp Vault. These provide audit logging, automatic rotation, access control, and encryption at rest — none of which .env files offer.

Practical Guidelines

Use .env files only in local development. Never commit them. Use different secrets per environment. Rotate secrets when team members leave. Document required variables in .env.example.

Inspecting .env Files

ParseLab for iOS can parse and display environment variable files, making it easy to check configurations, verify that placeholder values have been replaced, and ensure sensitive values are properly formatted.