Source Map Leak Post-Mortem: How One Build Config Error Exposed a Smart Coding Tool's Full Source Code

    A smart coding tool distributed through public package registries accidentally published a ~60 MB Source Map file, making its complete source code recoverable in minutes. This post-mortem breaks down how a default build setting and a missing exclusion rule turned into a full source code leak, explains why Source Maps are effectively plaintext source, lists the risks that outlast the code itself, and outlines practical release controls such as artifact allowlists, explicit build configuration, pre-publish scanning gates, credential governance, and an incident response order. If you ship CLIs, SDKs, or libraries, this guide helps you keep debuggability and confidentiality from conflicting in your pipeline.

    1. Incident Overview: How One Configuration Oversight Became a Full Source Code Leak

    The smart coding tool was distributed through a public package registry using a one-command install model, which is the mainstream delivery method for CLI-based developer tools today. A package registry is essentially a public software distribution platform: developers package and upload their tools, and users pull and install them as needed. This model is highly efficient, but it also means that if an unintended file slips into the published artifact, it spreads just as fast.

    Under normal engineering practice, production artifacts are minified and obfuscated: variable names are replaced with short identifiers, and code structure is rearranged so the output is essentially unreadable by humans. To make defect localization easier during development, however, build tools generate an extra Source Map file — effectively a lookup table that maps minified positions back to the original files and original line numbers. This type of file should only be used in development environments and must be excluded from production releases.

    The problem lay precisely here. When a particular version was published, the underlying build tool had Source Map generation enabled by default, and the release configuration never added the .map extension to the exclusion list. As a result, a mapping file close to 60 MB was pushed to the public registry along with everything else. Every user who installed that version downloaded the file locally.

    More importantly, a mapping file is plain JSON with two parallel arrays: one holds source file paths, and the other holds the full text content of each corresponding file. In other words, what leaked was not a set of clues but the source code itself. A few dozen lines of script writing each entry to disk by path are enough to fully reconstruct the project directory. The incident also surfaced a reference pointing to a public object storage address, from which the complete packaged source directory could be downloaded directly — skipping even the parsing step.

    The timeline is equally worth noting: first, security researchers disclosed the issue on social media; within hours, multiple mirror repositories appeared on a public code hosting platform, and the source code spread quickly. A few of those repositories amassed significant attention in a very short time, even though they no longer contained the original code. This shows that source code leaks have almost no “recall window,” and the focus of any response must be shifted to before release.

    2. Under the Hood: Why a Source Map Equals Plaintext Source

    Source Maps were designed for debuggability, not confidentiality. Their core fields typically include:

    1. {
    2. "version": 3,
    3. "file": "cli.js",
    4. "sources": ["src/index.ts", "src/parser.ts"],
    5. "sourcesContent": ["full original file text...", "full original file text..."],
    6. "mappings": "AAAA,CAAC..."
    7. }
    • sources: original file paths, often exposing the project directory structure and module breakdown;
    • sourcesContent: the full original file text corresponding to each path — the decisive field for a leak;
    • mappings: encoded mapping from minified positions to original positions, used for breakpoint placement.

    The reconstruction logic is straightforward:

    1. import json
    2. with open("cli.js.map", encoding="utf-8") as f:
    3. sm = json.load(f)
    4. for path, content in zip(sm.get("sources", []), sm.get("sourcesContent", [])):
    5. if content is None:
    6. continue
    7. safe_path = path.lstrip("./").replace("..", "_")
    8. with open(safe_path, "w", encoding="utf-8") as out:
    9. out.write(content)

    One common misconception needs clarifying: obfuscation and minification are not security mechanisms. They only raise the cost of reading the output and provide no confidentiality strength whatsoever. As long as a client can execute it, the artifact can always be recovered into an analyzable form; Source Maps simply reduce that cost to near zero. The protective logic must therefore be “do not publish sensitive content,” not “make sensitive content harder to read.”

    3. Risk Inventory: More Than Just Code Leaks

    In incidents like this, the long-term impact often comes not from the business code itself but from four categories of information that leak along with the artifact:

    1. Internal implementation details: module breakdown, call chains, and protocol wrapping — useful to attackers for crafting targeted inputs.
    2. Credentials and configuration: hardcoded tokens, internal addresses, debug switches, and third-party service endpoints — the highest-severity items.
    3. Prompts and policy assets: for smart coding products, system prompts, rule templates, and evaluation samples are often as sensitive as the code.
    4. Compliance and contractual risk: open source license obligations, customer data boundaries, and trade secret clauses may all be triggered at once.

    The distribution phase also creates secondary risks: mirror repositories may be seeded with backdoors, and users may mistakenly install tampered versions, forming a chain of supply chain problems.

    4. Protection Practices: Making the Release Pipeline Verifiable

    4.1 Build Artifact Allowlist

    A release package should contain only explicitly declared files and reject everything else by default. Using a common package manifest as an example:

    1. {
    2. "name": "demo-cli",
    3. "files": ["dist/", "README.md"],
    4. "scripts": {
    5. "prepublishOnly": "npm run build && npm run verify:artifacts"
    6. }
    7. }

    The verification script should exit with a hard failure rather than print a warning:

    1. // verify-artifacts.mjs
    2. import { readdirSync, readFileSync } from "node:fs";
    3. const forbidden = [/\.map$/, /\.env/, /\.pem$/, /\.key$/, /secret/i];
    4. const files = readdirSync("dist", { recursive: true });
    5. for (const f of files) {
    6. if (forbidden.some((re) => re.test(f))) {
    7. console.error(`Forbidden file to publish: ${f}`);
    8. process.exit(1);
    9. }
    10. }

    4.2 Explicit Build Configuration

    Do not rely on tool defaults. Production builds should explicitly disable mapping output, or direct it to a directory outside the repository:

    1. // Illustration: disable source map in production build
    2. export default {
    3. build: {
    4. minify: true,
    5. sourcemap: false, // no .map generated for production artifacts
    6. },
    7. };

    If online troubleshooting genuinely requires it, the correct approach is internal retention: upload mapping files to a controlled internal artifact repository or a private object storage bucket, correlate them by version with an error reporting system, and reconstruct stack traces only on the server side — never deliver them to the client.

    4.3 Pre-Release Scanning and Gating

    Add three types of automated checks to the pipeline: sensitive information scanning (entropy detection plus rule matching), artifact manifest comparison (set difference against the allowlist), and size anomaly alerts (a single file of tens of megabytes is usually a warning sign). Any failed check blocks the release, and audit records are preserved.

    4.4 Permission and Credential Governance

    • Use short-lived tokens for release credentials, scoped to specific repositories and permissions; never leave long-lived, high-privilege tokens on local machines.
    • Apply two-person review for critical version releases, and route configuration changes through code review.
    • Disable anonymous listing and anonymous reads on the storage side; public distribution should go only through a dedicated release channel.

    4.5 Response Plan

    Once a leak is confirmed, handle it in a fixed order: first revoke credentials and rotate keys, then take down the affected version and request its retraction, then assess the impact scope and publish a statement, and finally review the gap in the gating controls. Always pull the version before explaining it — the speed of propagation determines the value of every minute.

    5. Recommendations for Users

    For enterprises and individual developers, lock versions, verify integrity hashes, prefer official signed channels, and stay alert to mirrors of unknown origin. When introducing dependencies into your own projects, also check whether their artifacts contain mapping files, to avoid bringing the risk into your internal network.

    6. Conclusion

    The root cause of this incident was not a sophisticated attack technique but a default value and a missing exclusion list. The usability goal of Source Maps and the goal of confidentiality conflict inherently; in engineering, only three gates can hold the line: do not publish by default, enforce strong pre-release validation, and minimize credentials. Fixing these three points into the pipeline is what allows a convenient distribution model to proceed without trading away source code and credentials.