Exposed .env or .git files: what to do
Short answer: If yoursite.com/.env or yoursite.com/.git/config returns the file itself, treat it as public. A 404 or your app's normal page is fine; a 200 that is just the SPA shell (same HTML as the home page) is not the file. Judge by the body, not only the status code. Take the file or .git folder off the deployed site (it often landed in public/ or the whole project folder was uploaded), redeploy, and rotate every secret that was in the .env or in the git history. Deleting the file or folder does not un-leak those secrets. Put secrets in the host's environment variables or secret store, not in a file the web server can serve. Keep .env files out of git. Run a free SniffPup scan of your own site after you have removed the files and rotated the secrets.
Passive, read-only checks only, for a live URL you own or are authorized to test. This is not a source, RLS, or security audit. A score of 100 means no issues were found in our checks, not proof of security.
Home › Guides › Exposed .env or .git files: what to do · Last updated · By Ember, SniffPup
What to do
1. Check your live URL
In a private window, open https://your-domain/.env and https://your-domain/.git/config. Also try /.env.local, /.env.production, and /.env.development if you use those names. Look at the response body: KEY=value lines or a Git config with a [core] section means the file is public. A 404 or your normal app page means that path is not serving the file. Single-page apps can return HTTP 200 with index.html for missing paths; that is not an exposed file. Do not paste secret values into chats, tickets, or screenshots.
2. Take it off the deploy
Remove .env* and the .git directory from anything that gets published: the public/ or static folder, a drag-and-drop or ZIP upload of the whole project, or a document root that is the repo itself. Redeploy so the live site no longer serves those paths. Store secrets in the host's environment variables (for example Vercel Project Settings → Environment Variables). Vercel stores those values outside your source code. Do not put secret files in a folder the web server treats as public.
3. Rotate every secret that was exposed
If a .env was public, revoke or replace every secret in it at the provider (API keys, database URLs, service_role keys, webhook secrets, tokens). If .git was public, treat the repository history as exposed: rotate every secret that ever appeared in the repo, not only the latest commit. GitHub's docs say that if the sensitive data is a secret, the first step is to revoke and/or rotate it; once it cannot be used, that may be enough, and rewriting history may not be warranted. Deleting the file from the current deploy does not revoke the secret.
4. Know the limits of history cleanup
Optional history rewrite (for example git-filter-repo on your own GitHub repo) does not erase copies that already left the site: clones, forks, cached views, and pull requests can still hold old commits, as GitHub documents. Follow GitHub's Removing sensitive data from a repository page for your own repo. After rotation, keep .env files in .gitignore. The default create-next-app template gitignores all .env files; Next.js says you almost never want to commit them.
For your own repository, see GitHub: Removing sensitive data from a repository.
5. Confirm and keep secrets server-side
Revisit the same URLs and confirm they no longer return file contents. Put replacement secrets only in the host's env or secret store, and read them only in server code. This is different from NEXT_PUBLIC_ or VITE_ variables, which are copied into the browser bundle even when no .env file is public. A free SniffPup scan of a URL you own can help find public .env and .git paths still being served. It is passive and read-only. It is not a source, RLS, or security audit. It cannot confirm a secret is absent everywhere. A score of 100 means no issues were found in our checks, not proof of security.
See Are NEXT_PUBLIC_ environment variables public? and Are VITE_ environment variables public? for browser bundle exposure.
Next: Leaked API key: what to do, Find exposed API keys on your website, Are NEXT_PUBLIC_ environment variables public?, and Are VITE_ environment variables public?.
FAQ
How do I tell if my vibe-coded site is serving a .env or .git file?
Open /.env and /.git/config on your live domain in a private window and read the body. File contents (KEY=value or a [core] Git config) mean it is public. A 404 or your normal app page is fine. An SPA may return 200 with the same HTML as the home page; that is not the file.
I deleted the .env and redeployed. Am I done?
No. Revoke or rotate every secret that was in the file at the provider. GitHub's docs say rotating or revoking a leaked secret is the first step, because deleting the file does not stop the old value from being used. Then confirm the URL no longer serves the file.
If /.git/config was public, is only the latest commit exposed?
No. A reachable .git directory can expose repository history, including secrets that were later deleted from the latest files. Rotate every secret that ever appeared in the repo, remove .git from the deploy, and do not assume a history rewrite erases copies that already existed.
Is a public .env file the same problem as a NEXT_PUBLIC_ or VITE_ variable?
No. A public .env file is the file itself being served on the website. NEXT_PUBLIC_ and VITE_ values are inlined into the JavaScript the browser downloads, even when no .env file is public. See the Next.js and Vite guides.
Read the Next.js guide and Vite guide.
What can a SniffPup scan tell me about this?
The free site scan is passive and read-only on a live URL you own or are authorized to test. It checks paths such as /.env, /.env.local, /.env.production, /.env.development, /.git/config, and /.git/HEAD at the site root, and it reports variable names only, never values. It cannot see private repos, server-only env vars, or git history that is not served. It is not a source, RLS, or security audit, and a clean score is not a guarantee.
Sources: OWASP Developer Guide: Secure by Default (keep source-control metadata and secrets off public deploys), GitHub: Removing sensitive data from a repository (revoke or rotate first; history cleanup limits), Next.js: Environment variables (.gitignore and browser bundles), and Vercel: Environment variables (configure values outside source code), checked November 10, 2026.