Is Your .env File Exposed? How to Check and Fix It

Check your own app — free, in about a minute.

The free mini-scan checks your live homepage for TLS/HTTPS basics, response security headers, cookie flags, exposed sensitive files, Firebase/Supabase backend rules, and the WordPress plugin versions your site exposes. You get a score and the finding titles — no account, no card.

Run the free mini-scan →

Is Your .env File Exposed? How to Check (and Why AI Deploys Leak Them)

Two of the highest-severity checks in any external security scan are also the simplest: request https://your-app.com/.env and https://your-app.com/.git/HEAD. If either returns a 200 with real content, your secrets — API keys, database passwords, signing tokens — and your full git history are public. This is exactly what PreShipIt's passive first pass probes, and an exposed .env is flagged high severity, no nuance needed.

How to check right now

curl -s -o /dev/null -w "%{http_code}" https://your-app.com/.env
curl -s -o /dev/null -w "%{http_code}" https://your-app.com/.git/HEAD

A 404 on both: fine. A 200 on either: stop and fix it now, before you read further. A 403 means the server blocked it — acceptable, but a 404 (the file genuinely isn't served) is cleaner.

If /.git/HEAD returns something like ref: refs/heads/main, your .git directory is web-accessible, which means an attacker can reconstruct your repository — every commit, every file, every secret that was ever committed, even ones you later "removed."

Why this keeps happening to AI-built apps

The failure mode is almost always the deploy, not the code:

  1. Static hosts and default server configs. You run npm run build, drag the folder onto a host, and the host serves everything in the directory — including the .env you used during development and the .git folder you forgot was there. The AI never told you to exclude them because the deploy "worked."
  2. Misconfigured web servers. An nginx or Apache rule meant to serve the app root also serves dotfiles. One missing location block and /.env is a URL.
  3. The "it worked on localhost" gap. Locally, .env is read by your framework and never served. In production, if your server's document root contains the project directory instead of just the build output, the file becomes a route.

AI coding tools optimize for a working deploy. "Working" doesn't include "dotfiles unreachable." Nobody checks until a scanner — or an attacker — does.

How to fix it

Immediate (do this today):

Then assume the worst:

Structural (so it can't recur):

Related: security.txt and robots.txt

While you're probing paths, the same passive pass checks two files that should exist: /.well-known/security.txt (tells researchers how to report vulnerabilities to you — a missing one is a low-severity note, but having one is how you hear about problems before they're public) and /robots.txt (not a security control, but its Disallow lines are a map of your sensitive paths — don't list your admin panel there).

The two-command habit

Add this to whatever "is it safe to ship" ritual you have:

curl -s -o /dev/null -w ".env: %{http_code}\n" https://your-app.com/.env
curl -s -o /dev/null -w ".git/HEAD: %{http_code}\n" https://your-app.com/.git/HEAD

Two commands, five seconds, and you've closed the hole that ends up in breach write-ups more often than almost any other. Or run the PreShipIt scan ($29 one-time): the passive pass probes both paths along with your headers, TLS certificate, cookie flags, and HTTP→HTTPS redirect behavior, then agents probe the live app — and the report tells you what to fix first, in plain English.

The PreShipIt Brief — a short weekly email for people shipping vibe-coded apps: the week's important vulnerabilities and launch-safety checks, in plain English.

New and free. Double opt-in: we email you a confirmation link before anything else arrives. Unsubscribe any time.

Check your own app — free, in about a minute.

The free mini-scan checks your live homepage for TLS/HTTPS basics, response security headers, cookie flags, exposed sensitive files, Firebase/Supabase backend rules, and the WordPress plugin versions your site exposes. You get a score and the finding titles — no account, no card.

Run the free mini-scan →

← Back home · Run a free mini-scan · Scan my app — $29 · See a sample report