{
  "id": 23882290,
  "title": "Your .env.example is a password everyone already knows",
  "url": "https://urgent.news/2026/12/06/your-env-example-is-a-password-everyone-already-knows",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-12-06T18:50:11.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/salnor/your-envexample-is-a-password-everyone-already-knows-50b4"
  },
  "original_language": null,
  "account": "Your .env.example file in a NestJS codebase can act like a password that everyone already knows. The placeholder in the example file was long enough to pass a validator check requiring a JWT secret of at least 32 characters, but this didn't guarantee the secret remained secret. Several doors were left open in the codebase, all due to treating published values as if they were secret. This article explains the three doors and how to fix them.\n\nThe first door is the validator checking shape but not secret security. The validator ensures the string is long enough, but it can't prevent someone else from knowing the string. The same applies to seed admin passwords, SMTP credentials, and API keys. To fix this, create a denylist of all published example values and refine the validator to reject anything in that list.\n\nThe second door is publishing the secret empty and generating it instead. Instead of shipping a value in .env.example, leave it empty and generate a unique secret each time the application is run for the first time. This ensures the secret is randomly generated and kept secure. The setup script fills the .env file with a randomly generated secret using OpenSSL and sed.\n\nThe third door is the seed script that rewrites the password directly. The seed script was reading the process.env variable and not re-seeding the password after it was written. To fix this, add a separate function to assert the seed password meets certain criteria, and use that function in your setup and seed scripts. Also, avoid putting sensitive information like admin passwords directly in the .env file. Instead, generate them separately and pass them only to the scripts that need them.",
  "summary": "Our config validation required a JWT secret of at least 32 characters. The placeholder in .env.example was 40 characters long. It passed, and so did everyone who copied the repo. This is a short story about three doors we left open in a NestJS codebase we maintain, all with the same root cause: a value that is published in the repository was treated as if it were secret. If your project has an…",
  "summary_source": "publisher",
  "key_points": [
    ".env.example acts like password known to everyone",
    "Validator checks shape but not secret security",
    "Fix by creating denylist and generating secrets"
  ],
  "editors_take": null,
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "outlets_capped": false,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}