AI Coding Tool Source Code Leaked Again via Source Maps

    This article examines how an AI coding tool's source code was leaked for the second time within a year because source map files were included in its release packages. It explains how Source Map v3 files expose complete source code through the sourcesContent field, why closing the source code through dead code elimination does not prevent disclosure, and what was revealed about the tool's agent architecture. It also provides a tiered risk assessment of source code leaks for closed-source software and practical safeguards for build pipelines, debug symbol storage, secrets management, and release gates. The goal is to help engineering teams ensure source maps are debuggable but never publicly accessible.

    Incident Overview: A 60MB Map File Exposed the Complete Source Code Again

    A security researcher recently found a file of about 60MB in the release package of an AI-powered coding tool. The file followed the widely used Source Map specification (version 3), and its sourcesContent field contained the full contents of 4,756 source files. Among them were 1,902 TypeScript and TSX files, totaling approximately 33MB of uncompressed, unobfuscated code. From the tool’s permission system to subtask orchestration, and to feature branches with internal codenames, everything was exposed. Within hours, the code hosting platform for the project received thousands of stars and forks. The tool’s newer version was urgently withdrawn from the package registry, and the official channel rolled back to the previous release. This was almost a complete replay of the same tool’s source code leak one year earlier.

    Notably, this was a closed-source commercial tool, not an open-source project. For open-source projects, the code is already public, and a source map leak typically causes no material loss. For a closed-source tool, however, the release artifacts, internal codenames, and permission-checking details are core assets. Therefore, “whether debug information is distributed with the package” should be considered a release security issue of equal importance to “whether the code is encrypted or obfuscated.”

    Timeline: The Same Pitfall Twice Within One Year

    The incident can be summarized in three phases:

    1. Initial Exposure (About One Year Ago): The tool was released in a research preview form, still in the 0.2 series. Developers found the same type of source map file in the tool’s dependency directory. At that time, what was leaked was a relatively simple command-line tool.
    2. Rapid Response: The official team urgently deleted the source map file and removed all old versions from the package registry. However, the on-site recovery process was quite dramatic. After clearing all caches, the team nearly gave up on retrieving the source code, but it was ultimately recovered because a developer still had the file open in their text editor and performed an undo operation.
    3. Repeat Offense (Recently): Over the following year, the tool evolved from the 0.2 series to version 2.1.88, with its features growing several times over. However, the “prohibit packaging source maps” configuration in the build pipeline was never solidified. The same type of map file entered the release package again, forcing the official team to roll back the version and withdraw the old release once more.

    These two incidents, one before and one after, form a natural control group. They show that the speed of version iteration far outpaces the pace at which security baselines are embedded into release processes. The first response was timely but was not converted into a mechanism to prevent recurrence, ultimately leading to paying twice for the same mistake.

    How the Leak Happened: Why Source Maps Can “Casually” Take Away the Entire Source Code

    3.1 The Role and Key Fields of Source Maps

    A Source Map is a text file generated by a compiler, bundler, or minifier during the build process. Usually in JSON format, it describes the mapping between “the minified output code” and “the original source code before minification.” The most familiar scenario for frontend developers is the browser developer tools using it to map error stacks in minified code back to the original source lines, greatly reducing troubleshooting time. According to the Source Map v3 specification, it includes several key fields:

    • mappings: Uses a Base64-like VLQ encoding to record the line and column mapping between minified code and source files;
    • sources: A list of source file paths involved in the build;
    • sourcesContent (optional): The full content of each source file corresponding one-to-one with sources. It is this field that makes “a map file equivalent to the entire code repository” possible.

    3.2 How the Leak Occurred

    A leak often requires only two steps: enabling source maps during the production build; packaging the map files into the release bundle. Common causes include:

    • The bundler outputs source maps by default for all modes;
    • The configuration file only sets a switch like sourcemap: true without distinguishing between development and production environments;
    • No allowlist is set during packaging and release, or whether the ignore file takes effect is overlooked;
    • The release script treats the entire output directory as the deliverable.

    A sample directory is as follows:

    1. my-cli/ # Tool root directory
    2. ├── package.json # Release manifest, contains the files field
    3. ├── dist/
    4. │ ├── cli.js # Minified entry file
    5. │ └── cli.js.map # Source map (accidentally packaged)
    6. └── src/ # Source directory (usually not packaged)

    The sourcesContent in the map file looks roughly like this, with each element being the complete text of the corresponding source file:

    1. {
    2. "version": 3,
    3. "file": "cli.js",
    4. "sources": ["../src/repl/index.ts", "../src/coordinator/index.ts"],
    5. "sourcesContent": [
    6. "/* Interactive loop and input handling... full source code */",
    7. "/* Multi-agent coordination and scheduling... full source code */"
    8. ],
    9. "mappings": "AAAA,……"
    10. }

    3.3 Is It Safe to Just Empty the Inline Content?

    Some may ask: Is it safe to just set sourcesContent to empty? This can greatly reduce the risk but cannot solve the problem once and for all. Because the sources field still exposes the directory structure, internal module naming, and even the internal code repository addresses used for the build. If debug information really needs to be provided externally, at least the following should be done:

    • Use sourceRoot to uniformly rewrite to a neutral path prefix;
    • Remove internal addresses and personnel-related naming;
    • Only upload desensitized versions that correspond one-to-one with the public build.

    What Was Leaked and Its Impact: From a Command-Line Tool to an Agent Platform

    The leaked code this time was no longer the simple command-line tool from years ago, but a complete agent platform. The leaked content can be summarized into the following technical profile:

    • Technical Composition: The runtime chose a high-performance JavaScript runtime that starts quickly and supports directly executing TypeScript. The terminal interface used a declarative component-based rendering solution; when interacting with the large model, streaming responses were handled manually; Schema validation libraries were used for runtime type checking across the board.
    • Code Scale: The largest single file was about 875KB (the main interactive interface file); a single tool interface defined 47 fields; the permission decision pipeline had more than ten checkpoints.
    • Permissions and Collaboration: The large size of the main interactive interface file indicates that responsibilities such as event loop, input parsing, rendering, and approval are highly centralized; the many permission checks suggest a multi-layer verification approach; the numerous fields in tool interfaces indicate that tool calls follow a unified declarative contract.

    On this basis, several modules that did not exist a year ago are particularly noteworthy:

    4.1 Multi-Agent Coordination Module (coordinator)

    The Coordinator plays a pure orchestration role in the architecture, exposing only 4 tools (create agent, send message, stop task, subscribe to events). It does not execute specific tasks but is only responsible for task distribution. Its core decision is “Continue or Spawn”, i.e., whether to reuse an existing agent or create a new one. The basis is context overlap: when the current task highly overlaps with existing context, the existing agent is inclined to continue execution to save context costs; when the overlap is low, a new independent agent is created to avoid context pollution.

    This design reflects the idea of separating the orchestration layer from the execution layer and using tool interfaces as the interaction boundary between agents, which is a model worth learning from when building multi-agent systems. However, making the collaboration logic public also means that scheduling strategies, message formats, and termination conditions are exposed externally.

    4.2 Internal Codename Branches and Compile-Time Feature Flags (assistant)

    The internal codename of this module had never appeared publicly before. The source code extensively uses compile-time feature flags, in the form of:

    1. // Evaluated and inlined by the bundler at build time
    2. if (feature('INTERNAL_CODENAME')) {
    3. // Features enabled only in internal builds
    4. }

    In external builds, the feature flag is evaluated to false by the bundler during compilation, and the corresponding branch is completely removed by Dead Code Elimination (DCE). Therefore, these codes are simply not visible in normal artifacts. The problem is that dead code elimination only affects the compiled output and has nothing to do with the generation of source maps. The source map still records the source files before compilation, so these “erased” codes are leaked intact again. This also shows that implicit confidentiality relying on “not visible in the artifacts” cannot replace explicit access control.

    4.3 Voice Interaction Module (voice)

    Voice interaction had previously only been mentioned in public documents, and its implementation details had been a black box. This time, it fully exposed the way voice sessions are connected and processed.

    4.4 Plugin and Skill System (plugins / skills)

    Skill definitions support frontmatter-style metadata, including:

    • allowed-tools: The set of tools that the skill can use;
    • effort: The reasoning or computational intensity required for execution;
    • model: The recommended model to use;
    • paths: Conditional activation only when matching specific file paths.

    This indicates that its skill model follows a convention-based architecture of “declarative metadata + conditional activation + tool allowlist”: the skill loader reads metadata to complete registration and constraints. This is also consistent with the idea in industry agent specifications of “declaring callable tools with metadata.”

    Risk Classification: What Does Source Code Leak Mean?

    For closed-source software, the risks of source code leaks can be roughly divided into three levels:

    • Directly exploitable risks:
      • Hardcoded keys and tokens;
      • Internal service addresses and test accounts;
      • Flaws in permission judgment logic, such as bypasses caused by improper path normalization, or some tools bypassing approval under specific branches;
      • Debug backdoors or feature flags.
    • Risks that are hard to exploit directly but lower the attack threshold: Route information such as directory structures, internal module naming, internal codenames, and unreleased features.
    • Ecosystem and compliance risks:
      • Public dependency lists make it easy to attract targeted poisoning for specific versions;
      • Open-source license compliance issues are more likely to be scrutinized by third parties;
      • Intellectual property of unpublished designs faces the risk of being plagiarized.

    It needs to be emphasized that a leak itself usually does not equal a vulnerability. However, if there are unpatched flaws in the leaked code, the time window from discovering the leak to exploiting the flaw will be greatly compressed. For individual developers and enterprises using such tools, this means two things: first, they should upgrade to the official fixed version in time; second, they should continuously monitor official security announcements.

    Protection Practices: Making Source Maps “Debuggable but Not Accessible”

    The core principle to prevent source code leaks is only one: Source maps should go into private-side platforms such as error monitoring, not into public release packages. Around this principle, it can be implemented at four levels.

    5.1 Build and Packaging Layer: Default Off, Explicit On

    • Explicitly distinguish build modes, and prohibit generating source maps in production builds. For example, set them separately by mode in the bundler configuration, rather than globally enabling them:
    1. // Sample configuration, syntax varies by bundler
    2. export default defineConfig(({ mode }) => ({
    3. sourcemap: mode === 'development',
    4. }));
    • If the bundler supports it, you can choose options such as “hidden source maps” that do not output source files, embedding the maps into the minified artifacts for error monitoring platforms to extract and parse server-side, without producing independent .map files.

    • When releasing, use a packaging allowlist (such as the files field in package.json) to deliver only necessary files; also ensure that the priority relationship between ignore rules and the allowlist meets expectations. The following sample script traverses the files to be published, and any source map file will cause the build to fail:

    1. // Scan before release, traverse the packaging directory and check item by item
    2. import { readdir } from 'node:fs/promises';
    3. async function assertNoSourceMaps(dir) {
    4. for (const entry of await readdir(dir, { withFileTypes: true })) {
    5. const fullPath = `${dir}/${entry.name}`;
    6. if (entry.isDirectory()) {
    7. await assertNoSourceMaps(fullPath);
    8. } else if (/\.map$/i.test(entry.name)) {
    9. throw new Error(`Source map file detected in release package: ${fullPath}`);
    10. }
    11. }
    12. }
    13. await assertNoSourceMaps('dist');

    5.2 Debug Information Layer: Upload Source Maps to Private Storage, Not Distributed with the Package

    • Upload source maps to isolated private storage after the build, such as a separate directory in object storage or an error monitoring platform.
    • Carry the build version number and commit hash when uploading to ensure precise restoration by version.
    • Combined with permission control and access auditing, only authorized personnel are allowed to read.

    In this way, developers can still see readable error stacks as usual, while outsiders cannot get the source code, satisfying both debugging capabilities and confidentiality needs.

    5.3 Key and Information Layer: No Sensitive Data from the Source

    • Use key management services or inject credentials via environment variables to eliminate hardcoding.
    • Add key scanning during the submission and build stages, rotate immediately when problems are found, and check whether they have been published in historical versions.
    • Use placeholders or neutral naming for internal domain names and internal paths in the source code.

    5.4 Process and Gate Layer: Solidifying Experience into Rules

    • In the CI pipeline, add “release artifact content verification” as a release gate and list a pre-release checklist.
    • Before version release, review to clarify that the build configuration will not be changed.
    • Continuously monitor after artifact release. The reason why the incident was spread on a large scale within hours is related to the indexing speed of public repositories and package repositories. Establishing release artifact scanning and abnormal alerts can detect violating files at the first time.

    Evolution Review: Can the Leaked Design Ideas Be Borrowed?

    From an engineer’s perspective, the leaked content can be read as an architectural reference. At least four ideas can be transferred to your own projects:

    1. Decoupling Orchestration from Execution: The coordination role is only responsible for scheduling “continue or create new”, and specific tasks are handed over to worker agents, facilitating horizontal scaling and permission isolation.
    2. Unified Tool Contract: The tool interface describes inputs, outputs, permissions, and behavioral constraints with complete fields, and the runtime performs unified verification, which is more reliable than scattered judgments in each implementation.
    3. Convention-based Skills/Plugins: Use frontmatter metadata to describe tool allowlists, reasoning intensity, and applicable paths. The loader automatically registers according to metadata, and plugin developers do not need to understand the host’s internal implementation.
    4. Multi-layer Permission Decision: The permission judgment is split into multiple checkpoints, and any layer should stand independently. The idea of “default deny, explicit authorization” can be referenced to avoid relying on the unknown implementation details of a certain layer for security.

    At the same time, we must also learn lessons: avoid the main interactive file expanding to nearly 1MB and split modules according to responsibilities; feature flags should be combined with explicit configuration management and cannot rely on “invisible after compilation.”

    Additional Suggestions for Cloud Scenarios

    This type of leak can also occur in cloud-native environments. Residual debug symbols in container images and map files mixed in build artifacts on platforms such as Function Compute can lead to source code leakage. Whether it is local CI or pipelines hosted on cloud platforms such as Baidu AI Cloud, the following measures can be integrated into general engineering practices:

    • Store build artifacts and debug information separately: Put debug information in private storage, such as an independent and controlled directory in object storage, and release artifacts only contain what is needed for operation;
    • Add artifact content verification in the release process and connect it to log services and monitoring alerts, alerting immediately once a map file is detected;
    • Centrally manage credentials through key management capabilities, and implement least privilege and runtime isolation using deployment forms such as container platforms;
    • Regularly review build scripts to prevent debug configurations from being brought into the production pipeline.

    Conclusion

    The same AI coding tool leaked its source code twice within a year due to source maps. The root cause is not a certain technical difficulty, but that “prohibiting packaging source maps” has never become an iron rule that cannot be bypassed in the build pipeline. For developers, source maps should be treated as production data that needs to be protected, not as a byproduct of the build:

    • Default off;
    • Explicit on;
    • Upload to private storage;
    • Verify before release;
    • Audit throughout.

    This “minimal exposure” practice applies to any closed-source tool. For enterprise users, when evaluating AI agent programming tools, in addition to functions and performance, the maturity of the release security process should also be taken into account. How a tool protects its own code often reflects how it protects the user’s code.