Source Map Leak in an AI Coding Tool: How a Build Artifact Exposed the Full Source Code

    This article analyzes a recent incident in which a mainstream AI coding tool shipped a complete source map file inside its package registry artifact, allowing anyone to reconstruct the original source code with a few lines of JavaScript. It explains why source maps containing the sourcesContent field are equivalent to publishing source code, what architectural details the leak revealed, who is actually at risk, and six practical CI-level controls teams can use to prevent the same class of accident.

    1. What Happened: An “Accidental Open Source” Release

    A recent version of a mainstream AI coding tool was found by security researchers to include a complete debug map file in the artifact published to a package registry. The news spread within hours, and the community quickly assembled the recovered source into a public repository that picked up thousands of stars and tens of thousands of forks in a short time.

    Notably, this was not an external intrusion or a supply chain attack, but a configuration oversight in the release pipeline: the build artifact grew abruptly from roughly 17MB to 31MB, and the extra content was a map file of about 57MB (the figure differs depending on how decompressed content is counted). A similar issue had appeared once in an earlier version of the tool; it was fixed and then reintroduced, which indicates that changes to the build configuration lacked automated verification of artifact contents.

    The community’s overall assessment was measured: the incident did not involve model weights or user data, and poses no direct security risk to ordinary users. The real loss is that implementation details accumulated by the engineering team over years were fully exposed.

    2. Why a Map File Is Effectively a Source Code Dump

    Modern frontend and Node/Bun ecosystems generally minify and obfuscate code during bundling. The output is smaller and loads faster, but is nearly unreadable. To preserve debugging capability, build tools generate a map file that maps positions in the bundled output back to the original locations. Its structure typically contains two parallel arrays:

    1. {
    2. "version": 3,
    3. "sources": ["src/tools/read.ts", "src/tools/edit.ts"],
    4. "sourcesContent": ["export const readTool = { ... full source code ... }", "..."],
    5. "mappings": "AAAA,CAAC..."
    6. }

    The critical field is sourcesContent. To support breakpoint debugging and stack trace restoration, build tools inline the original file contents directly into the map file. This means an attacker needs no decompilation and no deobfuscation: parsing the JSON is enough to obtain the unmodified original implementation. The core logic of the extraction script used in this incident is under ten lines:

    1. const map = JSON.parse(await Bun.file("cli.js.map").text());
    2. map.sources.forEach((p, i) => {
    3. if (map.sourcesContent[i]) writeFileSync(p, map.sourcesContent[i]);
    4. });

    The conclusion is straightforward: once a map file ships with the artifact, it is equivalent to publishing the source code, and any “obfuscation strength” becomes meaningless.

    3. Architectural Information Exposed

    Judging from the recovered directory structure, the project contains roughly 1,900 source files and more than 500,000 lines of code, with a fairly representative technology stack:

    • The runtime is Bun rather than traditional Node.js.
    • The terminal UI is built on React and a terminal rendering library, meaning the command-line interaction is constructed in a component-based way.
    • Command-line parsing uses a mainstream command framework, and argument validation uses a schema-based validation library.
    • It bundles a high-performance search tool and integrates the MCP protocol, OpenTelemetry tracing, and a remote feature flag service.

    Writing a CLI with React is especially noteworthy: interactions in the terminal such as the cursor, lists, and streaming output are essentially re-renders driven by component state, which substantially lowers the development cost of complex interactions.

    On the capability side, its tool system contains about 39 tool implementations covering command execution, file read/write, glob and grep search, sub-agent dispatch, web fetching and search, external tool protocol integration, skill loading, and task creation. The command layer adds more than 50 slash commands, including diagnostics, diff viewing, cost statistics, and cross-device bridging. The permission checks, input schema validation, and error handling logic for every tool are all clearly visible, which makes the code both learning material and attack surface intelligence.

    4. Risk Breakdown: Who Should Care

    Affected party Risk level Notes
    Ordinary users Low No account data or model weights involved
    Vendor engineering team High Implementation details, internal naming, and roadmap direction exposed
    Enterprise in-house teams Medium-high Similar build oversights can leak internal system source code
    Security teams Medium Permission and validation logic can be used to design bypass paths

    The real lesson is that the barrier to a source code leak is often not adversarial attack and defense, but a single build pipeline configuration.

    5. Governance Recommendations for Enterprises

    1. Artifact allowlist verification: add an artifact manifest comparison to CI so the build fails when unexpected files such as .map, .d.ts, or test snapshots appear.
    2. Size baseline alerting: set a threshold on artifact size and automatically block the release on abnormal growth. The 17MB to 31MB jump in this incident could have been intercepted entirely.
    3. Separate map file publishing: upload debug maps only to internal error monitoring and logging services, never to public artifacts.
    4. Secret and configuration scanning: prohibit inline tokens, internal addresses, and default debug flag values in artifacts.
    5. Least-privilege review: treat the leaked permission logic as an attack surface checklist and confirm default-deny and manual confirmation steps item by item.
    6. Observability as a fallback: use monitoring alerts and tracing to identify anomalous calls rather than relying on code secrecy alone.

    If an enterprise chooses to integrate AI coding capabilities into its own R&D system, it can consider the general R&D and cloud tool chain capabilities offered by Baidu AI Cloud, combined with general categories such as object storage, log services, and monitoring and alerting, to complete artifact control and auditing.

    6. Conclusion

    The essence of a map file leak is a failed boundary between “debugging convenience” and “asset confidentiality.” For developers, it is a rare learning window. For engineering organizations, the more worthwhile investment is to bake artifact content verification, size baselines, and secret scanning into the pipeline, so that the same class of incident cannot pass through the release stage again.