Short answer
Vite doesn’t create production source maps or ship .env files by default, but a changed build setting, a .env placed in public/ or a deploy that uploads the project folder can put both on your live domain. Source maps give anyone your original source with comments and internal endpoints; a reachable .env often holds the keys that matter most. Switch source maps off or to hidden, keep secrets out of public/ and VITE_ variables, and rotate any key that was ever served.
Ask an AI about this page:ChatGPTClaude
On this page
This defect is a live site that serves files meant to stay on your machine: .js.map source maps next to the JavaScript bundle, or a .env file at https://your-app.example/.env. Source maps hand anyone the original, readable source of your frontend. A reachable .env is worse, because it is where secret keys like a Supabase service role key or an AI provider key usually live. It is rated high because of that second case: one download can give full database or billing access. Source maps alone are a smaller issue, but they often point the way to the next bug.
Why it matters
Vite’s defaults are safe. build.sourcemap is false, and the dev server refuses to serve .env files through its server.fs.deny list. The problems come from changes around those defaults:
- Source maps switched on. Someone set
build.sourcemap: trueto debug a production error and never switched it back. Every bundle then ends with a comment pointing to its.mapfile. - A
.envinpublic/. Vite copies thepublicdirectory to the root of the build output as-is, so a.env(orconfig.jsonwith keys) placed there is published. - The wrong folder deployed. A host configured to serve the project root instead of
dist/, or a Docker image that copies everything, ships.envalong with the app. - The dev server exposed. If the Vite dev server runs on a public address, its
.envprotection depends onserver.fs.deny. Vite’s docs note that setting this option replaces the default list entirely, so a custom list without.envremoves the protection.
Even without these, anything prefixed VITE_ is bundled into the public JavaScript. Vite’s docs say VITE_* variables should not contain sensitive information such as API keys. Source maps simply make those values, and the code around them, easier to read; see secrets in VITE_ variables.
How to find it in your app
Check your repository first:
grep -n "sourcemap" vite.config.* 2>/dev/null
ls -a public | grep -iE "^\.env|secret|key"
git ls-files | grep -E "(^|/)\.env($|\.)"Then check your own live site. Start with the .env file and look at the body, not only the status code:
curl -s https://your-app.example/.env | head -c 300Your app’s HTML (the SPA fallback) is fine. Lines like SUPABASE_SERVICE_ROLE_KEY=… mean the file is public. For source maps, find a bundle name and ask for its map:
curl -s https://your-app.example/ | grep -oE "/assets/[^\"]+\.js" | head -1
curl -s https://your-app.example/assets/index-XXXX.js | tail -c 120
curl -s -o /dev/null -w "%{http_code}\n" https://your-app.example/assets/index-XXXX.js.mapA //# sourceMappingURL= comment at the end of the bundle, or a 200 with JSON for the .map URL, means source maps are public. In the browser, DevTools → Sources showing your original src/ folder tells you the same.
How to fix it
Turn production source maps off, or use 'hidden' if an error tracker needs them:
import { defineConfig } from "vite";
export default defineConfig({
build: {
// false (the default) creates no maps. "hidden" creates them without the comment
// that points browsers to them: upload them to your error tracker, then delete them before deploying.
sourcemap: false,
},
});With 'hidden', delete dist/**/*.map after the upload step, so they never reach your host.
Keep .env out of anything that gets published. Nothing secret goes into public/. Deploy only the build output (dist/). Add .env, .env.* and *.local to .gitignore, as Vite’s docs suggest for local env files.
Move secrets to the server. Keys that must stay secret belong in your backend: for Supabase, set them as Edge Function secrets (supabase secrets set NAME=value or in the dashboard) and read them with Deno.env.get. Supabase’s secrets guide also says to add that .env file to .gitignore before you commit.
Rotate what leaked. If a .env was ever reachable, create new keys at each provider, update the server-side secrets, and revoke the old ones. Removing the file doesn’t make old copies disappear.
Check vite.config and set build.sourcemap to false (or to “hidden” only if we upload source maps to an error tracker, and then add a build step that deletes dist/**/.map after the upload). Make sure no .env, .env. or file containing keys or tokens exists in public/, and that only dist/ is deployed. Add .env, .env.* and *.local to .gitignore.
List every variable in .env files and in import.meta.env usages. Mark which ones are secret (service role keys, secret keys, AI provider keys, webhook secrets): remove those from VITE_ variables and client code and move them to Supabase Edge Function secrets. Tell me which keys I must rotate at their providers.
Check that the fix works
- Build locally with
npm run buildand runfind dist -name "*.map"(ordir /s dist\*.mapon Windows). It must find nothing (or only files your deploy step deletes). - After deploying, repeat the
curlchecks:/.envmust return your app’s HTML or a 404, the bundle must end withoutsourceMappingURL, and the.mapURL must not return JSON. - Open DevTools → Sources on your live site. You should see bundled files under
assets/, not yoursrc/folder. - Confirm the old keys are revoked at each provider and the app still works with the new server-side secrets.
Frequently asked questions
Are source maps a vulnerability on their own?
They reveal code, not access. Your bundled JavaScript is public anyway; source maps make it readable, with original file names and comments. That becomes serious when the code contains secrets or describes internal endpoints, which is why the bigger risk on this page is the .env file.
My .env URL returns 200. Is it leaked?
Not necessarily. Single-page apps often answer every unknown path with index.html and status 200. Look at the body: your app’s HTML is fine, lines like KEY=value are a leak.
I want readable stack traces in my error tracker. What now?
Build with sourcemap: ‘hidden’. Vite then writes the .map files without the comment that points browsers to them. Upload them to your error tracker during the build and delete them before the deploy, so they never reach your web host.
I removed the file. Am I done?
No. Treat every secret that was ever served as known to others: rotate it at the provider, then deploy the new value as a server-side secret.
Sources
- 1.Build options: build.sourcemap — Vite Docs
- 2.Env variables and modes — Vite Docs
- 3.Server options: server.fs.deny — Vite Docs
- 4.Environment variables (Edge Functions secrets) — Supabase Docs
- 5.CWE-538: Insertion of Sensitive Information into Externally-Accessible File or Directory — MITRE
- 6.CWE-540: Inclusion of Sensitive Information in Source Code — MITRE