Source Map Security: Lessons from an AI Coding Tool Source Code Leak

    An accidentally published Source Map exposed the implementation of an AI coding CLI, highlighting gaps in build configuration and release controls. This article explains how embedded source code becomes accessible, why similar incidents recur, and how artifact checks, private Source Map storage, and release monitoring can reduce the risk.

    1. Incident Review: A Release That Exposed Its Own Source Code

    Security researchers recently reported a source code leak involving an AI coding command-line tool from a major vendor. Its latest npm package accidentally included a 57 MB Source Map file. The published package had grown from 17 MB to 31 MB, an unusual increase that drew researchers’ attention.

    A Source Map maps minified or obfuscated code back to its original source. It is a useful debugging tool, but when it includes the sourcesContent field, it can also contain the source code itself. Anyone with access to that file can recover the embedded TypeScript code without decompilation or deobfuscation.

    According to the disclosure, the exposed material included approximately 1,900 source files and more than 500,000 lines of code. It revealed core implementation details, including the tool registration system, permission controls, input validation, and error handling.

    More concerning, the team had reportedly experienced the same problem in an early release a year earlier. Although that incident was fixed, subsequent build configuration changes reintroduced the issue. This points to a systemic gap in release safeguards rather than simply an individual mistake.

    The impact should also be kept in perspective. This type of exposure does not typically include model weights or user data and does not, by itself, establish a direct security risk to end users. The primary loss is the disclosure of proprietary implementation details and architectural decisions.

    2. How Source Maps Can Expose Original Code

    Understanding the incident starts with the structure of a Source Map.

    A Source Map is a JSON file with several core fields:

    • version: The Source Map specification version.
    • sources: An array of original source file paths.
    • sourcesContent: An array containing original source text, with entries corresponding to sources.
    • names: Original identifiers, such as variable and function names.
    • mappings: VLQ-encoded position data linking locations in the generated code to locations in the original source.

    The critical field is sourcesContent. Depending on their defaults and configuration, build tools may embed complete source files to make debugging easier. When that content is present, extracting it requires little more than a short script:

    1. const fs = require('fs');
    2. const map = JSON.parse(fs.readFileSync('bundle.js.map', 'utf8'));
    3. map.sources.forEach((sourcePath, index) => {
    4. const content = map.sourcesContent[index];
    5. if (content) {
    6. const outputPath = './recovered/' + sourcePath;
    7. fs.mkdirSync(require('path').dirname(outputPath), { recursive: true });
    8. fs.writeFileSync(outputPath, content);
    9. }
    10. });

    For the files embedded in the map, this illustrates how directly the source text and directory layout can be recovered. It helps explain why the community was reportedly able to assemble a source repository within hours of the disclosure.

    The exposed structure also revealed several architectural choices: a modern JavaScript runtime in place of traditional Node.js execution, a React component model for terminal interfaces, a standardized registration mechanism for dozens of tool capabilities, and a feature flag platform for staged rollouts.

    These decisions may be instructive to other engineering teams, but accidental publication is not how an organization would choose to share them.

    3. Root Causes: Why Similar Incidents Recur

    Accidental source code exposure of this kind generally points to three categories of process failure.

    Build Configuration Changes Lack Sufficient Controls

    When one release is clean and the next contains debugging artifacts, likely areas to investigate include build scripts, bundler upgrades, and configuration changes.

    For example, some build tools generate inline Source Maps in development mode. If environment detection behaves incorrectly, a production build may inherit those debugging settings.

    The underlying problem is not merely that Source Map generation was enabled. It is that a release-relevant configuration change could reach publication without an effective check.

    Release Artifacts Are Not Audited Before Publication

    An increase from 17 MB to 31 MB is close to a doubling in package size. That should have prompted investigation, yet no automated check appears to have blocked the release.

    A robust release pipeline should enforce checks on package size, file inventories, and prohibited file types. Reviewing the source repository alone is insufficient: the security boundary is the artifact actually being distributed.

    Previous Incidents Do Not Become Lasting Safeguards

    A repeat incident suggests that the earlier response may have been limited to removing the offending file and publishing a corrected version.

    That fixes the immediate release, but it does not prevent recurrence. The durable response is to turn the lesson into an automated release gate.

    This is a common engineering management failure: resolving the visible defect while leaving the conditions that produced it unchanged.

    4. Practical Defenses for a Safer Release Pipeline

    The following measures address both accidental inclusion and the process gaps that allow it to reach users.

    1. Validate Release Contents with an Allowlist

    Add artifact inspection to the release process. Explicitly exclude files that do not belong in the distribution, such as .map files, unintended .ts source files, tests, and environment configuration files.

    For npm packages, the files field can define an explicit inclusion list:

    1. {
    2. "files": ["dist/cli.js", "dist/assets"]
    3. }

    Use npm pack --dry-run before publication to inspect the package contents. Incorporate the resulting file inventory and package-size baseline into CI checks rather than relying solely on manual review.

    2. Separate Debugging Artifacts from Public Releases

    If Source Maps are required for production error analysis, upload them to a private error-monitoring system instead of distributing them with the package.

    Error-monitoring solutions commonly support privately hosted Source Maps so that stack traces can be resolved on the server side. This preserves their debugging value without making the source content part of the public release.

    3. Block Unexpected Package-Size Changes

    Record package size for each release and compare it with the previous version. If the change exceeds a defined threshold—for example, 20%—block publication pending human review.

    Size changes are not proof of a security issue, but they are a useful signal. In this incident, the near-doubling of the published package size should have been an easily detectable warning.

    4. Apply Least Privilege to Publishing Credentials

    Publishing tokens should have narrowly scoped permissions and be rotated regularly. Combine token controls with two-factor authentication to reduce the risk of unauthorized releases following credential exposure.

    Enable publication provenance where supported so that a distributed artifact can be traced to its build record.

    These controls address release integrity alongside the artifact-content checks needed to prevent accidental source exposure.

    5. Turn Incident Findings into Enforceable Checks

    Every release incident should produce actionable pipeline checks, not just a written retrospective or verbal reminder.

    Maintain a release security checklist covering risks such as:

    • Unintended Source Maps.
    • Hardcoded secrets.
    • Internal domain names.
    • Dependency license requirements.

    Automate these checks wherever practical so that lessons remain effective as teams, dependencies, and build configurations change.

    Teams using cloud-based development infrastructure can integrate artifact checks with their logging, monitoring, alerting, and CI/CD systems. The goal is an auditable delivery process from code submission through artifact publication.

    5. Conclusion

    Source code exposure does not always begin with a sophisticated external attack. It can result from a build setting and a release process that fails to inspect its own output.

    A Source Map containing sourcesContent can disclose substantial portions of a codebase directly. Protecting against that outcome requires four complementary controls: build configuration governance, artifact auditing, package-size monitoring, and lasting safeguards derived from previous incidents.

    The central lesson is straightforward: release security is not a one-time cleanup. It is an engineering capability that must remain built into the delivery pipeline.