Source maps in production
| Class | Secrets, Reconnaissance |
|---|---|
| CWE | CWE-540: Inclusion of Sensitive Information in Source Code |
| OWASP Top 10 | A02:2025 Security Misconfiguration |
| Standard | ECMA-426, source map format version 3 |
| Typical severity | Medium; higher when the source holds a key |
| Affects | Front-end builds made with Next.js, Vite, webpack or Bun; npm packages; mobile apps built from JavaScript |
A build tool that turns src/checkout.ts into a file such as assets/index-4f2a.js can also write index-4f2a.js.map next to it, a JSON file that records where each piece of the minified code output came from.1 Browser developer tools read that file to show the original code in place of the optimized bundle, so a developer can debug the code they wrote.2 A source map left on a public server does the same for anyone who downloads it: it rebuilds the project's source files, often with their comments and original names.
The file format
The format began as a debugging aid for the Closure Inspector tool. The current version is always 3, and in 2023 and 2024 it was turned into the Ecma standard ECMA-426, which covers code compiled to JavaScript, WebAssembly and CSS.1 A map is one JSON object:
{
"version": 3,
"file": "index-4f2a.js",
"sources": ["../src/checkout.ts", "../src/admin/refunds.ts"],
"sourcesContent": ["// Staff discount, remove before launch\nexport function applyDiscount(...", "..."],
"names": ["applyDiscount", "refundOrder"],
"mappings": "AAAA,SAASA,cAAc;..."
}sources lists the original files by path. sourcesContent is optional and holds the full text of each of those files, in the same order; the standard intends it for sources that cannot be hosted. names holds the original identifiers, and mappings is a compact string of base64 VLQ numbers that ties each position in the generated file to a file, line, column and name in the original.1
A map with sourcesContent filled in is a copy of the source tree. A map without it still gives away every file path and the original function and variable names.
How a map is found
Generated code points to its map in one of two ways. A comment at the end of the file, //# sourceMappingURL=index-4f2a.js.map, gives a relative or absolute address. An HTTP response header, SourceMap: /assets/index-4f2a.js.map, does the same from the server, and wins when both are present.12 The older header name X-SourceMap is deprecated.2
The file stays reachable when the pointer is removed. By convention the map for page.js is named page.js.map,1 so a person who knows the bundle's address can request the map directly. A map can also be embedded: Vite's inline setting appends it to the JavaScript file itself as a data URI.3
What a public map gives away
Minified code is already public, since the browser has to run it. The map makes it readable again, with file and folder names that describe the application's structure, comments, original identifiers, and code for features that are built but switched off.4 Readable source lets an attacker follow the logic, look for bugs and pick out any login or password written into it.5 How serious a public map is depends on what the source contains, such as an API key or the address of an internal service (see Client-side code exposure, Debug mode in production and Exposed credentials in source code repositories).
Build tool settings
| Tool | Setting and default | What it writes |
|---|---|---|
| Next.js | productionBrowserSourceMaps, off | When on, maps next to the JavaScript files, served on request |
| Vite | build.sourcemap, false | true: separate file; 'inline': data URI in the bundle; 'hidden': separate file, no comment |
| webpack | devtool | false: none; source-map: file with comment; hidden-source-map: file, no comment; nosources-source-map: file without source text |
Next.js keeps production maps off so that the source does not leak to the client.6 Vite also defaults to no maps.3 For webpack, no map at all is the suggested starting point. Its documentation says a source-map file should be blocked for normal users, and that a hidden-source-map file belongs in error report tooling and should not be deployed. A nosources-source-map file leaves out sourcesContent and can be deployed to map stack traces in the browser.7
Error tracking without public maps
Error trackers use maps to turn a stack trace from a minified bundle into file names and line numbers. With Sentry, the build writes hidden maps, the Sentry plugin uploads them, and the maps are removed before the files reach the web server. Sentry's documentation warns that generated maps can end up public and leak source code, and gives two fixes: a server rule that refuses requests for .js.map files, or its plugin option that deletes the maps once the upload has finished.8
// vite.config.js
import { defineConfig } from "vite";
import { sentryVitePlugin } from "@sentry/bundler-plugins/vite";
export default defineConfig({
build: { sourcemap: "hidden" },
plugins: [
sentryVitePlugin({
org: "example-org",
project: "example-app",
authToken: process.env.SENTRY_AUTH_TOKEN,
sourcemaps: { filesToDeleteAfterUpload: ["./**/*.map"] },
}),
],
});Packages and apps
The same file causes the same exposure outside the browser. On 31 March 2026 a researcher found that version 2.1.88 of the @anthropic-ai/claude-code package on npm contained a map file. The map pointed to the complete TypeScript source, about 1,900 files and more than 512,000 lines, which could be downloaded as a ZIP from an Anthropic cloud storage bucket. The tool runs on Bun, which writes source maps unless told not to. Anthropic described it as "a release packaging issue caused by human error, not a security breach" and said no customer data or credentials were involved.4 The minified code had always been available; the map added the original names, comments, module layout and features hidden behind flags.4
For a package, the published file list decides what ships. Adding *.map to .npmignore, or listing allowed files in the files field of package.json keeps a map out, and npm pack --dry-run lists what would be published before it is.4
Checking a site
Open a page, find a JavaScript file it loads, and test three things: the last line of the file, the response headers, and the same address with .map added.
curl -s https://example.com/assets/index-4f2a.js | tail -c 200
curl -sI https://example.com/assets/index-4f2a.js | grep -i sourcemap
curl -s https://example.com/assets/index-4f2a.js.map | head -c 200A sourceMappingURL comment, a SourceMap header, or a JSON answer to the third request with "version":3 in it, means a map is public.
Check this project's production build for source maps. Look at productionBrowserSourceMaps in next.config.js, build.sourcemap in the Vite config, devtool in the webpack config and the source map setting of any Bun or esbuild build. Production builds must not publish .map files: turn maps off, or, if an error tracker needs them, use the hidden setting and delete the .map files after upload. For an npm package, make sure .map files are excluded through the files field in package.json or .npmignore, and show the output of npm pack --dry-run. List each file you changed.
In SecFlash
When the live site hands out a map, SecFlash reports SF-EXP-101 on the Exposure page. A map found inside a mobile build is SF-EXP-609, also on Exposure, and source maps shipped inside an installed app are one of the cases of SF-SEC-732 on the Security page.
See also
- Client-side code exposure
- Debug mode in production
- Public environment variables
- Exposed .git folder
- Directory listing
- Attack surface
- Category: Reconnaissance
References
- a b c d e Ecma International TC39-TG4 (2026). "ECMA-426: Source map format specification". tc39.es.
- a b c MDN contributors (2025). "SourceMap header". MDN Web Docs.
- a b "Build Options". Vite documentation.
- a b c d Wiggers, Steef-Jan (7 April 2026). "Anthropic Accidentally Exposes Claude Code Source via npm Source Map File". InfoQ.
- back "CWE-540: Inclusion of Sensitive Information in Source Code". Common Weakness Enumeration. MITRE.
- back "productionBrowserSourceMaps". Next.js Docs. Vercel.
- back "Devtool". webpack documentation.
- back "Uploading source maps: Vite". Sentry Docs.
External links
- Devtool, webpack documentation, with every source map mode compared
- CWE-540: Inclusion of Sensitive Information in Source Code, MITRE CWE