Guide · Exposed files · Updated
Exposed .env and .git files: how they get served, how to check, what to do
Rather check your own app first and read later? Paste its address, prove it’s yours, and the free scan shows you the worst thing a stranger can reach. Run the free scan
A .env file is where your app keeps database passwords and API keys. A .git folder is the whole history of the project, old keys included. Neither should ever be reachable from the internet. They still are, on a surprising number of sites, because the folder that got deployed was the project folder instead of the build, or because someone dropped a secret file into public/. This guide is the plain version: how that happens on the hosts vibe-coded apps use, one curl loop that shows whether yours is leaking, and what to do about it — starting with rotating every key, because deleting the file is not enough.
New to this? Start with our vibe coding security checklist, eleven checks for any AI-built app. Exposed files are check 10 there. This page is the long version for .env and .git. Source maps have their own step in our leaked keys guide.
What we tested, and how
Everything on this page we ran ourselves on 25 October 2026, on our own machine. We built a small “notes” project that was both a git repo and a web root: a homepage, a .env, a .env.local, a .env.production, and a two-commit history that once had a fake Stripe test key hard-coded in a file. Every key in it was invented for the lab. Then we pointed nine servers at that folder: Python’s built-in HTTP server, Express 4.22.3 and Express 5.3.0 with express.static, the same Express 5 app with an SPA fallback, nginx 1.26.3, and Apache 2.4.69 — each one before and after the fix. We also ran Next.js 16.4.3 next start and Vite 8.3.5 vite build / vite preview with the same files dropped into public/. Against the open nginx, we ran git-dumper 1.0.9 and read back the deleted key and a fake GitHub token from the remote URL. For prevention we ran gitleaks 8.30.1 on the history and as a pre-commit hook through pre-commit 4.7.0. What we say about Vercel, Netlify, Replit and Docker comes from their docs (and, for Vercel and Netlify’s CLI filters, from reading the published packages). We didn’t deploy this project to any of those accounts.
The eight checks
- How .env and .git end up on a live site
- A safe self-test, the same five paths our scan asks for
- What a public .env file really means
- What a public .git folder really means
- If anything came back 200: block it, then rotate every key
- Per-platform fixes we tested
- Keep them out of the next deploy
- Test again
01
How .env and .git end up on a live site
Almost every leak we see has the same shape: the live site is serving the project folder, or a build folder that still contains project files. OWASP’s 2025 Top 10 puts it under both broken access control (“ensure file metadata (e.g., .git) and backup files are not present within web roots”) and security misconfiguration. MITRE calls a public version-control folder CWE-527.
Here’s how that folder gets chosen on the hosts vibe-coded apps actually use:
- Vercel. A Git-connected project builds from what Git has. The CLI is different: it uploads your working directory, and Vercel’s default ignore list (only for the CLI) skips
.gitand.env.local, but not a plain.envor.env.production. Anything that lands inpublic/is copied into the deployment and served. Vercel’s CLI docs even warn that a hidden file “serves the file publicly.” - Netlify. Only the publish directory is deployed — “Files and assets located outside of the publish directory won’t be included.” A
.envat the project root never goes out. One that got copied into that publish folder does. The Netlify CLI also skips every name that starts with a dot, except.well-known. - Replit. Agent apps run as a full server (Autoscale or Reserved VM), so whatever that server’s static middleware points at is what gets served — see the Express cases below. Replit’s Static Deployments publish a configured public directory with no backend; keep secrets in Secrets, which “stores and encrypts” them as environment variables, not in that directory.
- nginx / Apache / a VPS.
rootorDocumentRootpointed at the project folder serves everything in it, dots included. That’s the before state in our lab. - Express.
express.staticuses the serve-staticdotfilesoption. The default isignore, which pretends a file whose name starts with a dot doesn’t exist — but, as the docs note, “this default will not ignore the files within a directory that begins with a dot.” We saw that: Express 4.22.3 answered/.envwith 404 and still handed out/.git/HEAD. Express 5.3.0 (serve-static 2.x) refused both in our run. Relying on the default across major versions is how this bites people on Replit. - Next.js and Vite. Next.js serves everything under
public/at the site root. Vite copies the public directory “to the root of the dist directory as-is.” Drop a.envor a.gitin there and the next build publishes it. A.envat the project root is for the build process; Next’s docs say create-next-app already puts those files in.gitignore, and Vite says to ignore*.local. - Docker.
COPY . .copies the build context. A .dockerignore file is how you keep.gitand.env*out of the image; without it, they ride along. (Lines starting with!make exceptions, which is how you keep.env.example.)
This is not rare. In August 2024 Unit 42 described a campaign that “targeted 110,000 domains resulting in over 90,000 unique variables in the .env files,” after scanning “more than 230 million unique targets.” In October 2024 Sysdig’s EMERALDWHALE write-up found “more than 67,000 URLs with the path /.git/config exposed” and “more than 15,000 cloud service credentials stolen.” Both started with a folder that should never have been public.
02
A safe self-test, the same five paths our scan asks for
You don’t need an account or a scanner. These are the five paths LockShip asks for. Run them against your live address:
# Put your live address in APP. Then:
APP=https://yourapp.com
for p in /.env /.env.local /.env.production /.git/HEAD /.git/config; do
code=$(curl -sL -o /tmp/lockship-check -w '%{http_code} %{content_type}' "$APP$p")
line=$(head -n 1 /tmp/lockship-check | cut -c1-60 | sed -E 's/=.*/=(value hidden)/')
echo "$p $code $line"
done
rm -f /tmp/lockship-checkHow to read each line:
- 404 or 403. Good. The file isn’t readable. lockship.dev returned 404 for all five when we ran this on 25 October.
- 200, and the third column starts with
<!doctypeor<html, or the content type istext/html. Your host is falling back to the homepage for unknown paths. That’s normal for SPAs. Not a leak. - 200, and the third column looks like
KEY=,ref: refs/, or[core]. That’s the file. Treat every value in it as stolen. Checks 3 and 4, then 5.
Against our careless test project, before any fix:
Our test project, one folder that was both the web root and the git repo:
python3 -m http.server (project folder)
/.env 200 application/octet-stream DATABASE_URL=(value hidden)
/.env.local 200 NEXT_PUBLIC_SITE_URL=(value hidden)
/.env.production 200 DATABASE_URL=(value hidden)
/.git/HEAD 200 ref: refs/heads/main
/.git/config 200 [core]
nginx 1.26.3, root = that folder: same five 200s.
Apache 2.4.69, DocumentRoot = that folder: same five 200s.
Express 4.22.3, express.static(projectFolder):
/.env* 404, /.git/HEAD and /.git/config 200
Express 5.3.0, express.static(projectFolder): all five 404
SPA that returns index.html for unknown paths: all five 200 text/html
(the homepage, not the file — ignore these)Our scan uses the same five paths and the same HTML filter. On those open servers it reported two critical findings: “Environment file is publicly readable” and “Git directory is publicly readable,” with the key names only — never the values.
03
What a public .env file really means
A public .env is a list of everything your app needs to talk to the outside world: the database URL with its password, the Stripe secret key, the OpenAI key, the email provider key. Unit 42’s write-up puts the starting point bluntly: “Attackers obtained initial access to victims' cloud environments through exposed environment files (.env).”
Three names show up most often, and all three are worth asking for:
.env— the default file most frameworks load..env.local— overrides for your machine. Next.js and Vite both treat*.localas local-only; Vite tells you to add*.localto.gitignore..env.production— production values. Easy to forget because it isn’t called “local.”
Our scan reports a readable env file as critical, title “Environment file is publicly readable.” The summary names the paths that answered and the key names it saw, and ends with “LockShip did not store the values.” That’s deliberate: the finding is enough to act on, and the values have no business sitting in our database.
One more thing the curl output can hide: a 200 with an empty body, or a body that isn’t KEY=value lines, won’t trigger our finding. We only flag a response that both looks non-HTML and contains at least one NAME= assignment. If you’re doing this by hand and you get a weird 200, open the body.
04
What a public .git folder really means
A public .git is worse than it looks. You don’t need directory listing. Tools like git-dumper walk the object store one hash at a time and rebuild the repo. Sysdig’s EMERALDWHALE write-up describes exactly that pattern against exposed /.git/config files.
We pointed git-dumper 1.0.9 at our open nginx. No directory listing. Seventy-one requests later:
$ git-dumper http://127.0.0.1:4306/ dumped
# nginx, no directory listing. 71 requests from the tool.
[-] Fetching http://127.0.0.1:4306/.git/HEAD [200]
[-] Fetching http://127.0.0.1:4306/.git/config [200]
...
[-] Running git checkout .
$ cd dumped && git log --oneline
a5c3f45 Move key to .env
42a5376 Add checkout
$ git log -p --all -S sk_test_ --oneline | grep -E "^[-+].*sk_test_"
-export const STRIPE_SECRET_KEY = "sk_test_51LabFakeKey...(value hidden)"
+export const STRIPE_SECRET_KEY = "sk_test_51LabFakeKey...(value hidden)"
$ git config --get remote.origin.url
https://alice:ghp_LabFakeToken...(value hidden)@github.com/alice/notes-app.gitTwo things fell out that weren’t in the live .env. The Stripe test key we had deleted from the working tree was still in commit 1. And .git/config held the remote URL, with a fake GitHub personal access token embedded in it — a pattern real repos pick up when someone clones over HTTPS with a token. The live .env was gitignored, so it wasn’t in the dump; nginx was serving it as a plain file next to the repo. You need both checks.
Our scan reports this as critical, title “Git directory is publicly readable.” It asks for /.git/HEAD and /.git/config only. A HEAD that starts with ref: or a 40-character hash, or a config that has a [core] or [remote section, is enough. Remote URLs are not stored.
05
If anything came back 200: block it, then rotate every key
Do this in order. Skipping the rotation is how people get a second incident a week later.
- Block the paths on the live site now. Check 6 has the configs. Redeploy or reload the web server so the five curl lines stop returning the file. A 403 or 404 is the goal.
- Rotate every key that was in the file, and every key that ever was. GitHub’s guidance on removing sensitive data puts it first: “if the sensitive data you need to remove is a secret (e.g. password/token/credential), as is often the case, then as a first step you need to revoke and/or rotate that secret.” For Stripe, use the Dashboard to expire and rotate the secret key; for AWS, create a new access key, deactivate the old one, verify the app, then delete the old one, and read CloudTrail for anything you didn’t do. Do the same at OpenAI, Resend, GitHub, your database host — every name that appeared in the file or in
git log -p. Our leaked keys guide has the order we use when the key was in the JavaScript instead. - Assume the git history is out. Anyone who ran a dumper has the old commits. Rewriting history with
git filter-repoonly helps after every clone and fork has been cleaned, which GitHub’s docs describe as a coordination problem. Rotation is what actually cuts off access. - Read the provider logs. AWS CloudTrail, Stripe’s request logs, your database’s connection log, GitHub’s security log. You’re looking for use of the old key from places that aren’t you.
- Then clean the repo. Make sure
.env*is in.gitignore(check 7), remove the files from the web root and frompublic/, and only then think about history rewriting.
06
Per-platform fixes we tested
After each of these, re-run check 2. This is what our lab looked like after:
Same project, after the fix:
nginx: location ~ /\.(?!well-known/) { deny all; }
all five 403, /.well-known/lockship.txt still 200
Apache: RedirectMatch 404 "/\.(?!well-known/)"
(in the vhost, or in .htaccess with AllowOverride FileInfo)
all five 404, /.well-known/lockship.txt still 200, /.htaccess itself 404
Express 5, build folder only, { dotfiles: "deny" }, /.well-known mounted first:
all five 404, /.well-known/lockship.txt 200nginx
One location, above any catch-all. nginx checks regular expressions in the order they appear, and the first match wins, so don’t put this under a location / that already ate the request:
# Inside the server { } that serves your site. Put it above any catch-all location.
# nginx checks regular expressions in the order they appear; the first match wins.
location ~ /\.(?!well-known/) {
deny all;
}In our lab that turned every one of the five paths into a 403, and left /.well-known/lockship.txt at 200. deny all is enough; you don’t need a separate return 404.
Apache
RedirectMatch with a non-3xx status takes no second URL argument. Status 404 is what we want:
# In the VirtualHost, or in a .htaccess file in the web root
# (AllowOverride FileInfo must be on for the .htaccess form).
# Status is 404, so there is no second URL argument.
RedirectMatch 404 "/\.(?!well-known/)"We tried it in the VirtualHost and in a .htaccess with AllowOverride FileInfo. Both returned 404 for the five paths, 200 for /.well-known, and 404 for /.htaccess itself.
Express (Replit and other Node servers)
Two rules. Serve the build folder, not the project. And set dotfiles: "deny", which the serve-static docs describe as “Deny a request for a dotfile and 403/next().” The default ignore is not enough on Express 4, where /.git/HEAD still came through. One catch: deny also hides /.well-known, which you need for ownership checks and certificates. Mount that path on its own first:
import express from "express";
import path from "node:path";
const app = express();
const dist = path.resolve("dist"); // the build folder, not the project root
// /.well-known must stay reachable (LockShip ownership file, ACME, etc.).
app.use("/.well-known", express.static(path.join(dist, ".well-known")));
// Serve the build. With "deny", any other path that starts with a dot is refused.
app.use(express.static(dist, { dotfiles: "deny" }));Our Replit guide covers the same Express trap in a Replit-sized checklist.
Next.js and Vite public folders
Nothing named .env or .git belongs in public/. In our Next.js 16.4.3 run, a .env at the project root was never served (404), but public/.git/HEAD came back 200 with the file contents, and public/.env returned a 500 rather than the file — still a sign it shouldn’t be there. In Vite 8.3.5, both files in public/ were copied into dist/ and served. Delete them from public/, rebuild, and check that dist/ (or .next) doesn’t still contain a leftover .git from an earlier build — Vite’s cleaner leaves a .git directory in outDir alone on purpose.
Vercel and Netlify
On Vercel, prefer a Git-connected project so only committed files are built. For CLI deploys, add a .vercelignore that names the env files the default list doesn’t already cover:
# .vercelignore (CLI deploys only; Git-connected deploys already skip .gitignore'd files)
.env
.env.production
.env.development
# .git and .env.local are already on Vercel's default ignore listOn Netlify, set the publish directory to the build output (dist, out, .next export, and so on) and keep secrets in the site’s environment variables, not in that folder. The CLI already skips dotfiles; a Git build trusts the publish directory setting.
Docker
Put a .dockerignore next to the Dockerfile. The ! line is the documented way to keep an example file:
# .dockerignore, next to your Dockerfile
node_modules
.next
.git
.env
.env.*
!.env.exampleWe didn’t run Docker in this lab (no daemon on the machine). The file above matches what Docker’s build context docs describe, and it’s what we use for lockship.dev itself.
If you’d rather have your AI builder do the change, this is the prompt we’d use:
Stop serving any file or directory whose name starts with a dot, except /.well-known. On nginx, add a location that matches /\.(?!well-known/) and returns deny all, above any catch-all. On Apache, add RedirectMatch 404 "/\.(?!well-known/)". On Express, point express.static at the build folder only (not the project root), set { dotfiles: "deny" }, and mount /.well-known on its own first. On Next.js or Vite, delete any .env* or .git from the public/ folder. Confirm /.env, /.env.local, /.env.production, /.git/HEAD and /.git/config each return 404 or 403, and that /.well-known still works. Don't change anything else, and list every file you changed.07
Keep them out of the next deploy
Three habits stop this from coming back. None of them replace the live check.
.gitignore, and the “already tracked” trap
Git’s own docs are blunt: a .gitignore “specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected.” So:
# Keep these out of every commit. create-next-app already adds the .env lines.
.env
.env.*
!.env.example
!.env*.exampleIf a .env was committed before that line existed, git rm --cached .env takes it out of the index without deleting the local file. Then rotate, because the old commit still has it.
Cursor users: our Cursor guide has a step for finding .env files the agent may have created or committed. Bolt and Lovable apps keep secrets in the builder’s secret store, not in a file you deploy — see the Bolt guide.
Pre-commit secret scanning
gitleaks catches keys before they enter history. With the pre-commit framework:
# .pre-commit-config.yaml
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.30.1
hooks:
- id: gitleaksThen pre-commit install. Against a staged fake Stripe key in our lab:
$ echo 'export const key = "sk_test_51LabFakeKey..."' > pay.js
$ git add pay.js && git commit -m "Add payments"
Detect hardcoded secrets.................................................Failed
- hook id: gitleaks
- exit code: 1
Finding: export const key = "REDACTED"
RuleID: stripe-access-token
File: pay.js
git commit exit code: 1
# The commit never landed.The commit never landed. On GitHub, turn on push protection too — it “prevent[s] hardcoded credentials… from ever being pushed to your repository,” which covers the cases that skip your laptop hook.
08
Test again
Run check 2 again against the live address, not localhost. You want 404 or 403 on all five, with no KEY= and no ref: refs/ in the body. Then click through the app once: a too-broad deny rule can break /.well-known (certificates, ownership files) or a path you actually meant to serve.
The way this comes back is a new deploy that points the web root at the project folder again, or an agent that helpfully writes a key into public/. When that happens, re-run the five curls before you move on.
What a clean result means
The five paths answer 404 or 403, or answer 200 with your homepage HTML and nothing else. Your web root is the build output, not the project. .env* is gitignored and not in public/. A pre-commit hook or push protection would refuse a key. That still says nothing about keys already in your JavaScript, or about database rules — those are other checks on the checklist.
Where LockShip fits
We built LockShip to read your app from the outside, the way a stranger would. For these files, here’s exactly what that covers. The scan sends five GET requests, no cookies or keys: /.env, /.env.local, /.env.production, /.git/HEAD, and /.git/config. For each response it ignores anything that isn’t HTTP 200, anything whose content type is HTML, and anything whose body looks like an HTML page. An env file counts only when at least one line matches a NAME= assignment; a git file counts when HEAD looks like a ref or a raw commit hash, or when config has a [core] or [remote section. The finding keeps the path list and the key names. Values are not stored. Remote URLs from .git/config are not stored either.
Both findings are critical: “Environment file is publicly readable” and “Git directory is publicly readable.” They fail a pass on their own. Monitor, at $9 a month, re-runs the scan every week and emails you once when a new critical or high issue shows up — including either of these after a deploy that pointed the web root at the wrong folder.
What it doesn’t do: it doesn’t fetch further git objects, doesn’t run a dumper, doesn’t open the env values, and doesn’t look inside /backup/ or other paths people sometimes use. The five curls above are yours to extend. Apart from its CORS preflights, the scan only sends GET and HEAD requests, and it never writes anything. A clean result means “nothing obvious from the outside right now,” not “safe.”
The summary is free: a score and the single worst thing we found. The $39 Launch Safe certificate includes every finding with a fix prompt you can paste into your builder, a PDF, and seven days of re-scans while you fix things.
Want to see if your app is handing out .env or .git?
Paste your app’s address, prove you own it, and see the worst thing we find. The summary is free.
Run a free scanBefore you rely on a result, read the disclaimer.
Questions people ask
My host says it never serves .env. Am I safe?
Often, but not always. Vercel’s CLI skips .env.local by default and never uploads .git, but a plain .env and .env.production are not on that list, and Git-connected deploys can still publish whatever ends up in a public/ folder. Netlify’s publish directory is the finished build only, so a .env at the project root never goes out — unless you put it in that build folder. The five curl lines above are the check that doesn’t care which host you use.
I got 200, but the body is my homepage HTML. Is that a leak?
No. Single-page apps often send index.html for every unknown path. Our scan (and the self-test above) ignore any answer whose content type is text/html, or whose body starts with <!doctype html or <html. A real .env or .git file is almost never HTML.
Is a 403 better than a 404?
Both mean a stranger can’t read the file. nginx’s deny all returns 403; Apache’s RedirectMatch 404 and Express’s default ignore return 404. Either is fine. Don’t spend time making them match.
I deleted .env and redeployed. Do I still need to rotate?
Yes. Removing the file stops new downloads. It does nothing for anyone who already grabbed it, and it does nothing for keys that also live in old git commits. GitHub’s docs put it first: revoke or rotate the secret, then worry about rewriting history.
Can I leave .env.example public?
Yes, if it only has placeholder names and empty or fake values. That’s what !.env.example is for in the .gitignore examples above. Never put a real key in an example file.
Keep reading
- Vibe coding security checklist: what to check before you launch an AI-built app
- Leaked API keys in your frontend bundle: how to find them and what to do
- Is my Replit app secure? A plain check before you launch
- Is my Cursor app secure? A plain check before you launch
- Is my Bolt app secure? A plain check before you launch
Sources
We read each of these on 25 October 2026. Frameworks and hosts change their examples, so if something here disagrees with their docs, trust the docs and tell us at hi@lockship.dev. The server results are our own, from a test project with fake keys on our own machine. We didn’t test on any host’s account, and we didn’t run any of this against anyone else’s app.
- A01:2025 Broken Access Control, OWASP Top 10
- A02:2025 Security Misconfiguration, OWASP Top 10
- CWE-527: Exposure of Version-Control Repository, MITRE
- Large-scale cloud extortion operation (exposed .env), Unit 42 / Palo Alto Networks
- EMERALDWHALE: 15k cloud credentials from exposed Git config, Sysdig
- git-dumper, arthaud on GitHub
- serve-static (dotfiles option), Express on GitHub
- ngx_http_core_module (location matching), nginx
- mod_alias (RedirectMatch), Apache HTTP Server
- The public directory, Vite
- Env variables and modes, Vite
- public folder, Next.js
- Environment variables, Next.js
- .vercelignore, Vercel
- Ignored files and folders (CLI), Vercel
- vercel deploy (hidden files), Vercel
- Configure builds (publish directory), Netlify
- .dockerignore files, Docker Build
- Removing sensitive data from a repository, GitHub
- Push protection, GitHub
- gitleaks, GitHub
- pre-commit
- gitignore, Git
- API keys (rotate), Stripe
- What to do if I notice unauthorized activity in my AWS account, AWS
- Secrets, Replit
- Static Deployments, Replit