skip to content

A security review finds a hotel-booking app's source maps publicly reachable; what do `sourcesContent`, `sources` and `names` reveal, and how do you keep maps private yet useful?

level: seniorimportance: should knowfreq 8%

answer

  1. the bundle is already public
  2. comments and full original text
  3. file paths and original identifiers
  4. unlinked versus unreachable
  5. maps never protect a secret

basics

~20 s

Public maps make the original code readable: sourcesContent holds every file's full text with comments, sources the project's file layout and names its original identifiers. Keep them off the public deploy, or behind access control, while internal tools still read them.

solid answer

~40 s

The bundle itself is already public; a map makes it readable and adds back what the build removed. `sourcesContent` is each original file's full text, comments, TODOs and all; `sources` is the project's file and folder layout, sometimes with build-machine paths; `names` gives back the original identifiers that minification shortened. Dropping `sourcesContent` hides the text but still discloses paths, names and the structure that maps onto them. To keep maps private yet useful: emit **hidden** maps and keep the `.map` files out of the public deploy, handing them to internal tooling; or serve them from a location only staff can reach, linked by the comment or by a `SourceMap` header sent to internal requests. Removing maps never protects a secret: a key compiled into the bundle is exposed with or without one.

go deeper

for a junior

Know that a public map makes the original code readable, comments included, and that the shipped bundle itself is never secret.

for a middle

Explain what sourcesContent, sources and names each disclose, and why dropping sourcesContent still leaves paths, names and structure visible.

for a senior

Fix exposure at the deploy, not only the build: hidden maps kept off the public origin, a restricted location or a selective header, and a secret found in source moved out and rotated.

for a principal

Decide where maps may live across the organisation, who may read them, and how every app's deploy enforces it, without taking readable errors away from the teams on call.

## What is already public Everything a browser downloads is public. The minified bundle of a hotel-booking app already contains its logic, its API routes, its feature checks and any string constant the build inlined. Minification makes that **hard to read**, not hidden. A source map therefore does not leak the program as such; it makes the program **readable**, and it adds back information the build had thrown away. ## What each field discloses | Field | What a reader learns | |---|---| | `sourcesContent` | The **full original text** of every listed file, including comments, TODOs, commented-out code and parts the shipped output never kept | | `sources` | The project's **file and folder layout**: module names, internal package names, and sometimes absolute build-machine paths if the build writes them | | `names` | The **original identifiers**: functions, variables and properties that the minifier shortened | | `mappings` | How every generated position lines up with those files and names, which turns the minified bundle back into structured code | The most sensitive field is usually `sourcesContent`. Comments are where developers write what code is for, which endpoints are unfinished, which customer a workaround is for, and which check is "temporary". None of that appears in a minified bundle; all of it appears in a map that embeds the sources. Leaving out `sourcesContent` helps, but only partly. Without it, a map still carries the paths, the names and the mappings. A reader cannot see comments, yet can still rebuild the program's structure under its real names, and tools will try to fetch each source by its URL, so those URLs must not resolve publicly either. ## What maps never protect - **Secrets.** An API key, a token or a private endpoint compiled into the bundle is exposed by the bundle itself. Deleting the map is not a fix; keeping the secret out of client code is. - **Business logic.** Anything the browser executes can be read, given time. Maps lower the cost of reading; withholding them raises it but does not prevent it. So the review's real question is what the maps add, and who should get that addition. ## Keeping maps private but useful The goal is that staff, and the tooling that translates error positions, can use full maps while the public cannot. The usual options: 1. **Emit hidden maps and keep them off the public origin.** The build writes the `.map` files without a link; the deploy step copies only bundles and assets to the public server and hands the maps to internal tooling. How that tooling receives them is the error pipeline's concern. 2. **Serve maps from a restricted location.** Emit external maps whose comment points to a host or path that answers only on the internal network or with authentication. Public visitors get a refusal; staff get the map in their own browser. 3. **Link selectively with the header.** Emit hidden maps, store them where staff can reach them, and have the server add a `SourceMap` response header only for requests from inside. ECMA-426 gives the header precedence over a comment, and it changes nothing in the file. 4. **Drop `sourcesContent` where text must never leave.** Useful as an extra layer, as long as nobody mistakes it for full privacy. Whichever option is chosen, verify the **deploy**, not the build settings: a hidden map uploaded beside its bundle is reachable at a guessable URL. ## Auditing what is published A review does not have to trust the configuration; it can check the result from outside, the way an outsider would: - Fetch a production bundle and read its last line: a `sourceMappingURL` comment means the map is advertised to everyone. - Check the response headers for `SourceMap` (and the deprecated `X-SourceMap`). - Request the bundle's URL with `.map` appended, even when nothing links it: a hidden map deployed beside its bundle answers here. - If a map is reachable, open it and look at `sources` for absolute paths and at `sourcesContent` for comments that name systems or people. Running the same checks after every release, rather than once, keeps a later configuration change from quietly reopening the exposure. ## Answering the review - State plainly that the bundle is public and the maps add readability, comments, names and layout. - Remove public access to the maps without losing internal ones, using one of the options above. - Check what is already out: maps published before the fix may have been fetched or cached. - Move any secret found in the source out of client code; no map setting fixes that.

  • If the maps are removed from the public server, can someone still read the app's code?
    Yes. The minified bundle is public and runs in the reader's own browser, so its logic can be studied, formatted and stepped through. Removing the maps takes away original names, comments and file layout, which makes that work slower, but it does not hide what the code does.
  • Why can a map without sourcesContent still leak the original code's text?
    Because tools then fetch each source from its URL in `sources`, resolved against the map's location. If those paths resolve to the original files on a public server, the text is one request away. Dropping `sourcesContent` is only private if the source URLs do not resolve publicly either.
  • Maps for the hotel-booking app were public for months; what does fixing access now not undo?
    Copies that were already fetched, cached by intermediaries or archived. Anything the maps revealed, such as internal endpoint names or comments about unfinished checks, should be treated as known, and any secret found in the sources must be rotated, not just removed.

  • Removing public source maps keeps an API key in the client code safe.
  • Without sourcesContent, a public map reveals nothing useful about the code.
  • Minification protects the code, so only the maps need guarding.
  • Hidden maps cannot be reached, even when they are deployed beside the bundle.
  • Names in a map only matter for debugging and disclose nothing.