PatchPaste · Guides

Last updated 2 November 2026

Is my .env file publicly accessible?

Scan your live app free. It checks whether your site hands out /.env or your .git folder to anyone who asks, and searches the JavaScript your site sends for Stripe, OpenAI, Anthropic, AWS, GitHub and Supabase admin keys. No login, no code access.

Short answer: open https://yourapp.com/.env in a private window. If you see lines like NAME=value, anyone can download your keys, and that's critical. Make new keys and delete the old ones first, then take the file out of what your host serves, redeploy and check again. The usual cause in a Vite app (Lovable, Bolt) is a .env file sitting in the public/ folder, because Vite copies everything in there to your live site.

Why this happens in AI-built apps

OWASP's testing guide lists .env files and .git/ folders among things that should generally never be publicly served.

Check your live app in 2 minutes

  1. Open a private window and visit each of these on your live address (not the editor preview):
    • /.env, /.env.local, /.env.production
    • /.git/HEAD and /.git/config
  2. Read what comes back:
    • Exposed: lines like STRIPE_SECRET_KEY=..., a line starting ref: refs/heads/, or a [core] section.
    • Fine: a 404 page, or your app's homepage. Single-page apps often answer any unknown address with the homepage, so a 200 status on its own proves nothing.
  3. Prefer the terminal? curl -i https://yourapp.com/.env shows the status and the first lines of the body.

How to fix it, in this order

1. Replace every key in the file

Assume the file has already been copied. For each secret (Stripe, OpenAI, Supabase service_role or sb_secret_, database passwords, email API keys), make a new one in that provider's dashboard, switch your app to it, then delete the old one. GitHub's guidance on leaked secrets says revoking or rotating comes first. Hiding the file doesn't un-leak a key.

A VITE_SUPABASE_URL or Supabase anon (publishable) key was already public in your JavaScript, because Vite builds every VITE_ value into the client code. Those don't need replacing just for this. Is the anon key safe? →

2. Take the file out of what your host serves

3. Running your own server? Block dotfiles too

As a safety net on nginx, refuse every hidden file except /.well-known/ (used for HTTPS certificates), using the deny directive:

location ~ /\.(?!well-known) {
    deny all;
}

This is a backstop. The real fix is that the file isn't in the served folder at all.

4. Tidy up Git

Add .env* to .gitignore, but know that .gitignore doesn't affect files Git already tracks. If .env is already committed, run git rm --cached .env and commit. The old copy stays in your history, which is why step 1 matters. Vite's docs also suggest ignoring *.local files, since .env.*.local files can contain sensitive variables.

5. Redeploy and check again

Repeat the 2-minute check on the live site. Then look in each provider's dashboard for usage you don't recognise while the old key was live.

A prompt to paste into Lovable, Bolt or Cursor

My live site serves my .env file (or .git folder) to anyone. Do not print or repeat any secret values. 1) Delete any .env file from the public/ folder and make sure no .env file or .git folder can end up in the build output. 2) Add .env* and *.local to .gitignore, and if .env is already tracked, remove it from Git tracking with git rm --cached (keep my local copy). 3) Move any non-VITE_ secret that the app needs into a server-side function that reads it from a server-only secret, not a VITE_ or NEXT_PUBLIC_ variable. Tell me exactly which files you changed. I will replace the leaked keys myself.

After you publish, repeat the check yourself. Don't take the AI's word for it.

While you're in there

Before launch, run the full Lovable/Bolt pre-launch checklist. Also see is my Lovable app secure?

Exposed .env and .git FAQ

How do I know if my .env file is publicly accessible?

Open your live site's address with /.env on the end (for example https://yourapp.com/.env) in a private window. If the browser downloads a file or shows lines like NAME=value, it is public. If you see your homepage or a 404 page, it isn't. Also try /.env.local and /.env.production.

Why does /.env show my homepage instead of a 404?

Many single-page apps send the homepage for any address they don't recognise, so the page loads with a 200 status even though no .env file exists. That isn't a leak. Only a response containing NAME=value lines means the file is exposed.

Is it a problem if my .env only has VITE_ variables?

Less of one. VITE_ values are built into the JavaScript every visitor downloads anyway, so a VITE_SUPABASE_URL or an anon (publishable) key was already public. Anything without the VITE_ prefix, and any secret key someone gave a VITE_ name by mistake, is a real leak. Remove the file either way.

Does adding .env to .gitignore fix an exposed .env?

No. .gitignore only stops Git tracking new files; it doesn't affect files Git already tracks, and it has nothing to do with what your website serves. Rotate the keys, take the file out of the folder your host serves, and if Git already tracks it, run git rm --cached .env.

Why is a public .git folder dangerous?

It can let anyone download your source code and its full history, including any key that was ever committed, even if you deleted it later. Treat every secret that was ever in the repo as leaked and rotate it.

Do I need to rewrite my Git history after leaking a key?

Rotating the key comes first. GitHub's own guidance is that once a secret is revoked or rotated it can no longer be used, and that may be enough. Rewriting history is extra work with side effects, so only do it if you need to.

Does PatchPaste check for an exposed .env or .git folder?

Yes. The free scan requests /.env, /.git/config and /.git/HEAD on your live site, like any visitor could, and flags any that return real contents rather than a web page. It doesn't store what it reads. It doesn't try other names such as .env.local or .env.production, so check those by hand.

Check your app for free

Paste your live URL for a free A to F report with every problem in plain English. Fix prompts for that report are a one-off £9 (or £29 for 10 reports). Scans are free to rerun, so you can check again after you remove the file and redeploy.

Free. No login. No code access.

Want to see one first? View a sample report.

Sources (checked 2 Nov 2026): Vite, The public directory (served at / and copied to the root of dist as-is) and server.fs.deny (dev-server blocklist including .env, .env.* and **/.git/**, which does not apply to the public directory); Vite, Env variables and modes (VITE_ values are bundled into client code; add *.local to .gitignore); Next.js, public folder; Git, gitignore (files already tracked are not affected; use git rm --cached); GitHub Docs, Removing sensitive data from a repository (revoke or rotate a leaked secret first); OWASP Web Security Testing Guide, Review old backup and unreferenced files; nginx, ngx_http_access_module. Vite 8.3.5 public/.env build test run by PatchPaste on 2 Nov 2026.