All articles

Is your .env file public? Check in two minutes

November 17, 2026 · 4 min read

A .env file holds the secrets your app needs: database passwords, payment keys, email credentials. It is meant to stay on your computer or your server. When it ends up somewhere a browser can open it, anyone who guesses the address can read every secret in it.

This happens more often than it should. Projects get deployed from a folder that includes hidden files, a .git folder gets uploaded along with the site, or a backup copy is left next to the real file. None of it shows up when you click around your own site, so it can sit there unnoticed for months.

How a .env file ends up public

  • The whole project folder is the web root. Some hosts and simple deploy scripts serve everything in the folder, hidden files included.
  • A build copies it. A build step that copies the project folder into the output folder takes .env along with it.
  • Backups and copies. Files such as .env.backup, .env.old or .env.production get saved next to the original and are served like any other file.
  • The .git folder is uploaded. Anyone who can open /.git/ can often rebuild your source code, including old versions that held secrets you later deleted.

Step 1: Try the addresses yourself

Open a private browser window and visit these addresses on your live site, replacing yourdomain.com with your own:

https://yourdomain.com/.env
https://yourdomain.com/.env.local
https://yourdomain.com/.env.production
https://yourdomain.com/.git/config

You can also check from a terminal:

curl -sI https://yourdomain.com/.env | head -n 1

A 404 or 403 is what you want to see. A 200 means the file is public.

One catch: some sites answer 200 for every address by showing the home page. If a page loads, read what it shows. A real .env file is plain text with lines like NAME=value. Your home page is not.

Step 2: If a file is public, rotate before you tidy

Assume every value in that file has been read. Removing the file stops new readers, but it does not undo what has already happened.

  1. Make a new key or password for each secret in the file, in the service that issued it.
  2. Put the new values in your host's environment settings, not in a file inside the project.
  3. Delete the old keys so they stop working.
  4. Look at the usage or billing pages of those services for activity you do not recognise.

Do the same for the .git folder. If it was public, treat any secret that was ever committed as exposed, even if you removed it from the current code.

Step 3: Stop it happening again

  • Serve only the build output. Point your host at the folder your build creates (for example dist), not the project root.
  • Keep secrets in your host's settings. Vercel, Netlify, Cloudflare and similar hosts have an environment variables screen. Use it instead of uploading a file.
  • Ignore the file in git. Check that .gitignore lists .env and .env.*. If a .env file was already committed, adding it to .gitignore does not remove it from history, so rotate its secrets as well.
  • Block dotfiles on your server. If you run your own server, refuse requests for any path that starts with a dot.

Step 4: Check your build output

Look inside the folder you deploy. If you see .env, .git or backup files, your build copies them.

ls -la dist
find dist \( -name ".env*" -o -name ".git" -o -name "*.bak" \)

Remove them from the output, and change the build step that copies them.

What to do today

  • Visit /.env and /.git/config on your live site in a private window.
  • If either loads, rotate every secret it holds before doing anything else.
  • Point your host at the build output folder only.
  • Move secrets into your host's environment settings.
  • Confirm .gitignore covers .env and .env.*.
  • Run the find command above on your deploy folder.

Check your own site

Attack Shield looks for these mistakes on your website and shows how to fix each one.

Scan your site