Source Map Leak Post-Mortem: How Debug Artifacts Expose Full Source Code

    This article reviews a source map leak in which a nearly 60 MB map file containing full original source was published to a public package registry. It explains why source maps are effectively source archives, breaks down the real risk boundary beyond "client code can be decompiled anyway," and lays out full-chain release gates across build, artifact, content, process, and organization layers to prevent repeat incidents.

    1. Incident Overview: A Configuration-Level Supply Chain Gap

    A smart coding tool accidentally pushed a source map file of nearly 60 MB to a public package registry during a public release. The file was meant to be a debugging aid, but it carried the complete original code text. Within hours of the news spreading, mirrors and reposts appeared across the internet, and the source code became effectively public.

    This was not the first time. The same tool had shipped an identical type of gap in an earlier release. Repeated mistakes point to a missing process and gate rather than individual error: the release pipeline lacked a hard constraint that debug artifacts must never leave the organization.

    The exposure was limited to the client side: roughly 1,900 source files and about 510,000 lines of code. It did not involve server-side logic, the key system, or user data, but it was enough to reveal internal architecture, module boundaries, and implementation details.

    2. How It Works: Why a Source Map Equals the Original Source

    2.1 The problem it solves

    Production scripts are minified and obfuscated: variable names are shortened, whitespace is stripped, and multiple files are merged. An online error stack then only shows something like a.b is not a function, which is extremely costly to trace. A map file builds a two-way index between “position after minification” and “original position.”

    2.2 Its data structure

    A map file is usually JSON with three core fields:

    1. {
    2. "version": 3,
    3. "sources": ["src/cli/index.ts", "src/core/agent.ts"],
    4. "sourcesContent": ["original text...", "original text..."],
    5. "mappings": "AAAA,CAAC,..."
    6. }
    • sources: an array of original file paths, equivalent to the project directory tree;
    • sourcesContent: the full source text, one-to-one with sources;
    • mappings: a VLQ-encoded position mapping string that handles row and column conversion.

    The key is sourcesContent. It is an optional field designed for “viewing the original text directly while debugging at breakpoints.” Once populated, the map file is no longer an index but a source archive. Any script that iterates over these two arrays and writes them to disk can losslessly reconstruct the project structure.

    Illustrative reconstruction logic:

    1. import json, os
    2. data = json.load(open("bundle.js.map"))
    3. for path, content in zip(data["sources"], data.get("sourcesContent", [])):
    4. target = path.replace("../", "").lstrip("/")
    5. os.makedirs(os.path.dirname(target) or ".", exist_ok=True)
    6. open(target, "w", encoding="utf-8").write(content)

    2.3 Why it is generated by default

    Modern bundlers generally treat “debuggability” as a default: they automatically generate map files in development mode, automatically append a //# sourceMappingURL= comment at the end of the output, and automatically keep sourcesContent. Defaults favor the development experience, whereas the default for production release should be “minimal exposure surface.” The two directions are opposite, and that is the root cause of the incident.

    The incident also had an amplifying factor: the map file referenced a public address on external object storage, so visitors could download the full directory without any parsing. This shows that “external references in build artifacts” are equally sensitive information that needs auditing.

    3. Deeper Analysis: The Real Risk Boundary

    Many people assume client code can be decompiled anyway, so it does not matter. That judgment is only half right. The risks break down as follows:

    1. Architecture and prompt assets leak. System prompts, tool-calling protocols, and context compression strategies are exposed in plaintext, and these are the hardest parts to obtain through decompilation.
    2. The attack surface expands. Internal API paths, authentication flows, degradation switches, and canary flags are all laid bare, letting attackers move from blind probing to targeted attacks.
    3. Compliance and IP risk. License headers, third-party dependency lists, internal comments, and ticket numbers are published together, which may trigger compliance review.
    4. Competition and trust cost. Repeating the same class of mistake damages a team that markets itself on security far more than the code itself does.

    4. Defense System: Full-Chain Gates from Build to Release

    4.1 Build layer: explicitly disable in production config

    1. // Production build config (illustrative)
    2. export default {
    3. minify: true,
    4. sourcemap: false, // disabled in production; use a separate channel for online debugging
    5. keepNames: false,
    6. define: { __DEV__: "false" }
    7. };

    If online debugging must retain mapping capability, the correct approach is: generate at build time, strip at release time, upload on demand to an internal error monitoring platform, and look it up through an authenticated endpoint, never distributing it with the package.

    4.2 Artifact layer: whitelist, not blacklist

    A blacklist (excluding *.map) can never keep up with new artifact types. Switch to a whitelist: only the explicit entry scripts, declaration files, and license list are allowed into the release directory.

    1. # Pre-release artifact check (illustrative)
    2. find dist -type f \
    3. \( -name "*.map" -o -name "*.ts" -o -name "*.env*" -o -name "*.log" \) \
    4. -print | tee artifacts_audit.txt
    5. test ! -s artifacts_audit.txt || exit 1

    4.3 Content layer: sensitive information scanning

    Add a dual-strategy scan of regex and entropy to the pipeline, covering keys, internal domains, object storage addresses, internal ticket numbers, and personal information. Any hit blocks the release; “manual confirmation to pass” is not allowed.

    4.4 Process layer: two-person review and immutable releases

    • Separate release credentials from build permissions, using short-lived tokens;
    • Require two-person review of the release manifest for critical versions;
    • Published versions cannot be overwritten; on discovering a leak, immediately revoke the version and rotate related credentials;
    • Set up an “external accessibility” inspection: periodically pull the public package anonymously and compare artifact fingerprints.

    4.5 Organization layer: fix the defaults

    Write “disable maps in production, block development dependencies from leaving” into engineering templates and scaffold default configs so new projects are secure by nature; also set checkpoints in continuous integration so non-compliant builds cannot produce releasable artifacts.

    5. Closing Thoughts

    The lesson here is not complicated: debugging convenience and minimal exposure surface are naturally in conflict, and the decision must be made by process rather than memory. For teams using smart coding tools, three things are worth doing: set scaffold defaults to a secure state, add dual artifact and content checks to the pipeline, and build an independent authenticated map lookup channel for online debugging. If you are using general capabilities such as Baidu AI Cloud object storage, log service, and monitoring alerts to handle artifact archiving and anomaly tracking, you should also stick to an “internally visible, externally unreachable” access policy to eliminate this class of risk at the architecture level.