Source maps in production: shipping your source code by accident
What a source map is
When you build a frontend, your readable code gets minified into a dense, unreadable blob for performance. A source map (bundle.js.map) is the reverse lookup: it tells the browser how to turn that blob back into your original files, with names and line numbers intact, so you can debug production issues comfortably. Useful — as long as only you can use it.
The accidental leak
The problem is that build tools generate source maps by default and deployment often ships everything in the output folder. So the .map files go live alongside the bundle, publicly reachable. Now the reverse lookup works for everyone: open dev tools on your site, head to the Sources panel, and your original folder structure and un-minified code appear. Minification was never security, and a public source map removes even that thin veil.
What an attacker actually gets
- Your real source — readable, with original names, making it trivial to study your logic and spot weaknesses.
- Comments — including the candid ones about workarounds, TODOs and where the bodies are buried.
- Internal structure — module names, API routes, feature flags, the shape of your app.
- Sometimes secrets — keys or tokens that were hidden inside minified code become plainly visible again.
How to check
Two quick ways. In the browser, open dev tools on your production site and look at the Sources panel — if you can see your original src/ tree and readable files, your maps are public. Directly, try requesting one of your bundle URLs with .map appended; if it downloads, it is exposed.
How to ship safely
You do not have to give up debugging — you have to stop publishing the maps:
- Do not emit source maps to production, or emit them and delete the
.mapfiles before the deploy step. - Upload them privately to your error tracker (the common pattern): the tool gets the maps for readable stack traces, the public never does.
- Block
.mapaccess at the server as a safety net, so a stray map still cannot be served. - Treat any exposed secret as leaked — if a key was visible through a public map, rotate it.
See whether yours are public
Source maps are easy to forget because everything still works whether they are public or not. An automated scan looks for the source-map references and the .map files an attacker would, and flags any that are reachable. Scan your site and make sure you have not published your source.