Source Map Leak Exposes Closed-Source AI Tool: A Full Postmortem of Distribution Security

    This article reviews a real-world security incident in which a closed-source AI coding CLI tool accidentally shipped a source map file to a public npm registry, exposing over 500,000 lines of TypeScript source code. It walks through the event timeline, analyzes the technical root causes — including build tool defaults, missing ignore rules, and lack of automated pre-publish audits — and provides a practical defense checklist for teams distributing proprietary software through public package repositories.

    Closed-source software distributed through public package registries relies on the assumption that only compiled, obfuscated artifacts reach users. That assumption was recently broken for a popular AI coding agent CLI tool when a bundled .js.map file — a debug artifact containing the full mapping back to original TypeScript source — was included in a published npm package. Anyone who downloaded the package could reconstruct the entire original codebase. This was not the first time: the same vendor had leaked source code via the same mechanism a year earlier, and had also recently exposed unpublished blog drafts and internal documents due to a misconfigured content management system permission.

    Event Background: When Closed Source “Goes Naked” on a Public Registry

    The tool in question is a mainstream AI programming agent CLI, distributed as closed-source via a public package registry. Closed-source means the vendor only publishes compiled, packaged binaries — users can run the software but cannot access the original source. However, due to a packaging oversight, a debug file that should have been excluded was uploaded alongside the release. Any developer who downloaded the npm package and extracted it could immediately recover the complete original TypeScript source code.

    This was not an isolated accident. Days earlier, the same vendor had accidentally exposed unpublished blog drafts and internal data due to a misconfigured access control on a content management system. And roughly one year earlier, on the tool’s first public release, the exact same source map leak occurred. The vendor fixed it urgently at the time, but a year later the same mistake resurfaced. This pattern points to a deeper issue: a one-off fix is not the same as systemic protection. If the root cause does not become a process-level automated check, the same class of incident will almost certainly recur.

    Full Timeline of the Incident

    1. The Leak Was Seeded (At the Moment of Release)

    The vendor pushed a new version of the tool to the public package registry. This release contained a .js.map file close to 60MB in size. A source map is a debug mapping file that preserves the complete correspondence between compiled JavaScript and the original source code — in many cases, it even embeds the original source text directly. According to security best practices, for closed-source software, such files must be excluded from the published artifacts before distribution.

    The problem did not stop there: the map file also contained references to the vendor’s own private object storage buckets. This further expands the attack surface — not only could the package contents be parsed, but the referenced cloud-stored resources could potentially be fetched directly.

    2. Public Disclosure (~Two Hours Later)

    A security researcher posted on social media about the leak, including instructions on how to obtain the source code. The post quickly drew tens of millions of views, turning the incident into a public security event within hours.

    3. Mass Archiving and Propagation

    Once sensitive data reaches the public internet, “deletion” becomes practically meaningless. Numerous mirror repositories appeared quickly, and the community began line-by-line analysis of the leaked code. The scale of the leak: approximately 1,900 files and over 510,000 lines of TypeScript. This was not a simple API wrapper but a complete engineering system, including:

    • dozens of fine-grained permission control and tool-calling modules;
    • a query engine implementation with tens of thousands of lines;
    • multi-agent coordination and scheduling mechanisms;
    • IDE integration bridge and persistent memory systems;
    • many unpublished feature flags, environment variables, and internal commands.

    Once exposed, this information goes beyond intellectual property loss — it can reveal potential security boundaries, internal experimental features, and unreleased architectural designs, providing reconnaissance material for future attackers.

    Root Cause Analysis: Why Did It Happen?

    1. Bundler Default Behavior

    Modern build tools (like a Bun-based build chain) generate source maps by default unless explicitly disabled. This is a developer-friendly convenience, but for closed-source distribution, this “default-on” behavior is exactly the hazard. Many framework defaults target open-source or internal development scenarios — closed-source commercial distribution requires a completely different set of defaults.

    2. Missing Ignore Rules

    Release toolchains typically rely on an ignore list (such as .npmignore or the files field in package.json) to control which files enter the published package. In this incident, someone forgot to exclude the .map file from that list. A seemingly small configuration omission resulted in a 60MB debug file being published alongside the release.

    3. No Pre-Publish Automated Audit

    If the release pipeline had included a “package content audit” step — for example, scanning the tarball for .map files or for URLs pointing to internal or private storage — the problem would have been caught before the release. Unfortunately, many teams only validate that the build “runs” and not whether the artifact “should be published”.

    4. Fixes Not Converted Into Mechanisms

    The exact same mistake had happened a year before. If, beyond the emergency fix, a CI-level guard rule had been added, the second incident would have been prevented entirely. A hard rule in security engineering: human memory and mindfulness cannot guarantee sustainability — only automated checks can.

    Defense Checklist: How to Avoid the Same Class of Incident

    The following practical recommendations, based on industry best practices, apply to any team distributing closed-source software through public package registries:

    1. Explicitly disable source maps in production builds, or ensure map files exist only on internal debug channels:
    1. // Example build configuration
    2. {
    3. "build": {
    4. "sourcemap": false,
    5. "minify": true
    6. }
    7. }
    1. Use a whitelist, not a blacklist, to control published content. Explicitly listing allowed files via the files field in package.json is safer than relying on ignore rules to exclude risky files. Whitelists naturally prevent omissions.

    2. Automatically scan the build artifact before publishing — add a guard check in CI, for example:

    1. # Pre-publish guard: detect map files and suspicious URLs
    2. if find ./dist -name "*.map" | grep -q .; then
    3. echo "Publish blocked: the artifact contains source maps"; exit 1
    4. fi
    5. grep -rE "(internal|staging)\.example" ./dist && exit 1
    1. Audit references and metadata in the artifact, including URLs pointing to private object storage, internal domain names, test environment configuration, and sensitive information in comments.

    2. Convert historical incidents into regression tests. After every security fix, add a corresponding automated check to ensure “the same mistake cannot be made twice”.

    3. Minimize the published package. The release should contain only files required for runtime; any debug, test, or documentation assets must be isolated from the public distribution channel.

    Deeper Takeaways

    The root cause of this incident is not technically sophisticated — a default build setting plus an unmaintained ignore list. Yet the consequences were severe. This illustrates that software supply chain security often depends less on advanced attack/defense techniques and more on the rigor and automation of the release process. For any team distributing closed-source software, a useful default assumption is: everything published is public data. All content that enters a public channel should be reviewed under the standard of “about to become fully public”. Only then can a team avoid the fate of failing the same way twice in a year.