Source Map Leak Exposed Client-Side Code: A Technical Post-Mortem
This article presents a technical post-mortem of a source code leak caused by source map files being shipped inside a published CLI package. It explains how source maps reconstruct original source, why Node.js release pipelines are vulnerable, the typical layered architecture of AI coding clients, and a practical checklist for preventing similar leaks.
1. Incident Overview: How a Single .map File Exposed an Entire Client Codebase
A smart coding tool accidentally shipped debugging source map files in its published command-line client because of a packaging misconfiguration. After downloading the package, external researchers parsed the source map to recover the source file list and the storage address of the bundled artifacts. They then obtained roughly 1,900 TypeScript source files and more than 512,000 lines of code. The incident was made public within hours, and the community quickly mirrored the files and mapped out the logic. The publisher then urgently released a new package version that removed the map files, but the copies that had already spread could not be recalled.
The scope needs to be stated clearly: what leaked was the client-side implementation. It did not include large language model weights, training data, server-side code, or user data. Even so, client code is still a high-value asset, because it exposes how prompts are organized, how the tool permission model works, and how context management is implemented.
2. Technical Root Cause: Why Source Maps Are a “Restoration Map”
To reduce bundle size, build tools merge modules, rename identifiers, and strip whitespace, producing minified output that is hard to read. A source map is a JSON mapping table that records how each segment of generated code corresponds to the original file, line, and column. Once a browser or debugger loads it, breakpoints, stack traces, and variable names can all be restored to a source-code view.
{"version": 3,"sources": ["src/engine/QueryEngine.ts", "src/tool/Tool.ts"],"sourcesContent": ["full original source code..."],"mappings": "AAAA,CAAC..."}
The key risk lies in two fields: sources exposes the directory structure, and sourcesContent embeds the full source code directly. In other words, a map file is not an index; it is a snapshot of the source code taken at bundle time.
3. Risk Surface: Why Release Pipelines in the Node.js Ecosystem Are Fragile
- Missing file allowlist. The package manifest did not precisely declare which directories to include, so debugging artifacts outside
distwere uploaded along with the release. - Build and release shared the same configuration. Debug switches enabled in the development environment were not forcibly turned off in the release pipeline.
- Public artifact links. The bundled artifacts were stored in a publicly readable object storage bucket, and the address was hard-coded in the map file, creating a “download once, get everything” situation.
- Lack of review. No automated scan for sensitive information or debug files was performed on the artifacts before release.
4. Architecture Post-Mortem: The Typical Layers of This Kind of Client
- Query engine layer: receives instructions, breaks down tasks, schedules model calls, handles streaming output, and manages caching and multi-step coordination. It is the core of the whole tool.
- Multi-agent collaboration layer: splits complex tasks across multiple roles that run in parallel, then merges the results.
- Memory layer: persists conversation history, file snippets, and task context to support long-term use.
- Editor bridge layer: communicates bidirectionally with mainstream editors, sending back diagnostics and changes, and typically relies on short-lived tokens for authentication.
- Tool layer and command layer: the former defines executable actions and permission boundaries, while the latter defines interaction entry points and argument parsing.
Looking at the distribution of code volume, the engine and tool interface definitions account for the vast majority of the size. This shows that the core complexity of this kind of tool is concentrated in “control of the call loop” and “permission modeling,” rather than in the interface.
5. Takeaways: A Practical Protection Checklist
- Minimize release artifacts: explicitly declare an include list and validate the artifact tree after the build.
- Force debug maps off in the pipeline, and add blocking checks for any leftover map files.
- Add sensitive information scanning to CI: addresses, tokens, internal domain names, and debugging notes in comments.
- Change artifact storage to private reads with short-lived signed access, avoiding direct links to public buckets.
- Never place any server-side credentials on the client; authentication should always go through short-lived token exchange.
- Establish a leak response plan: version rollback, key rotation, coordination to take down mirrors, and impact assessment.
If the build and release pipeline is hosted on general-purpose capabilities such as Baidu AI Cloud object storage, container platforms, log services, and monitoring and alerting, the checks above can be turned into pipeline gates and alert rules, changing “remembering to turn off the switch” into “the system does not allow a flawed release.”
