Vibe coding security
Public .env files: what it means and what to do
Exposed environment and config files are one of the most common — and most fixable — mistakes in AI-built apps. Here is what they are, why they matter, and the steps to take if one leaked.
Short answer
A .env file stores configuration and secrets for your app. It is meant to stay on the server, never to be downloadable from your public website. If yours is reachable at your-domain.com/.env and contains real secrets, treat those secrets as compromised, rotate them, and block public access to the file. This does not automatically mean your app was hacked — but anyone could have read the file, so act quickly.
Key takeaways
- A .env file holds secrets and should never be downloadable from your public domain.
- If a real secret was ever public, treat it as compromised and rotate it.
- A public .env file does not automatically mean your app is hacked — but it is a serious risk that needs immediate attention.
- Source maps, .git folders, and debug endpoints can leak internals the same way.
- Keys prefixed for the browser (for example NEXT_PUBLIC_) are meant to be public; server secrets are not.
What is a .env file?
A .env file (short for "environment") is a plain-text file that holds configuration values for your app — things like database connection strings, API keys, and feature flags. Keeping them in one file makes it easy to change settings between your local machine and production without editing code.
Because it is plain text, anyone who can open the file can read every value in it. That is fine on a server you control. It is a problem the moment the file becomes downloadable over the public internet.
Why .env files should not be public
Secrets in an exposed .env file give a stranger the same access your backend has. A leaked database password can mean someone reading or deleting your data. A leaked payment or email API secret can mean fraudulent charges or spam sent in your name. The file itself is small, but what it unlocks can be your entire backend.
Importantly, exposure is not the same as a breach. A public .env means the door was unlocked, not that someone walked through it. But because you cannot know who looked, the safe assumption is that any real secret in a public file is compromised.
What should never be exposed
These are server-side secrets. None of them belong in a public file or in your browser bundle:
Database connection strings and passwords
Service-role or admin API keys (for example a Supabase service_role key)
Payment provider secret keys (for example a Stripe secret key)
Email, SMS, and other third-party API secrets
Signing secrets, encryption keys, and webhook secrets
By contrast, values intentionally prefixed for the browser — such as NEXT_PUBLIC_ in Next.js or VITE_ in Vite — are designed to be public. Seeing those is expected. The risk is a true secret ending up where the public can read it.
How these files get published by accident
Nobody decides to publish their secrets. It usually happens because a tool or configuration treats the file as a normal asset:
The .env file is placed in a public or static folder that the host serves directly.
A build copies everything in the project — including .env — into the deployed output.
The .git folder is deployed, exposing history that may contain old secrets.
Source maps are shipped to production, revealing original source and sometimes embedded values.
A debug or info endpoint prints environment variables to anyone who visits it.
AI builders and quick-start templates make this more likely because they optimize for a working deploy, not a careful one — and you may never see the config that decides what gets published.
What to check on Vercel, Netlify, and static hosting
The goal is simple: confirm secret files are not reachable, and that real secrets are stored as environment variables in your host's dashboard rather than in committed files.
Visit your-domain.com/.env, /.env.local, and /.git/config — each should return a 404, not contents.
Store secrets in your host's environment-variable settings (Vercel, Netlify), not in a deployed file.
Confirm .env is listed in .gitignore so it is never committed.
Disable production source maps unless you specifically need them.
Remove debug, info, or status endpoints that print environment values.
Exposed secrets are one section of the broader vibe coding security checklist and a hard requirement on the final launch security checklist before going live.
What to do if secrets were exposed
Move in this order. Rotating secrets matters more than hiding the file, because the file may already have been copied.
Rotate every real secret that was in the file
Generate new keys and passwords in each provider, and update your environment variables. Treat the old values as compromised.
Block public access to the file
Remove it from the deployed output and confirm it now returns a 404.
Invalidate caches
Clear your CDN or host cache so the old file is no longer served.
Check for misuse
Review provider logs and billing for unexpected activity since the exposure.
Re-scan to confirm
Run a fresh scan and verify the file is gone and no secrets remain in the bundle.
If a key is tied to money, data, or user accounts and you are unsure whether it was misused, ask a developer to help review logs before you move on.
What GuardMint can and cannot verify
GuardMint checks your live site for exactly this class of mistake. Our methodology explains how the public scan works.
Detects common exposed files such as .env, .git, and source maps reachable on your domain.
Flags secret-looking keys and tokens found in your frontend bundle.
Reports debug or error responses that leak internal details.
What a scan cannot fully verify
A scanner can only see files and values that are publicly reachable. It cannot know whether a found key is still valid, whether it was already misused, or what a secret unlocks behind the scenes. It also cannot find secrets hidden behind authentication. GuardMint is a launch-readiness check, not a penetration test, audit, or compliance certification — use it to catch obvious exposure, then rotate and review anything it surfaces. See our disclaimer for full scope.
Frequently asked questions
- What happens if my .env file is public?
- Anyone who finds the URL can download it and read whatever it contains. If it holds real secrets — database passwords, API secret keys, service credentials — those should be considered compromised and rotated immediately. If it only holds public, browser-safe values, the risk is lower, but the file still should not be served publicly.
- Does a public .env file mean my app was hacked?
- No. Exposure means the file could be read, not that someone has acted on it. This does not automatically mean your app is hacked. It does mean you should rotate any real secrets and close the exposure quickly, because anyone could have copied the file.
- Are NEXT_PUBLIC_ or VITE_ variables a problem if exposed?
- Those prefixes exist specifically because the values are bundled into the browser and are meant to be public. Seeing them is expected. The risk is when a true server secret ends up in a public file or bundle — that is what you need to find and rotate.
- How do I check if my .env is exposed?
- Visit your-domain.com/.env in a browser. A safe setup returns a 404 or an error page. If you see the file contents, it is exposed. You can also run an automated scan that checks for this and related files.
- I removed the file but it still loads. Why?
- Hosting and CDNs cache content. After removing or blocking a file, clear or invalidate the cache and re-check. Also confirm the secret was rotated — removing the file does not undo any exposure that already happened.
Check whether your secrets are exposed
Run a free security scan on your live app — GuardMint looks for public .env files, leaked keys, and other obvious exposure. No signup required for your first score.