CapLeak / Guides

Did my .env leak?

Get a free score of what any browser can see on your live app. Then check the four places below.

Scan your app freeFree score in seconds. No password, no card.

Short answer: a .env file leaks in four common ways: it's served at /.env on your live site, its values were baked into your JavaScript through a public prefix such as VITE_ or NEXT_PUBLIC_, it was committed to a public Git repo, or it's still in that repo's history after you deleted it. Check all four. If any secret was exposed, rotate it. Deleting the file doesn't un-leak it.

Check the four places

1. Your live URL

Run these against your own domain:

curl -s https://your-app.com/.env | head -5
curl -s https://your-app.com/.env.local | head -5
curl -s https://your-app.com/.git/config | head -5

Many hosts answer unknown paths with your homepage HTML, so a "200 OK" alone means nothing. Read the content. Lines like STRIPE_SECRET_KEY=sk_live_… or a block starting [core] mean the file is public. An exposed .git folder can be worse than a single env file, because it can let someone rebuild your source code and history.

2. Your JavaScript bundle

Build tools copy some variables into the code visitors download on purpose. In a Vite app, every variable starting with VITE_ ends up in the browser; in a Next.js app, every NEXT_PUBLIC_ variable does. Check your project's package.json to see which one you use. So if someone put VITE_OPENAI_API_KEY in the env file, the key is in your bundle even though the file itself was never served. Open the live app, open DevTools, search all sources for sk-, sk_live_, sb_secret_ and AKIA, and check the names of your public variables.

3. Your Git repo

If your project is connected to a GitHub repo, open it and look for .env at the root. If the repo is public, anyone could have copied it. Even on a private repo, check who has access.

4. Your Git history

Deleting .env in a later commit leaves the old version readable in history. From a clone:

git log --all --oneline -- .env .env.local

Any output means the file was committed at some point. Treat every value it ever held as exposed.

If it leaked: rotate, block, fix the deploy

Rotate every secret in the file

Not only the one you're worried about. Go provider by provider and create a new key, update it where your server reads it, then revoke the old one:

SecretWhere to rotate
Supabase secret / service_roleYour Supabase project's API key settings (see our service_role guide)
Stripe secret keyThe API keys page in your Stripe Dashboard
OpenAI / AnthropicThe provider's API keys page: create new, delete old
Database URL with passwordReset the database password
Webhook and JWT secretsRegenerate in the provider or your auth settings

Check each provider's usage and billing page for activity you don't recognize, especially AI API spend.

Block the paths at your host

Make sure /.env* and /.git/ return 404, not the file. On static hosts the simplest fix is to make sure those files are never in the published folder at all.

Fix the deploy so it can't happen again

  • Never put .env inside public/ or static/; everything there is served as-is.
  • Add .env* to .gitignore and commit a .env.example with empty values instead.
  • Deploy the build output, not your whole project folder, and never upload .git.
  • Store real secrets in your host's environment settings or Supabase Edge Function secrets, without a public prefix.

A prompt for Lovable, Bolt or Cursor:

Audit how this project handles environment variables. List every VITE_ or NEXT_PUBLIC_ variable and tell me if any holds a secret. Move secret values out of public variables into a server route or Supabase Edge Function. Make sure .env files are in .gitignore and not in the public folder, and add a .env.example with empty values.

Rewriting Git history (for example with git filter-repo) is optional cleanup. It doesn't replace rotation, because copies may already exist.

What CapLeak checks

The free score covers places 1 and 2 from the outside. For place 2, it looks for secret keys in your homepage and the JavaScript files it loads. For place 1, it asks whether /.env, /.env.local, /.env.production, /.env.development, /.git/config and /.git/HEAD are served as real files. It only checks the answer's status and type and never downloads the file, and an HTML catch-all page doesn't count. It also checks HTTPS, headers and more.

The $12 full report (one time, per app) shows where each issue is, with a plain-English fix and a copy-paste prompt for Lovable, Bolt or Cursor, right after checkout. The deep part (database tables, hidden files like .env and .git, and source maps) is added after a quick ownership check, which takes about a minute. The deep check confirms a public .env or .git by its content. Places 3 and 4 are in your repo, so check those yourself. To keep an app watched every week, Watch is $15 a month per app and Unlimited is $39 a month for up to 25 apps, with no report needed first.

CapLeak runs passive checks only. A passing grade means none of its checks failed; it is not a guarantee of security.

FAQ

.env leaks, answered.

How do I check if my .env file is public?

Request /.env, /.env.local and /.git/config on your live domain and read the response. Your homepage HTML is fine. KEY=value lines or a git config block mean the file is downloadable.

I deleted .env from my repo. Am I safe?

Not yet. The old version stays in Git history and may already have been copied. Rotate every secret it contained.

Are VITE_ variables secret?

No. Vite copies every VITE_ variable into the JavaScript visitors download, and Next.js does the same with NEXT_PUBLIC_. Only public values belong there.

Which secrets do I need to rotate?

Every secret that was in the exposed file, not just the one you noticed: database passwords, API keys, Stripe keys, Supabase secret keys, webhook and JWT secrets.

Does CapLeak's free score check for a public .env?

Yes, without downloading it. The free score asks whether /.env, /.env.local, /.env.production, /.env.development, /.git/config and /.git/HEAD are served as real files, and also looks for secret keys in your homepage and JavaScript. After a quick ownership check, the $12 full report confirms an exposed file by its content.

Find out what's public before someone else does.

Free score in seconds. No password, no card.

Get my free score