How do these files end up public?
In apps built with Vite, Next.js or a plain static host, these files usually get out by one of four routes.
The public folder is served as is. Vite copies files in public/ "to the root of the dist directory as-is" (Vite: static asset handling). In Next.js, a file at public/avatars/me.png is served at /avatars/me.png (Next.js: public folder). Anything you put there, a .env, a db.sql export, a zip of the project, is published with the site.
Prefixed variables are built into the scripts on purpose. Vite says variables prefixed with VITE_ "will be exposed in client-side source code" and "should not contain sensitive information such as API keys" (Vite: env variables). Next.js inlines NEXT_PUBLIC_ values into "any JavaScript sent to the browser" at build time (Next.js: environment variables). No .env file is exposed here, yet the result is the same. The guide to an API key exposed in the frontend covers that case.
Source maps are switched on. Both tools default to off in production. Vite's build.sourcemap is false unless you change it; true writes a separate .map file and 'hidden' writes it without the comment that points browsers to it (Vite: build options). Next.js disables production browser source maps "to prevent you leaking your source on the client"; turn on productionBrowserSourceMaps and the maps sit next to the JavaScript files and Next.js serves them (Next.js: productionBrowserSourceMaps). Other tools have other defaults: InfoQ notes that the Bun runtime generates source maps unless they are disabled (InfoQ).
The whole project folder is deployed. Running git clone into the web root, or copying the project to a server with rsync or FTP, brings the hidden .git folder and the .env file along. So do the leftovers people forget: OWASP's testing guide describes editors that save copies like file~, renamed files such as login.asp.old that the server then sends as plain text, and backup archives holding every file in the web root (OWASP WSTG: old, backup and unreferenced files).
How do I check my own site?
Five requests, from a terminal, against your own domain:
curl -s https://yourapp.com/.env | head -5
curl -s https://yourapp.com/.git/HEAD | head -5
curl -s https://yourapp.com/.git/config | head -5
curl -s https://yourapp.com/db.sql | head -5
curl -s -o /dev/null -w "%{http_code}\n" https://yourapp.com/.env
Then the source map. Open your home page, view the source and find the main script, something like /assets/index-4f2a9c.js. Request the same address with .map added. Also look at the last line of the script: a //# sourceMappingURL= comment tells browsers where the map is (MDN: source map). With 'hidden' that comment is missing, but the file can still be on the server, so request it directly either way.
Why a 200 does not mean you have a problem
Most single-page apps are set up to return index.html for any address, so the router can handle it. Netlify's documented rule for this, /* /index.html 200, serves the home page "instead of giving a 404 no matter what URL the browser requests" (Netlify: rewrites). So /.env can answer 200 and be harmless.
The opposite also holds. The same Netlify page says a rewrite does not shadow a file that actually exists. If a real .env is in your build output, it wins over the rewrite and is served. That is why you read the body.
What does a safe answer look like?
| Path on your domain | Safe answer | Problem |
|---|---|---|
/.env, /.env.local, /.env.production, /.env.bak | 404, 403, or your app's HTML page | Lines like KEY=value |
/.git/HEAD | 404, 403, or your app's HTML page | ref: refs/heads/main |
/.git/config | 404, 403, or your app's HTML page | A [core] section and a remote address, sometimes with a token in it |
/assets/index-xxxx.js.map | 404 or your app's page, unless you chose to publish maps | JSON starting with {"version":3 |
/db.sql, /backup.zip, /site.tar.gz | 404 or your app's page | SQL statements or a file download |
A source map is JSON whose version field is always 3, and it may carry an optional sourcesContent list with the original source inside (ECMA-426 source map format).
Are source maps a security risk?
Less than the other three, in our view, but they should be a choice. A source map lets the original code be rebuilt from what the browser receives (MDN). That means readable file names, your comments, and sometimes the names of internal endpoints, admin routes or feature flags that the minified code made harder to spot.
What a source map does not do is reveal anything the browser did not already have. A secret in your front-end code is exposed with or without a map; the map only makes it easier to read. The real problem is the secret, and the fix is the server, not the build setting.
The Claude Code package shows how much one file can carry. On March 31, 2026, version 2.1.88 of @anthropic-ai/claude-code was published to npm with a .map file that pointed to its complete TypeScript source. Anthropic called it "a release packaging issue caused by human error, not a security breach" and said no customer data or credentials were involved (InfoQ). That was an npm package rather than a website, but the mechanism is the same one your build uses.
If you want readable stack traces, you do not have to publish maps. Sentry's Vite guide generates them with sourcemap: "hidden", uploads them during the build, and deletes them afterwards with sourcemaps.filesToDeleteAfterUpload; it also suggests denying access to .js.map files at the server as an alternative (Sentry: Vite source maps).
Why is an exposed .git folder worse than it looks?
Because it holds the whole history as well as today's files. A key you deleted from the code six months ago is still in the commits. Truffle Security checked the Alexa top one million websites in 2023, found about 4,500 with an exposed .git folder, and rebuilt the repositories with an open-source tool; they note that .git/config files often contain the password to the repository (Truffle Security). Turning off directory listing does not help, because the files inside .git have predictable names.
I found one on my site. What now?
In this order:
- Remove it from the server and from whatever put it there: the
public/folder, the deploy script, the Docker image. - Rotate every secret it contained. Assume each one was copied. Truffle Security calls rotating or invalidating exposed secrets the only reliable fix. Our fix prompt for moving secret keys to the server helps with the code side.
- Check your providers' logs for the time the file was public: database connections, payment API requests, AI usage.
- Purge your CDN cache, or the old copy can keep being served after you delete the file.
- Block dotfiles at the server. OWASP's advice is to configure the web server to deny access to such directories. On nginx, keep
/.well-known/open, since certificate checks use it:
location ~ /\.(?!well-known/) {
deny all;
}
- Deploy the build output only. Ship
dist/or the framework's build folder, never the project folder, and recheck the five paths after the next release.
Try it on yours now
Run the five curl lines above against your production domain and your staging domain, and read what comes back. It takes two minutes. If the body of /.env is your app's HTML page and /.git/HEAD does not say ref:, you are fine on those two. Then add the checks to your pre-launch checklist so they run on every release, not once.