Source Map Leak in an AI Coding Tool: Build-Chain Root Cause, Architecture, and Security Lessons

    This article examines how a source map accidentally included in an npm release package exposed the full unminified TypeScript source of a terminal-based AI coding assistant. It explains the build-chain failure behind the leak, analyzes the leaked system’s tool, multi-agent, and scheduled-task architecture, and summarizes practical security controls for build artifacts, object storage permissions, dependency governance, and incident response.

    In software development, source code is a core asset. Its security directly affects product competitiveness and user trust. Yet a seemingly minor build-configuration mistake can expose an entire source repository. A terminal-based AI coding assistant recently experienced such an incident: a release package published to a public package registry accidentally contained a source map file, and the paths inside that file pointed directly to a cloud storage bucket holding the complete, unminified TypeScript source. This article reconstructs the incident from a technical perspective, analyzes the architecture behind it, and extracts security practices that other development teams can adopt.

    The Incident: How One .map File Led to a Full Source Leak

    The incident began when the development team published an npm package without strictly cleaning and validating the build output. Build tools such as Webpack and Vite generate source map files (.map) by default to map minified code back to the original source for debugging. Normally, these files should remain in development environments or private deployments and should never be shipped with a release package. In this case, however, the release package contained the source map, and the resource paths recorded in it pointed directly to a source directory hosted on a cloud provider’s object storage service. Anyone with basic information-retrieval skills could follow that path and use a browser or command-line tools to enumerate and download the entire src/ directory.

    A researcher publicly disclosed the finding on social media. A university student then downloaded the source for “security research archiving” and published the organized code on a public code-hosting platform. Within a short time, the repository received more than 10,000 stars and a large number of forks. The incident reinforces a familiar lesson: security vulnerabilities often do not arise from sophisticated technical attacks, but from the most easily overlooked corners of engineering workflows.

    Technical Root Cause: Failure at the Last Mile of the Build Chain

    Why can a source map cause such a serious leak? The answer lies in how source maps work. Modern frontend or Node.js projects are often written in TypeScript or ES6+ and go through compilation, minification, and obfuscation before release to reduce size and improve loading speed. At the same time, build tools generate source map files so that error stacks can be restored in a browser or runtime environment. A source map is essentially a JSON file containing a sources field that lists all original file paths. If those paths are relative, the problem may be manageable. But many teams configure them as absolute URLs for debugging convenience, pointing to internal networks or cloud storage.

    In this incident, the paths in the .map file clearly pointed to the team’s private object storage bucket, and that bucket’s access permission was set to public-read (or at least listable). This meant an attacker could download all source code through HTTP requests without any authentication. More critically, the source was not obfuscated at all, preserving developer comments, module separation, and business logic. In effect, the product’s “design drawings” were made public. From an engineering perspective, the vulnerability resulted from multiple failures stacked together: no release allowlist filtering, no cleanup of debugging files, incorrect cloud storage permissions, and no pre-release security scanning. If any one of these controls had been strictly enforced, the complete leak would not have occurred.

    Source Scale and Architecture: From a “Simple Tool” to a Complex Agent System

    The leaked source shows that the tool was not a simple command-line wrapper but a complete agent system. The codebase contained about 1,900 TypeScript files and more than 510,000 lines of code, compiled in strict mode, with a runtime based on a modern JavaScript engine. Its terminal UI used a declarative component model. The core architecture can be divided into several layers.

    1. Tool System: The Agent’s “Limbs”

    The tool system is the foundation for the agent’s interaction with the external environment. The source contained about 40 independently wrapped tool modules, each defining a strict input schema, permission level, and execution logic. Common examples included a terminal tool for executing system commands, file tools for reading, writing, and editing files, content-search tools based on regular expressions or indexes, and a network tool for fetching web content. These tools were not tightly coupled to the conversation flow. Instead, they were registered with the runtime through a unified interface and dynamically invoked by the agent based on user intent.

    2. Multi-Agent Collaboration: From a Single Agent to a Team

    The most notable design was the tool’s multi-agent collaboration mechanism. The source contained tools for spawning sub-agents, tools for creating and deleting “teams,” and communication tools for passing messages between agents. This means a user could ask a main agent to decompose a task and dynamically spawn multiple sub-agents to work in parallel. Each sub-agent had its own context and tool permissions, and results were aggregated through a messaging mechanism. This design resembles service orchestration in microservices architecture, but it occurs at the inference layer, placing higher demands on context management and state synchronization.

    3. Scheduled Tasks and Asynchronous Triggers

    The source also included tools for creating scheduled tasks, allowing the agent to automatically execute predefined operations at a future time. This enabled the tool not only to respond to real-time requests but also to handle planned work such as periodic data collection, log analysis, or code inspection. Combining scheduled tasks with multi-agent collaboration further expands the application scenarios, but it also increases the complexity of security boundary management, because each scheduled task can become an anchor for persistent attacks.

    Security Risks and Industry Reflection

    This leak is not an isolated case. It reflects common blind spots in today’s software supply chain.

    First, the principle of minimizing build artifacts is often ignored. Many teams rely on default configurations when packaging releases, or focus only on whether the package runs while ignoring which files should not be present. Source maps, test files, configuration files, and .env examples can all be packaged by mistake. The correct approach is to set file allowlists or denylists in the CI/CD pipeline and enforce validation of artifact contents.

    Second, secure defaults are missing for cloud storage permissions. Object storage services often offer public-read permissions for quick sharing, but once enabled, anyone who knows the URL can access the data. Teams should set buckets that host source code to private read/write, provide temporary access through presigned URLs or server-side proxies, and regularly audit bucket permission configurations.

    Third, security scanning and threat intelligence are disconnected. Even if a source map is released by mistake, automated sensitive-information scanning before release, such as detecting .map files and checking for hard-coded keys, could have intercepted the incident. In practice, however, security scanning often focuses only on secrets in code and overlooks metadata leakage outside the trust boundary.

    Security Practices for Developers

    To avoid repeating this mistake, the following measures should be incorporated into standard development workflows:

    • Isolate build configurations: Configure source map strategies separately for development, testing, and production environments. Disable source maps in production, or inline them into a private monitoring system, and never ship them with a release package.
    • Audit artifact contents: Before release, use scripts to list all files in the npm package or binary package and check for sensitive items such as .map, .log, .bak, .env, and test directories.
    • Minimize cloud storage permissions: Set buckets that store source code, build artifacts, or backups to private by default. Use IAM policies to restrict access sources and enable access logging.
    • Govern the dependency supply chain: Scan third-party dependencies for vulnerabilities and watch whether dependency configurations may introduce path leakage, such as source maps bundled in a dependency’s build artifacts.
    • Prepare incident response: If source code leakage is discovered, immediately revoke the affected release version, revoke all potentially affected credentials, rotate core keys, and assess whether additional protection is needed for algorithms or business logic.

    Conclusion: Technical Risk Begins with Process and Human Behavior

    This incident should not be viewed merely as one company’s mistake. It is a warning for the entire industry. Source code security depends not only on encryption algorithms or firewalls but also on process discipline from every developer. A forgotten .map file connected to a public storage bucket was enough to waste hundreds of person-days of effort. As AI-assisted programming tools become more widespread, code generation and automated builds will become more complex. The industry therefore needs an engineering culture of “secure by default”: private by default, least privilege by default, and comprehensive scanning by default. Only then can the foundation of technical innovation remain stable.