Security guide
How to fix an exposed source map
A source map file (.js.map) gives anyone who requests it a full copy of your original, unminified JavaScript — variable names, comments, logic, and all. Most build tools generate them automatically, and they often ship to production without anyone noticing. This guide shows you how to detect the leak, disable source maps per build tool, block them at the server, and still get useful stack traces in your error monitor.
.map files are publicly accessible. Or run ExposureCheck to confirm automatically.
- What source maps expose
- Detecting the leak
- Disable at build time
- Block at the server
- Source maps for error monitoring
- Verify the fix
- FAQ
What source maps actually expose
A .map file is a JSON document that maps each position in your minified bundle back to a line and column in your original source. It was designed to make production debugging easier — but when served publicly, it fully reconstructs your pre-build code for anyone who requests it.
| What's in the map file | Why it matters | Risk |
|---|---|---|
| Original file paths | Reveals your project directory structure, build system, and technology choices | Medium |
| Original function and variable names | Fully undoes minification; business logic is as readable as your development source | High |
| Stripped comments | Developer notes, TODO items, internal architecture details, version comments | High |
| Internal API endpoint paths | Hardcoded URLs, staging endpoints, and admin routes visible in your JS logic | High |
| Credentials in source at build time | If any API key or secret was in your source when the map was generated, it's in the map | Critical |
| Feature flag names and logic | Undisclosed features, A/B test variants, unreleased code paths | Medium |
The map file also contains the full source text of each file via the sourcesContent array — which means even if the original source files aren't served, anyone with the .map file has every line of your pre-minified code.
Detecting a source map leak
Method 1: ExposureCheck (automated)
ExposureCheck fetches your deployed bundle, reads the //# sourceMappingURL= comment at the end of each script, constructs the corresponding .map URL, and requests it. If it gets back valid JSON with a sources array, the source map is confirmed publicly accessible — flagged as a high-severity finding with the full path listed.
Method 2: Browser developer tools
Open any page on your live site, open browser developer tools, and go to the Sources (Chrome/Edge) or Debugger (Firefox) panel. If you see a tree of named, readable files with comments and meaningful variable names instead of your minified bundle — your source maps are loading. This is the most immediate visual indicator.
Method 3: Direct URL test
Find your main bundle URL (check Network tab → JS → the largest file), then append .map:
curl -s -o /dev/null -w "%{http_code}" https://your-site.com/assets/index.abc123.js.map
A 200 response with a Content-Type: application/json header confirms the source map is publicly accessible.
Method 4: Check the SourceMappingURL comment
View the source of your deployed bundle and look at the last line:
curl -s https://your-site.com/assets/index.abc123.js | tail -5
If you see //# sourceMappingURL=index.abc123.js.map, the map file exists and your browser will attempt to load it. Request that URL directly to see if it's accessible.
Disable source maps at build time
The cleanest fix is to stop generating source maps for production builds entirely. The setting differs per build tool:
Vite
In vite.config.ts (or .js):
export default defineConfig({
build: {
sourcemap: false,
},
})
The default for build.sourcemap in Vite is false, but some templates and plugins set it to true or 'inline'. Explicitly setting false overrides any inherited value.
Create React App
Set the environment variable before your build command:
GENERATE_SOURCEMAP=false npm run build
Or add it to your .env.production file:
GENERATE_SOURCEMAP=false
Next.js
Next.js disables source maps for production builds by default. If source maps are appearing, check for these options in next.config.js and remove them:
// Remove these if present:
productionBrowserSourceMaps: true,
// For webpack customizations:
config.devtool = false; // set to false
webpack (manual config)
In webpack.config.js, set devtool to false for production:
module.exports = (env) => ({
devtool: env.production ? false : 'eval-source-map',
// ...
})
Or use environment detection:
devtool: process.env.NODE_ENV === 'production'
? false
: 'eval-source-map',
SvelteKit
In vite.config.ts (SvelteKit uses Vite under the hood):
import { sveltekit } from '@sveltejs/kit/vite';
export default defineConfig({
plugins: [sveltekit()],
build: {
sourcemap: false,
},
});
Nuxt
In nuxt.config.ts:
export default defineNuxtConfig({
sourcemap: {
server: false,
client: false,
},
})
Nuxt 3 generates source maps for both client and server bundles by default in production. Set both to false.
.css.map files, apply the same setting to your CSS pipeline. In Vite, setting build.sourcemap: false covers both JS and CSS. In webpack, a separate css-loader option controls CSS maps: { loader: 'css-loader', options: { sourceMap: false } }.
Block source map access at the server
If you can't change the build config (a third-party build, a legacy app, or an interim fix), you can deny all requests to .map files at the server or CDN layer. This doesn't remove the files from your deployment, but it prevents them from being served to public visitors.
Nginx
location ~* \.map$ {
deny all;
return 404;
}
Add to your server {} block, then nginx -t && nginx -s reload.
Apache (.htaccess)
<FilesMatch "\.map$">
Order allow,deny
Deny from all
</FilesMatch>
Place in the .htaccess file at the root of your deployed assets.
Vercel (vercel.json)
{
"redirects": [{
"source": "/(.*)\\.map",
"destination": "/404",
"statusCode": 404
}]
}
Netlify (_redirects)
/*.map /404.html 404
Or in netlify.toml:
[[redirects]]
from = "/*.map"
to = "/404.html"
status = 404
force = true
Caddy (Caddyfile)
respond /*.map 404
Cloudflare (Transform Rules)
Create a Transform Rule matching http.request.uri.path ends_with ".map" with action "Block". Available on all plan tiers, including free. Also consider a WAF rule to log attempts before blocking.
.map files sitting on your server. It's an effective interim fix, but the preferred approach is disabling map generation in the build so they're never deployed in the first place. Use server-level blocking when you can't change the build, and as defense-in-depth when you can.
Source maps for error monitoring — the right way
The reason source maps exist in production is legitimate: without them, a stack trace from a minified bundle is unreadable. The solution is private source map uploads — upload your .map files directly to your error monitoring service, then exclude them from your public deployment entirely.
How private source map uploads work
- Build your app with source maps enabled (to disk, not inline).
- Upload the
.mapfiles to your error monitor using their CLI or API, keyed to your release version. - Delete the
.mapfiles from your build output, or add them to your deploy's exclude list so they're never pushed to your CDN or hosting provider. - Your error monitor uses the private maps to symbolicate crash reports, showing you the original source line. Visitors never see the maps.
Error monitor source map upload commands
Sentry
# Install Sentry CLI
npm install -g @sentry/cli
# Upload source maps
sentry-cli releases \
--org YOUR_ORG \
--project YOUR_PROJECT \
files $VERSION upload-sourcemaps ./dist \
--url-prefix '~/assets'
Or use the @sentry/vite-plugin / @sentry/webpack-plugin to upload automatically as part of the build.
Datadog
datadog-ci sourcemaps upload ./dist \
--service=your-app \
--release-version=$VERSION \
--minified-path-prefix=https://your-site.com/
Rollbar
# Via Rollbar Deployment API:
curl https://api.rollbar.com/api/1/sourcemap \
-F access_token=YOUR_TOKEN \
-F version=$VERSION \
-F minified_url=https://your-site.com/assets/index.js \
-F source_map=@./dist/assets/index.js.map
After uploading, remove the .map files from your deploy artifact:
# Build, upload maps to Sentry, delete maps, then deploy
npm run build
sentry-cli releases files $VERSION upload-sourcemaps ./dist --url-prefix '~/'
find ./dist -name "*.map" -delete
# now deploy ./dist — no .map files present
Verify the fix
After making the change and redeploying:
1. Run ExposureCheck
ExposureCheck will re-fetch your live bundle, check for the sourceMappingURL comment, and attempt to download the referenced .map file. If the fix is correct, the source map finding will be absent from the report.
2. Test directly with curl
# Check your main JS bundle for a sourceMappingURL comment
curl -s https://your-site.com/assets/index.abc123.js | grep -i sourceMappingURL
# If a .map URL appears, request it directly:
curl -s -o /dev/null -w "%{http_code}" https://your-site.com/assets/index.abc123.js.map
# Should return 404, not 200
3. Check browser dev tools
Open the Sources (Chrome/Edge) or Debugger (Firefox) panel on your live site. You should now see only the minified bundle, not readable original source files. If source files still appear, your browser may have a cached version of the old map — do a hard reload (Ctrl+Shift+R or Cmd+Shift+R) or check with a new incognito window.
.map file may still be cached at the edge even after your origin fix is deployed. Purge the cache for *.map paths after deploying the fix, then re-test.
Scan your live site with ExposureCheck to confirm the fix →
Frequently asked questions
Are source maps actually a security vulnerability?
Yes, publicly accessible source maps are treated as an information disclosure vulnerability by most security frameworks. A .map file exposes your complete original JavaScript — variable names, comments, business logic, internal API paths — undoing all the protection minification provides. If your source ever contained credentials, those appear in the map file too. Most penetration test reports cite public source maps as a medium-to-high severity finding.
What exactly does a source map expose?
A .map file is a JSON object containing a sourcesContent array — the full text of every source file that went into the bundle. It also contains the original file paths, original variable and function names before minification, and a mapping table that reconstructs every line of original code from the minified output. Developer tools use it to show you a debuggable view; an attacker uses it to understand your application in detail.
How do I know if my site has an exposed source map?
Run ExposureCheck on your live URL — it reads the sourceMappingURL comment from your deployed bundle and tests whether the referenced .map file is publicly accessible. You can also check manually: open browser developer tools → Sources → look for readable, named files instead of minified code. Or request your bundle URL with .map appended and see if you get back JSON.
If I disable source maps, how do I debug production errors?
Use private source map uploads. Build with source maps enabled, upload them to your error monitoring service (Sentry, Datadog, Rollbar, Bugsnag all support this workflow), then delete the .map files before deploying. Your error monitor uses the private maps to show you symbolicated stack traces in your dashboard — without ever serving them publicly. This is the industry-standard approach and the one all major error monitoring docs recommend.
Does minification without source maps protect my code?
Minification provides weak obfuscation — variable names are shortened and whitespace removed, making the code harder to read, but a determined reader can still reverse-engineer your business logic. If your source maps are exposed, minification offers zero protection; the map reconstructs everything. If you need real code protection, consider a dedicated JavaScript obfuscator on top of (or instead of) minification. But be aware: all client-side code should be treated as visible regardless, because it runs in users' browsers.
Why do source maps end up in production by default?
Most build tools enable source maps in development for debugging, and the production setting inherits from the same base config unless explicitly overridden. Vite's build.sourcemap defaults to false, but some plugin presets set it to true. Create React App requires an explicit GENERATE_SOURCEMAP=false to disable. Next.js disables them by default in production but has options that can re-enable them. The inconsistency means source maps often appear when someone copies a dev config to production, upgrades a framework, or changes build tools.
What's the SourceMappingURL comment at the end of my bundle?
The last line of a built JavaScript file often reads //# sourceMappingURL=index.chunk.js.map. This comment tells the browser where to find the source map for that file. When a browser (or tool like ExposureCheck) reads this, it constructs the .map URL and requests it. Removing the comment from your bundle or blocking *.map requests at the server both prevent the map from loading in a visitor's browser, but the cleanest fix is not generating the map file at all.
Related guides in the ExposureCheck suite
Rotate credentials, block the path on every hosting platform, and verify the fix across Nginx, Apache, Vercel, and Netlify.
Prevention Prevent exposed filesServer configuration, deploy workflow, and .gitignore patterns to keep sensitive files out of your public webroot.
Pre-commit LeakCheckScan your source code and .env files for hardcoded API keys before they reach your repo or your bundle.