Source Maps in Production: What They Give Away

A source map turns your minified JavaScript back into readable code. Useful while building, risky when it is published. Here is what is inside one, how to check yours and how to turn it off.

Dr. Security3 MIN READ

πŸ’‘ The short version: a source map is a file that lets tools turn your squashed, unreadable production JavaScript back into the code you actually wrote. If yours is public, so is your code, comments and all. It isn't a break-in by itself, but it hands a stranger a much easier job.

When your app is built for production, the JavaScript gets minified: names shortened, whitespace gone, everything squeezed into a few giant lines. Source maps exist so that when something breaks, your error tool can show you the real file and line instead of a.b(c). πŸ—ΊοΈ Great for debugging. Less great when the map ships to every visitor.

πŸ“¦ What's inside a source map

  • The names of your original files and folders, which reveal how your project is organised.
  • Very often the full original source code, as a sourcesContent section.
  • Your comments, including the one that says // TODO: remove hardcoded key.

Minified code can still be read by a patient person. A source map makes it easy for everyone, and makes it much quicker to spot endpoints, hidden routes and anything you forgot was there.

πŸ” Check yours in two minutes

  1. Open your live site, view the loaded scripts and open one in a new tab.
  2. Scroll to the very end. A line like //# sourceMappingURL=app.js.map says a map exists.
  3. Request that address. If a JSON file comes back, your map is public.
  4. Repeat for a couple of other scripts, including the main one.

No comment at the end doesn't prove there's no map, because some setups serve them by convention. Try adding .map to a script's address too.

πŸ› οΈ Turning them off

Many frameworks don't publish browser source maps in production by default, but a setting or a plugin can easily switch them on. Check your build configuration for these:

ToolSetting to look for
Next.jsproductionBrowserSourceMaps, which should not be true
Vitebuild.sourcemap, which should be false (or "hidden")
Webpackdevtool, which should be false or hidden-source-map
Error trackers (Sentry and similar)Upload the maps to the tracker during the build, then don't deploy them with the site

A hidden map still gets produced, but the script no longer points to it, which is handy for uploading to an error tracker.

⚠️ The important caveat

Turning maps off hides your code. It doesn't make secrets safe. If a key is written into your code, it's also in the minified bundle, just harder to read. The real fix is keeping secrets on the server. Here's how to find and remove them.

πŸ€– How a scan treats it

Source maps are part of the exposed-files group in a Dr. Security report, next to .env files, .git folders and backups. A free report shows how many issues that group has, and the full report names each one and how to fix it. See also the other files that shouldn't be public.

πŸš€ Curious if your maps are showing? Run a free scan and find out.

  • source maps production
  • javascript source map security
  • sourcemap exposed
  • frontend security
  • next.js source maps

FIND OUT WHAT YOU'RE EXPOSING.