AppInspected

Fix guides

Your .env file can be downloaded from your website.

Last reviewed November 29, 2026 against the providers' current documentation.

The short version

Treat every value in the file as stolen. Rotate the secrets first, starting with payment, database and AI keys, because bots request /.env on websites all the time and deleting the file doesn't take back copies. Then move the file out of the folder your host publishes, set the values in your host's environment variable settings, and block dotfiles at the host as a safety net.

Why it matters

A .env file usually holds the most sensitive values your app has: database passwords and connection strings, payment keys, AI keys, email service keys. Requesting /.env is one of the cheapest checks an attacker's bot can run, so assume it was downloaded if it was ever reachable. Unlike a key buried in a JavaScript bundle, a .env file lists every secret by name, so nobody has to guess what each value unlocks.

Fix it, in this order

  1. Check it yourself

    Open https://yoursite.com/.env in a private window. If you see lines like KEY=value, it's exposed. If you see your normal homepage or a 404, your host is returning the app or an error for unknown paths; that's fine. Try /.env.local and /.env.production too if you use those files.
  2. Rotate every secret in the file, starting with money and data

    Go line by line. For each key, create a new one in that provider's dashboard, put it in your host's environment settings, and revoke the old one. Order: payment keys (see Stripe secret key exposed), database URLs and passwords (see database URL exposed), Supabase secret or service_role keys (see service_role key exposed), AI keys (see OpenAI key exposed), then email, storage and everything else. Values that are public by design, such as a Supabase publishable/anon key or a Firebase web config, don't need rotating.
  3. Take the file out of what you deploy

    The usual cause is a .env file inside a folder that gets published as-is. Vite serves files in public/ at / and copies them "to the root of the dist directory as-is"; Next.js serves everything in public/ from the base URL /. So public/.env becomes yoursite.com/.env. Keep .env files in the project root (where both tools read them), deploy only the build output (dist/, build/, out/), and on hosts that upload a folder as the site, make sure that folder isn't the project root.
  4. Use your host's environment variables, not a file

    Set production values in your host's environment variable settings. Next.js reads process.env before any .env file, and says you "almost never want to commit these files to your repository". Vite says .env.*.local files "can contain sensitive variables" and should be ignored with *.local in .gitignore. Add .env* to .gitignore (commit a .env.example with empty values instead). A secret must also never be a VITE_ or NEXT_PUBLIC_ variable, because those are copied into the browser bundle (see VITE_ variables).
  5. Check git history

    git log --all -- .env shows whether the file was ever committed (empty output means never). If it was, .gitignore alone doesn't help: Git says files "already tracked by Git are not affected"; run git rm --cached .env and commit. If the repository is or was public, the old values are still in its history. GitHub's guidance is to revoke or rotate the secret as the first step, and says rewriting history "may not be warranted" after that, because clones, forks and cached views can still hold the old commits. If you do rewrite it, GitHub documents git-filter-repo --sensitive-data-removal (version 2.47 or later) and lists the side effects first.
  6. Block dotfiles at the host

    As a safety net, refuse requests for paths that start with a dot, except /.well-known/ (used for HTTPS certificates and other standard files). On nginx:
    location ~ /\.(?!well-known) {
        deny all;
    }
    On other hosts, look for a rule or firewall setting that blocks paths starting with /.env and /.git. Then open /.env again to confirm you get a 403 or 404.

Or ask your AI tool to do it

Paste this into Lovable, Bolt, Cursor, Claude Code or whichever tool built your app. Review what it changes before you deploy.

My .env file is being deployed and is publicly downloadable at /.env. 1) Find every .env* file in the project and make sure none is inside a folder that gets deployed or copied as-is (public, static, dist, build, out). 2) Add .env* to .gitignore except a .env.example with empty values, and if .env is tracked, run git rm --cached on it. 3) Load production configuration only from the hosting platform's environment variables. 4) List every variable the app reads, grouped by service, and mark which are secret (need rotating) and which are public by design. 5) Make sure no secret uses a VITE_ or NEXT_PUBLIC_ prefix. Don't print the secret values.

How this happens

AI tools sometimes create the .env file inside public/ or static/ so the frontend can "read" it, or a static host publishes the whole project folder instead of the build output. Either way the file ships with the site, and nothing in the build warns you.

Check that it's really fixed

After you deploy, run the free check. It reads your live site the way an attacker would and tells you if any secret key is still visible.

Topic check: Website security check

Find the other leaks before someone else does

The free check reads your home page and its scripts. The website security report goes through up to 30 pages and 40 JavaScript files, plus .env and .git files, security headers, cookies and CORS, domain and email records, and libraries with known vulnerabilities. Every finding comes with the fix for your host and a prompt for your AI tool.

$19 once, including 20 runs over 30 days so you can fix things and check again.

Get the report, $19 See an example report

Example report header: a score out of 100, findings by severity, Download PDF and Email me this report.

Questions

I deleted the file. Do I still need to rotate keys?

Yes. If it was ever reachable, assume someone has a copy. Deleting it only stops new downloads.

Which keys can I skip?

Only values that are meant to be public: a Supabase publishable or anon key (as long as RLS is on, see is the anon key safe), a Firebase web config, a Stripe publishable key (pk_). Everything else, including database passwords, secret keys, webhook secrets, JWT or session secrets and SMTP passwords, needs a new value.

My host shows my homepage at /.env. Is that a problem?

No. Single-page apps often return the app for any unknown path. What matters is whether the response is the file's KEY=value lines. Our free check makes that distinction and ignores HTML fallback pages.

How does the AppInspected check find it?

The free check requests /.env on your site and flags it when the response has NAME=value lines and isn't an HTML page. It doesn't print the values. It also requests /.git/HEAD and coding-agent files such as /.claude/settings.local.json and /.mcp.json.

What about /.git?

Same problem, often worse: an exposed .git folder lets people rebuild your source code and every secret ever committed. See how to fix an exposed .git folder.

Sources

Related guides