Your .env file is a URL away.
Updated 2026-10-13 · Plain English, written for founders who built with Lovable, Bolt, Cursor or similar.
Your .env file holds every secret your app has: database passwords, Stripe keys, AI keys. If your web server hands it out at https://yourapp.com/.env, anyone can download it. A served .git folder is worse. From it, free tools rebuild your entire source code and its history, including every secret you ever committed and later deleted.
Bots request /.env and /.git/HEAD on new websites all day. This is one of the first things they check.
Check in ten seconds
curl -s https://yourapp.com/.env | head -5 curl -s https://yourapp.com/.env.local | head -5 curl -s https://yourapp.com/.env.production | head -5 curl -s https://yourapp.com/.git/HEAD
- Lines like
STRIPE_SECRET_KEY=sk_live_...: your env file is public. Go to "Rotate" below now. ref: refs/heads/main: your git folder is public.- Your homepage HTML, or a 404: fine. Single-page apps answer every path with
index.html, so a 200 status alone does not mean a leak. Look at what came back.
While you are there, check source maps. Open one of your JavaScript files in the browser and add .map to the end of the URL. If a file downloads, anyone can read your original source code, comments included. It is not always a disaster, but it makes every other mistake easier to find, and secrets are sometimes inside.
Rotate first
If either file was public, every value in it is compromised. You can't know who fetched it.
- Rotate every key and password in the file, starting with payments (Stripe), databases (Supabase service key, database URL) and AI providers.
- If
.gitwas exposed, also rotate anything that was ever committed, not just what is in the current version. - Then fix the server (below) so the new values don't leak the same way.
Fix the cause
This happens when the web server publishes your whole project folder instead of just the build output. Common causes:
- nginx or Apache pointed at the repo instead of
dist/orbuild/. Point it at the build output, and block dotfiles as a backstop:location ~ /\.(?!well-known) { deny all; } - Docker
COPY . .into an image that serves static files. Add a.dockerignore:.env* .git node_modules
- A file copied into
public/. Everything inpublic/is published as-is. Secrets never go there. - Uploading the whole folder over FTP or a drag-and-drop host. Upload only the build output.
For source maps: Vite and Next.js do not publish them by default, so check whether someone turned them on (build.sourcemap in Vite, productionBrowserSourceMaps in Next.js). If you need them for error tracking, upload them to your error tracker privately instead of serving them.
Stop it happening again
- Make sure
.env*is in.gitignore, and keep only a.env.examplewith blank values in the repo. - Turn on GitHub secret scanning and push protection, so a key is blocked before it reaches the repo.
- Re-run the curl commands after every hosting change. It takes ten seconds.
Check your app
SecureIndie looks for this mistake. The free quick check covers the basics from outside (exposed files, keys in your site's code, headers) in about a minute. Database rules, payment webhooks and AI endpoints need the full audit, which also reads your code and proves what a visitor can actually reach.
Questions
My host is Vercel or Netlify. Can this happen to me?
Rarely for /.env, because those builds only publish the output folder. It happens when the output folder is the project root, or when a file gets copied into public/ or dist/.
I got a 200 for /.env but it is my homepage HTML. Is that a leak?
No. Single-page apps answer every path with index.html. It is only a leak if the response contains lines like KEY=value.
Do I have to rotate keys if I fix it quickly?
Yes. You cannot know who fetched it while it was public, and bots check /.env on new sites within hours of them going live.
Related guides
- Your AI API key is in your frontend. Anyone can spend your money.
- Your Supabase service_role key is in the browser.
Checks covered: INFRA-EXP-001, INFRA-EXP-002, INFRA-MAP-003, SEC-HIST-003 · If you think data already leaked