Source Map Leak in an AI Coding CLI: What Was Exposed and How to Prevent It

    This article analyzes an accidental source code leak in a popular AI coding CLI, where a published package included full source maps. It explains how `sources` and `sourcesContent` expose original code, what the leaked codebase revealed about the tool’s architecture, which risks matter and which do not, and how teams can add build, artifact, and release safeguards to prevent similar incidents.

    1. What Happened: A Self-Inflicted Source Code Leak

    A recent release of a popular AI coding command-line tool was found by security researchers to include complete source map files in the package published to a package registry. Within hours, the news spread quickly. Community members had already created mirrored repositories containing the organized source code, attracting significant attention and copies.

    Notably, this was not an external intrusion, and it did not involve model weights or user data. The actual cause was that the publisher included debugging source maps in the package during the build process. The attack surface was zero, but the information exposure was complete—a typical “self-inflicted” leak.

    2. Technical Root Cause: What Source Maps Expose

    Source maps are common artifacts in frontend and build toolchains. They map compressed or transpiled code back to the original source, making it easier to locate the real file and line number in a debugger. They usually contain two key arrays:

    • sources: a list of original file paths;
    • sourcesContent: the complete original code text corresponding one-to-one with those paths.

    This means that anyone with the .map file can restore the entire original implementation without decompiling or deobfuscating—simply by opening it with a JSON parser. The extraction logic often takes only a dozen lines of script:

    1. const fs = require('fs');
    2. const map = JSON.parse(fs.readFileSync('bundle.js.map', 'utf8'));
    3. map.sources.forEach((p, i) => {
    4. fs.mkdirSync('out/' + p.split('/').slice(0, -1).join('/'), { recursive: true });
    5. fs.writeFileSync('out/' + p, map.sourcesContent[i] || '');
    6. });

    The package size also showed signs of trouble: it grew from about 17MB to 31MB, with the extra size coming from the tens-of-megabytes mapping file. A sudden size increase is itself one of the easiest signals for outsiders to notice.

    What made it worse was that the same issue had occurred once before, when the tool was first released a year earlier, and had been fixed at that time. One version iteration later, the mapping file was included in the artifact again. Since the previous version was still clean, it was most likely introduced accidentally during a build configuration change rather than intentionally published.

    3. What Was Leaked: A Complete Technical Portrait of a Modern CLI

    The leaked source code contained about 1,900 source files and roughly 510,000 lines of code, covering the entire implementation of the CLI. It revealed a fairly typical modern Node ecosystem technology stack:

    • Runtime: a high-performance JavaScript runtime rather than a traditional Node runtime;
    • Terminal UI: React combined with a terminal-oriented rendering library (an Ink-like approach), drawing interactive interfaces in a component-based way;
    • Command parsing: a mature CLI framework (a Commander-like approach);
    • Runtime validation: a schema validation library such as Zod for input constraints;
    • Search capability: a built-in high-performance text search binary (a ripgrep-like approach);
    • Protocol and observability: integration with an MCP-like protocol SDK and OpenTelemetry tracing;
    • Feature rollout: feature flags controlled through a feature flag platform (a GrowthBook-like approach).

    Using React to build a command-line interface is especially noteworthy: it shows that terminal interaction has been engineered as a “renderable UI.” State management, component reuse, and asynchronous rendering all follow frontend experience, with interaction effects driven by the component tree rather than imperative string concatenation.

    In terms of capabilities, the source registered 39 tools covering command execution, file reading, file editing, file writing, path matching, content search, sub-agent dispatch, web scraping, web search, protocol extensions, skill loading, task creation, and more. It also included more than 50 slash commands, such as diagnostics, diff viewing, cost statistics, cross-platform bridging, and several internal debugging commands. The permission checks, input validation, and error-handling paths for each tool were all clearly readable.

    4. Impact Boundaries: What to Worry About and What Not to

    An objective assessment needs to separate risks by layer:

    1. For ordinary users: it does not involve model weights, accounts, or user data, so the direct runtime security risk is low.
    2. For the developer: the core assets are prompt orchestration, the tool permission model, internal subsystem design, and engineering conventions. Once fully readable, competitive barriers and iteration pace can be compressed.
    3. For the ecosystem: readable source code will accelerate third-party plugins and compatible implementations, while lowering the barrier to vulnerability research and increasing pressure on security response.

    The conclusion is that this was not a security incident, but an intellectual property and engineering confidentiality incident.

    5. Prevention Practices: Layered Defenses from Build to Release

    To avoid similar issues, the pipeline needs a “disabled by default, explicitly enabled” policy at each stage:

    • Build configuration: force source map output off in production mode; keep mapping files only in internal artifact archives and out of release packages;
    • Artifact audit: compare package contents before release and hard-block .map files, .d.ts files, test fixtures, and internal documentation;
    • Size gate: set a package size threshold and block release with an alert when the size exceeds a certain percentage above the baseline;
    • Dependency and configuration review: include build configuration changes in code review to prevent leaks introduced by casual edits;
    • Secret scanning: scan artifacts and commit history for tokens, internal addresses, and internal domains;
    • Observability: archive hashes of release artifacts so that, when external mirrors appear, the version and differences can be located quickly;
    • Response plan: once a leak occurs, follow an “assess—communicate—fix—retrospective” process, first determine data-plane risk, then decide the disclosure approach.

    6. Recommendations for Users

    For developers, readable source code is high-quality material for learning modern CLI architecture, but license and compliance requirements should be respected, and it should be used only for research and learning. For enterprise users, vendor selection should focus on supply chain security capabilities: whether artifacts are auditable, whether versions are reproducible, and whether releases have gates. These reflect long-term reliability more than a feature list. If an enterprise builds internal R&D processes on top of AI coding tools, it is advisable to build its own artifact repository and admission policies, bring external tool versions, sizes, and content inventories into unified governance, and use common cloud capabilities such as object storage, logging services, and monitoring alerts for archiving and tracking.