Source Map Leak Post-Mortem: How a Forgotten Config File Exposed Source Code

    This article is a technical post-mortem of a source code leak caused by a Source Map file that was accidentally published with a CLI package. It explains what Source Maps contain, how the original source can be reconstructed without any real "hacking," and why client-side code exposure still raises serious risks. The article also covers the process failures behind the incident and provides a practical hardening checklist for release pipelines, plus response steps if a leak has already occurred.

    1. Incident Overview: A Forgotten Config File

    A command-line client for an AI coding tool was distributed through a public package registry. Developers can package a tool and upload it to this kind of public software repository, and users can install the executable with a single command. Before a formal release, such tools are usually compressed and symbol-obfuscated, producing artifacts that are smaller and extremely hard to read.

    The problem was in a debugging artifact. To locate exception stack traces inside compressed code, the build tool generates an additional source map file; its job is to establish a one-to-one mapping between “position in the compressed output” and “position in the original file.” This kind of file should only exist during development and debugging, and must be explicitly excluded at release time.

    In this version, however, the build tool had map file output enabled by default, and the release allowlist did not remove it. As a result, a map file close to 60 MB was pushed to the public registry along with everything else. Anyone who obtained the install package could download it.

    From an engineering perspective, this was not “being hacked.” It was a loss of control over the release artifact boundary: an intermediate build product that should never have left the build machine was treated as an official deliverable.

    2. What a Source Map Actually Leaks

    A source map file is essentially a piece of JSON text, and its core fields are usually these three:

    1. {
    2. "version": 3,
    3. "sources": ["src/cli/entry.ts", "src/core/session.ts"],
    4. "sourcesContent": ["original code...", "original code..."],
    5. "mappings": "AAAA,CAAC..."
    6. }
    • sources: a list of original file paths, exposing module layout, directory structure, and naming conventions;
    • sourcesContent: the complete original code, mapped one-to-one with the paths — this is the most damaging field;
    • mappings: the position-mapping encoding used to restore a stack trace to a specific line and column.

    Restoring the source requires no “cracking” at all — just iterate the arrays and write files by path:

    1. import json, os
    2. m = json.load(open("cli.js.map"))
    3. for path, code in zip(m["sources"], m.get("sourcesContent", [])):
    4. if code is None: continue
    5. p = os.path.normpath(path).lstrip("./")
    6. os.makedirs(os.path.dirname(p) or ".", exist_ok=True)
    7. open(p, "w").write(code)

    A worse scenario: the map file may still contain temporary artifact locations used during the build, such as a path in a publicly readable object storage bucket. If that bucket is configured for public read, an attacker does not even need to write a script — they can simply traverse the directory structure and download everything. This is a classic case of missing object storage permission governance. It is a separate problem from the code leak itself, yet the two often occur together.

    Within hours of the incident being discovered, multiple mirror repositories appeared on code hosting platforms, and the source code spread quickly across the public internet. Notably, the same class of incident had already happened once in the prior year — which suggests the problem is not individual carelessness, but a process that lacks mandatory validation.

    3. The Real Risk of Leaked Source Code

    What leaked was client-side code: roughly 1,900 source files and more than 500,000 lines. The risk is not that “the code was seen,” but that the following categories of information were exposed along with it:

    1. Internal implementation details: module boundaries, state management approach, caching strategy — a map for follow-on attacks.
    2. Prompt and policy text: prompt templates and tool-call constraints for an AI coding tool often exist as string constants; once leaked, they can be bypassed in a targeted way.
    3. Interface and protocol clues: internal service addresses, request header fields, and the naming of authentication flows can be used to craft probing requests.
    4. Hidden endpoints and switches: debug interfaces, feature flags, and undocumented parameters — the things attackers most want to find.
    5. Dependency inventory: combined with known vulnerabilities in third-party dependencies, this can directly form an attack chain.

    It must be emphasized: client-side code leakage does not mean the server was breached, but it significantly lowers the cost of attack, turning “black-box probing” into “white-box auditing.”

    4. Why the Same Mistake Happens Twice

    The root causes are usually four:

    • Defaults are the risk: the build tool produces map files by default, and the team kept the default configuration;
    • No artifact admission check: the release process only cares “can it be installed,” not “what is inside the package”;
    • No human review step: release is a one-click script with no second pair of eyes;
    • No governance of historical packages: published versions cannot be withdrawn, only overwritten by a new release, while old packages can still be cached and mirrored.

    5. Hardening Checklist for the Release Pipeline

    1) Explicit allowlist for build artifacts
    Do not use an “exclusion blacklist” approach; switch to “only files on the list may enter the release package.”

    1. {
    2. "files": ["dist/cli.js", "dist/chunk-*.js", "package.json", "README.md"]
    3. }

    2) Automated pre-release scanning (blocking)

    1. # Fail on any hit; do not continue the release
    2. find dist -name "*.map" -size +1M -print -quit | grep -q . && exit 1
    3. grep -rEn "AKIA|sk-[A-Za-z0-9]{16,}|password\s*=" dist && exit 1

    3) Send map files inward, not outward
    Upload map files to an internal artifact repository or error monitoring platform that requires authentication, and restore stack traces only on the server side, so the client artifact contains no such file at all.

    4) Artifact hashes and content audit trail
    Record the file list, size, hash, and scan results for every release, forming a traceable audit record that makes incident scoping easier.

    5) Least privilege for object storage
    Buckets holding build caches and temporary artifacts should be private by default, with public read forbidden; access should use short-lived credentials, with access logging and alerts on anomalous downloads enabled.

    6) Secret and address cleanup
    Temporary variables injected during the build must be stripped from artifacts, and a sensitive-information regex scan should be added in CI as a mandatory gate.

    6. What to Do If a Leak Has Already Happened

    1. Take the affected versions offline immediately and publish a fixed version;
    2. When distributed copies cannot be deleted, clearly state the risk boundary — do not exaggerate or conceal;
    3. Rotate credentials and tokens that may have leaked with the code; this is the highest-priority action;
    4. Audit server-side logs to look for anomalous probing and calls;
    5. Run a post-mortem and fill the pipeline gaps, writing “secure by default” into the build configuration template.

    In engineering practice on cloud platforms such as Baidu AI Cloud, this class of problem is usually contained by combining a private artifact repository, build pipeline admission checks, and log service with monitoring alerts. The core idea is the same: move security constraints forward into the build stage instead of relying on post-release remediation.

    7. Conclusion

    A source map file is a debugging asset and also the deliverable most likely to get out of control. The lesson from this incident is not “stop using Source Maps,” but three engineering principles: release artifacts must be allowlisted, sensitive files must be kept server-side, and storage permissions must be private by default. Only by hardening these three points into mandatory pipeline gates can this class of incident avoid happening a second time.