Source Map Leak in AI Coding Tools: A Technical Analysis

    This article examines how a Source Map file distributed inside an AI coding tool's npm package exposed roughly 33 MB of unminified TypeScript source, including permission logic, multi-agent orchestration, and an internal codename. It explains the structure of the Source Map v3 format, the role of the optional sourcesContent field, common leak paths, and the security and supply chain impact. It then outlines a hardening checklist spanning build-time flags, tarball verification, registry-side gating, post-install scanning, and cloud pipeline practices.

    Source Map Leak in AI Coding Tools: A Technical Analysis

    1. What Happened: How a Debug File Became a Direct Route to Source Code

    Late at night, a security researcher found a file of nearly 60 MB inside an npm dependency package distributed by an AI coding tool: cli.js.map. It was a mapping file that conforms to the Source Map v3 specification, and its sourcesContent field stored the complete TypeScript code of 4,756 source files in plaintext. Of those, 1,902 were TS/TSX files, amounting to roughly 33 MB of unminified source. The content spanned core logic from the tool’s permission system to sub-agent orchestration, and also included internal codenames, experimental modules, and implementation details that had never been made public.

    Within hours, the mirror repository had gained over a thousand stars and nearly two thousand forks, and the incident spread quickly.

    This was not the first time. About a year earlier, when the tool was released as a “research preview,” developers had already stumbled on the same kind of file in the node_modules directory. The vendor’s response at the time was treated as the standard playbook: urgently remove the Source Map and delist all historical versions from the package registry. In a rather dramatic twist, the original finder’s rescue effort became a story the community retold repeatedly—the vendor-side cache had already been cleared, and just as they were about to give up, the file was still open in a local editor, and a single undo operation brought the content back.

    A year later, the version had moved from 0.2.x to 2.1.8x and features had multiplied, but the “no Source Map in build output” constraint in the build pipeline had clearly never hardened into a blocking gate. As of this writing, the latest version in the package registry has been rolled back to the previous revision number, and the emergency-unpublish process has started again.

    2. Scale of the Leak: From a CLI Tool to an Agent Platform

    This leak is on a completely different scale from the one a year ago. Last time, what outsiders saw was a CLI tool with a simple structure; this time, what was exposed is a complete AI agent runtime platform. Several characteristics stand out:

    • Technology stack: a high-performance JavaScript runtime hosts the CLI process, the terminal UI is built on a React-based terminal rendering approach, model calls manually handle streaming responses through the official SDK, and Zod v4 is used for runtime type validation across the entire chain.
    • Code volume: the largest single file is about 875 KB (the main REPL interaction file), tool interface definitions run to as many as 47 fields, and the permission decision pipeline contains more than 10 checkpoints.
    • Modules that did not exist a year ago:
      • coordinator/ (multi-agent coordination): the coordinator itself is a pure orchestration role, exposing only 4 tools (create agent, send message, stop task, subscribe to status). It does no concrete work and only dispatches. Its core decision is “keep reusing vs. spawn a new agent,” based on context overlap.
      • assistant/ (internal codename KAIROS): this codename had never appeared in any public material before. Large amounts of feature flags in the source are evaluated at bundle compile time in the form feature('KAIROS'), and branches that return false are completely removed by dead code elimination, so they should be invisible in external artifacts—yet they still leaked along with the Source Map.
      • voice/ (voice interaction): mentioned in public documentation, but implementation details had always been opaque.
      • plugins/ + skills/ (plugin and skill systems): skill definitions support frontmatter metadata, including the list of allowed tools, reasoning effort, model selection, and conditional path activation.

    3. Technical Analysis: Why a Source Map Creates a Direct Route to Source Code

    3.1 Anatomy of Source Map v3

    A Source Map maps positions in minified or bundled output back to positions in the original source. The format is JSON, and the key fields are:

    • version: always 3;
    • mappings: VLQ-encoded mapping data describing the correspondence between output line/column and source line/column;
    • sources: a list of source file paths;
    • sourcesContent: an optional field that holds the full text of source files;
    • names: a symbol name table.

    The root of the leak is that “optional” field, sourcesContent. It exists for debugging convenience: developer tools can pull the original code directly without going to find the .ts files. Once that field is written and distributed with the artifact, anyone who obtains the file can reconstruct the entire source.

    3.2 Three Typical Leak Paths

    1. Generated by default + retained by default: many bundlers generate xxx.js.map with their default configuration, and if the release pipeline does no filtering, it goes straight into the tarball.
    2. postinstall / runtime write to disk: a package install script writes debug artifacts into node_modules, where a local scan finds them.
    3. Publicly readable object storage: pushing artifacts with sourceMappingURL together with the .map files to a public storage bucket leaves URLs open to enumeration.

    3.3 Relationship to Minification

    It is worth stressing that minification and Source Maps sit at opposite ends of “reversibility.” Minification raises the cost of reading, but a Source Map hands over the reverse-engineering key directly. Minifying while keeping the map is like taping the safe key to the door; the correct approach is no map in the artifact, maps existing only in the internal build system, combined with a symbol reconstruction process.

    4. Deeper Impact of the Exposure

    4.1 The Permission System, Mapped Out

    The source shows a permission decision pipeline with more than 10 checkpoints covering path allowlists, command classification, and network access control. With this logic in hand, an attacker can craft bypass inputs precisely, reducing “finding vulnerabilities” from fuzzing to “reading code and checking it off.”

    4.2 Agent Orchestration Strategy Exposed

    The coordinator’s “continue vs. create new” decision is based on context overlap, and this kind of scheduling strategy is the core of the product’s competitiveness. After the leak, competitors can replicate the orchestration topology, and the community can run targeted prompt injection experiments.

    4.3 Internal Codenames and Experimental Features Surfaced Early

    Feature flags are eliminated at compile time, with the intent that they stay “externally invisible.” But the Source Map resurrected the dead code: half-finished implementations of unreleased features, internal naming, and even commented-out design discussions were all made public, undermining the confidentiality of the product roadmap.

    4.4 Supply Chain Trust Cost

    Rolling back versions and delisting historical packages breaks CI pipelines that depend on the tool; it also triggers a chain of checks on “whether other packages ship maps,” requiring security teams to invest extra effort in a full scan.

    5. Hardening: A Closed Loop from Compile Time to Release Time

    5.1 Compile Time: Explicitly Disable + Tiered Artifacts

    1. # Principle: release artifacts carry no map; debug artifacts are produced separately
    2. # Option 1: explicitly empty it via a build flag
    3. --no-sourcemap
    4. # Option 2: disable it in the build config
    5. # build.config.ts
    6. export default {
    7. sourcemap: false, // or 'hidden', but never true
    8. minify: true,
    9. }

    If a team insists on keeping observability, adopt a dual-artifact strategy:

    • External artifact: sourcemap: false;
    • Internal artifact: sourcemap: 'hidden' + uploaded separately to an internal symbol server, with the URL never written into the published package.

    5.2 Packaging Time: Materialized Manifest Verification

    Add a verification step before npm pack: if any .map or .d.ts source file enters the tarball, fail immediately.

    1. // scripts/verify-tarball.mjs
    2. import { execSync } from 'node:child_process';
    3. const files = execSync('npm pack --dry-run --json', { encoding: 'utf8' });
    4. const list = JSON.parse(files)[0].files.map(f => f.path);
    5. const forbidden = list.filter(p =>
    6. p.endsWith('.map') ||
    7. p.includes('sourcesContent')
    8. );
    9. if (forbidden.length) {
    10. console.error('Debug artifacts detected in the package:', forbidden);
    11. process.exit(1);
    12. }

    5.3 Release Time: Registry-Side Gate

    • Insert verify-tarball before the publish stage in CI, and block on failure;
    • Run a one-time cleanup script over historical versions to confirm no residual .map files;
    • Disable directory listing on the object storage side to prevent URL guessing.

    5.4 Runtime: Post-Install Scanning

    In postinstall or during enterprise internal image builds, run a find . -name "*.map" scan over node_modules and alert on any hit. This line of defense also covers the case of a poisoned upstream package.

    5.5 Organizational Side: Turn the Rule into an Iron Law

    1. # .github/workflows/release.yml (illustrative)
    2. - name: Verify no sourcemap
    3. run: node scripts/verify-tarball.mjs
    4. - name: Publish
    5. run: npm publish

    Also write “no Source Map in release artifacts” into the code review checklist and bake it into build templates, so new services do not step on the same landmine when they go live.

    6. General Practices for Cloud Pipelines

    If builds and releases run in the cloud, you can combine the following general capabilities into defense in depth:

    1. Container platform: separate build images from release images, use multi-stage builds for the release image, and ensure debug artifacts never enter the final layer.
    2. Object storage: enable versioning and access logging on the artifact repository, keep .map files only in an internal-network bucket, and set a lifecycle policy.
    3. Message queue: notify a security scanning service asynchronously on release events, forming a “release—scan—alert” loop.
    4. Logging service + monitoring alerts: set real-time alert rules for “tarball contains a .map” and roll back on trigger.

    Taking Baidu AI Cloud as an example, a build pipeline can use the container image multi-stage build capability to isolate debug artifacts, store symbol files in a private object storage bucket, and use monitoring alerts to run compliance checks on release events. This combination is already well established in the industry.

    7. Conclusion

    The essence of a Source Map leak is not a “sophisticated attack” but “a configuration oversight amplified by automation.” A single late-night find command was enough to expose 33 MB of source, internal codenames, the permission model, and orchestration strategy all at once. For engineering teams, the real lesson is that debugging convenience and production isolation must be institutionalized: explicitly disable it in build flags, enforce tarball manifest verification, block automatically at the release gate, and back it up with runtime scanning—all four lines of defense are indispensable. Turning “never upload a .map” from a verbal agreement into a single assertion in the pipeline is what truly closes this revolving door.