Are Source Maps in Production a Security Risk?
A source map is a file that maps your minified JavaScript back to the original source code, so a browser's DevTools or an error tracker can show readable file names and line numbers. They are essential during development. Source maps in production are a different question: if the .map files are public, anyone can open DevTools and browse your front-end source as you wrote it, with comments, file structure and sometimes things that were never meant to ship.
What a Public Source Map Reveals
Minified JavaScript is already public, so a source map does not reveal anything the browser does not receive. It makes it much easier to read. With source maps in production, someone can see:
- Original source files and folder structure, including file names like
admin/,internal/orfeature-flags/. - Comments, which sometimes contain TODOs about security gaps, internal URLs or ticket numbers.
- Hidden routes and API endpoints, including admin or unreleased features shipped behind a flag.
- Secrets that were bundled by mistake. The real problem here is the bundled secret, but the source map makes it trivial to find. See how to fix hardcoded secrets.
- Server code, occasionally. Misconfigured builds have shipped maps that included server-side files.
How Serious Is It?
For most sites, public source maps in production are a low-severity information disclosure, not a vulnerability by themselves. Security through obscurity is weak, and any determined person can read minified code. But source maps lower the effort a lot, and they turn small mistakes, such as a leftover debug route or a key in a comment, into easy finds. Open source projects often publish them on purpose, and that is fine. For closed-source apps, the safer default is to keep them private.
How Browsers Find Source Maps
The last line of a minified file usually points to its map:
A server can also send a SourceMap HTTP header. Maps can even be inlined as a data: URL, which puts the whole original source inside the JavaScript file. Even with no comment, the map file may still be reachable by adding .map to the script URL.
Keep Error Tracking, Hide the Maps
The usual goal is not to stop generating source maps, but to stop serving them publicly. Build them as hidden source maps, upload them to your error tracker (Sentry, Bugsnag, Datadog and others support this), and do not deploy them to the public web server.
After uploading the maps to your error tracker in CI, delete the .map files from the build output before deploying, or block *.map at the web server. Check your CDN too: an old deploy may have left maps cached.
How to Check Your Site
Open DevTools, go to the Sources panel and see whether original file names appear under your domain. Or request a script URL with .map added. A security scan checks this automatically: it reads the sourceMappingURL comment or SourceMap header of the page's scripts, tries the .map URL when there is no reference, and confirms the response really is a source map before reporting "JavaScript source maps are publicly accessible". It also flags inline source maps. The same scan looks for secrets in those scripts and for vulnerable JavaScript libraries.
Related Leaks to Check
Source maps in production often come from the same build and deploy setup that leaks other files. Check that .git and .env are not public either: see how to fix an exposed .git directory and how to fix an exposed .env file. For the difference between checking code before and after it ships, see static vs. dynamic analysis.
Questions fréquentes
Usually a low-severity one. They make your front-end source easy to read, including comments, file structure and hidden routes. They are a bigger problem when the bundle also contains secrets or internal details.
Keep generating them for error tracking, but do not serve them publicly. Use hidden source maps, upload them to your error tracker and remove the .map files from the deployed build.
A source map generated without the sourceMappingURL comment in the JavaScript file. Error trackers can still use it if you upload it, but browsers will not find it automatically.
Open the Sources panel in DevTools and look for original file names, or add .map to one of your script URLs. A security scan checks this automatically.
Related reading
How to Fix an Exposed .git Directory
An exposed .git directory lets anyone download your source code, history and any secrets ever committed. How to confirm it, block it, clean up and stop it happening again.
How to Fix an Exposed .env File
If your .env file is publicly accessible, every secret in it is compromised. How to block it, rotate the keys, check for abuse and stop a .env file exposed again.
How to Fix Hardcoded Secrets in Your Codebase
An API key committed to a public (or even private) repo is compromised the moment it's pushed - how Scanverra's repo scanner finds them, and how to rotate and remove them properly.
Static Analysis vs. Dynamic Analysis: What Each Actually Catches
SAST reads your code without running it, DAST attacks a running app from the outside - what each approach can and can't see, and why most teams need both.
Subresource Integrity and Third-Party Script Security Explained
Every third-party script you load is code execution on your site by a company you don't control - what SRI actually verifies, and where it can and can't help.
Security Scan
Finds public source maps, secrets in scripts and exposed files.
Find out which headers you're missing
Run a free security scan and get a plain-English breakdown of every header, cert, and exposed secret.
Run a free security scan