Source Map Leak Post-Mortem: How an AI Coding Tool Exposed Its Client Source Code

    This article reviews a Source Map leak in which an AI coding tool's CLI client accidentally published a roughly 60 MB .map file to a public package registry, allowing anyone to reconstruct the original source from the sources and sourcesContent arrays without any reverse engineering. It explains why Source Maps are inherently source carriers, what client-side leaks expose, and which engineering practices from AI coding clients are worth adopting. It closes with a release-hardening checklist covering artifact allowlists, stripping .map files, pre-publish scanning, zero-bundled credentials, storage permission audits, and incident response order.

    1. Incident Recap: A Delivery Accident That Could Have Been Avoided

    A command-line client for an AI coding tool was distributed through a public package registry. The developers packaged the tool and uploaded it to the public repository, where anyone could install it with a single command. This distribution model dramatically lowers the barrier to adoption, but it also means that any file included in the package becomes publicly accessible across the internet the moment it is uploaded.

    Under normal practice, code is minified and symbol-obfuscated before release, producing output that is nearly unreadable to humans. However, to speed up debugging during development, the build pipeline automatically generates Source Map files, which act as a lookup table mapping minified output back to the original source. These files are meant to be used only in development environments and must be excluded before release. The problem: in one release, Source Map generation was enabled by default in the bundler, and the publish configuration did not exclude .map files. As a result, a mapping file of nearly 60 MB was pushed directly to the public repository.

    A mapping file is essentially a JSON document with two corresponding arrays: sources records the original file paths, and sourcesContent records the full content of each file. Parsing this JSON and writing each entry back to disk restores the source code exactly as it was, with no “cracking” required.

    1. // Example: reconstructing the source tree from a mapping file
    2. const fs = require('fs');
    3. const path = require('path');
    4. const map = JSON.parse(fs.readFileSync('cli.js.map', 'utf8'));
    5. map.sources.forEach((p, i) => {
    6. const target = path.join('restored', p);
    7. fs.mkdirSync(path.dirname(target), { recursive: true });
    8. fs.writeFileSync(target, map.sourcesContent[i] || '');
    9. });

    More concerning, the mapping file also referenced a public address on an object storage service. Visiting that address allowed anyone to download the complete packaged source directory directly, with no script needed. Within hours of the news spreading, multiple mirror repositories appeared on public code hosting platforms, and a few of them gained significant attention in a very short time (the source was later removed). A similar incident had already occurred a year earlier, with the same step failing again. This repetition shows the problem is not individual carelessness but a process that lacks mandatory validation.

    2. Why Source Maps Are Dangerous: Bringing Debuggability into Production

    Source Maps are designed to map positions in minified or transpiled output back to their original locations, so debuggers and error reporting systems can display readable file names, line numbers, and variable names. Their value is unquestionable, but their data density makes them natural carriers of source code.

    The risk comes from three overlapping factors. First, the content is complete: sourcesContent inlines the full text. Second, the structure is self-explanatory: field names are clear, and the parsing barrier is extremely low. Third, distribution is public: access controls on package registries and object storage are often misconfigured to allow public reads. Constraining any one of these would break the leak chain, yet in practice all three tend to fail at once.

    3. What the Client Source Leak Exposed

    This type of incident leaks client-side code, which can span thousands of source files and hundreds of thousands of lines. It is important to be clear that client source code is not the same as server-side keys and data, but it does expose three categories of sensitive information: internal architecture and module boundaries, protocol details of interactions with the backend, and endpoint addresses and identifiers hard-coded in the client. The first two significantly reduce an attacker’s reconnaissance cost, and the third can be directly abused.

    Therefore, the first response action is not “delete the repository” but to rotate every credential that could have been bundled into the client, and to audit public-read permissions on object storage and package registries.

    4. Engineering Design and Security Boundaries Worth Learning From

    Setting the incident aside, the architecture of this kind of AI coding client includes several general practices worth studying.

    First, layered tool capabilities. Separating context collection, prompt assembly, model invocation, and result delivery into independent modules, with model invocation wrapped behind a unified gateway, makes it easy to switch backends and apply unified rate limiting.

    Second, least privilege and confirmation for dangerous operations. Introducing explicit confirmation and sandbox boundaries for high-risk actions such as file writes and command execution is a widely accepted industry practice.

    1. type ToolCall = { name: string; args: unknown };
    2. async function dispatch(call: ToolCall, ctx: Ctx) {
    3. if (HIGH_RISK.has(call.name) && !ctx.confirmed) {
    4. throw new Error('User confirmation required');
    5. }
    6. return await registry.run(call, ctx);
    7. }

    Third, context budget management. Segmenting, summarizing, and retrieving relevant content for overly long contexts, rather than simply truncating, can significantly improve performance on long tasks.

    Fourth, built-in observability. Structured logs, trace identifiers, and error reporting make problem diagnosis independent of source code readability.

    5. Release Pipeline Hardening Checklist

    • Build artifact allowlist: only explicitly declared files may enter the release package; everything else is rejected by default.
    • Mapping file policy: disable inline maps in production builds, or strip .map files uniformly at the release stage.
    • Automated pre-publish gate: add artifact scanning to the pipeline that blocks on source code signatures or credential signatures.
    • Zero bundled credentials: the client should not inline any long-lived credentials and should use short-lived tokens instead.
    • Storage permission review: object storage defaults to private; public read requires review and expiration.
    • Incident playbook: define the order of rotate credentials, retract artifacts, audit access, and archive the post-mortem.