Skip to content
SEO Optimizer is live, Audit on page SEO and AI-search readiness. Try it free
Security

Are Source Maps in Production a Security Risk?

·5 min read

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/ or feature-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:

app.min.jsA sourceMappingURL comment at the end of a bundle
//# sourceMappingURL=app.min.js.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.

next.config.tsNext.js: browser source maps stay off in production
const nextConfig = {
  // Default is false. Only enable it if the maps are uploaded and removed from the deploy.
  productionBrowserSourceMaps: false,
};
export default nextConfig;
vite.config.tsVite: generate maps without the sourceMappingURL comment
export default {
  build: {
    sourcemap: "hidden", // or false to skip maps entirely
  },
};
webpack.config.jswebpack: hidden source maps
module.exports = {
  mode: "production",
  devtool: "hidden-source-map",
};

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.

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.

FAQ

Häufig gestellte Fragen

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.

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