high · M1 · MASVS-STORAGE-1 · PTKD-LEFTOVER-ENV-NOT-IGNORED

    Secret .env file is not ignored by git

    A .env file with secret-looking keys is not covered by .gitignore, so the next commit can publish it to your repository and everyone with access to it (or the whole internet, for a public repo).

    How it is exploited

    A vibe-coded project has .env with SUPABASE_SERVICE_ROLE_KEY and STRIPE_SECRET_KEY, but the generated .gitignore only lists node_modules. One `git add .` and the keys are in the repository. Bots scan public GitHub for exactly these names within minutes of a push.

    Why it matters

    Leaked server keys: database takeover, card charges and refunds, cloud bills.

    How to fix it

    1. Add `.env*` and `!.env.example` to .gitignore.
    2. Check whether the file was ever committed: `git log --all -- .env`. If so, rotate every key in it and purge it from history.
    3. Keep a .env.example with the names only, so new developers know what to set.

    .gitignore

    .env*
    !.env.example

    Does your app have this?

    PTKD checks your build or your source project for PTKD-LEFTOVER-ENV-NOT-IGNORED and every other check in this knowledge base.

    Scan your app

    References

    Related checks (M1)