Source Map Leak Exposed an AI Coding Tool's Full Source Code: A Technical Post-Mortem
This article reviews a Source Map leak that exposed the complete source code of an AI coding tool, and explains why build artifacts are an attack surface. It covers how Source Map v3 files reconstruct original code, why the exposed CLI and agent platform design is sensitive, how to grade the risk as a design disclosure, and how to add artifact scanning gates to CI, alongside a security checklist for enterprises evaluating AI coding assistants.
1. What Happened: One Mapping File Exposed the Entire Codebase
Late at night, a security researcher noticed that a release package for an AI coding tool on a public package registry was unusually large, with a single mapping file approaching 60MB. The file used the Source Map v3 format, and its sourcesContent field stored the complete contents of thousands of source files in plaintext. Nearly 2,000 of those files were TypeScript and TSX, and the unobfuscated source amounted to roughly 33MB. Within hours, the incident had collected over a thousand stars and over a thousand forks on a code hosting community. The release package was then urgently rolled back to the previous version, and the old version was removed from the registry.
Notably, this was not the first time a similar issue had occurred. About a year earlier, when the tool was first released as a research preview, developers had already found the same mapping file in the dependency directory. The response at that time was to delete the mapping file and take down all historical versions. The version number had evolved from early iterations all the way to 2.1.x, and the feature set had grown several times over, but the build pipeline’s policy for producing mapping files was never locked down as a mandatory constraint. As a result, the same problem appeared again.
The value of this incident is not in “watching one vendor’s accident,” but in the fact that it pushes a long-overlooked engineering problem into the spotlight: build artifacts are an attack surface. Any team using a bundler, transpiler, or terminal UI framework faces the same risk if its artifacts contain debug mappings.
2. How Source Maps Reconstruct Source Code
A Source Map is side-channel metadata emitted by compilers and bundlers. It maps positions in the compressed, transpiled, and merged output back to positions in the original files. The core fields of v3 include:
version: the format version, currently 3 in mainstream use;file: the corresponding output file name;sources: a list of original file paths;sourcesContent: a snapshot of the original file contents (an optional field, but often written by default by bundlers);names: a symbol name mapping table;mappings: a string of row and column offsets encoded with semicolons and commas.
The risk is almost entirely concentrated in sourcesContent. Once that field is present, an attacker needs no reverse-engineering skill at all: they only need to parse the JSON and pull the contents in sources order to reconstruct the project structure in bulk. Illustrative parsing logic:
// For risk illustration only: read the map file and extract the original sourceconst fs = require('fs');const map = JSON.parse(fs.readFileSync('bundle.js.map', 'utf8'));map.sources.forEach((p, i) => {const code = map.sourcesContent?.[i];if (code) console.log(`===== ${p} =====\n${code}`);});
Three engineering facts need to be emphasized:
- Minification only changes the form of the output, not the amount of information in the mapping file. If the mapping file is present, minification is effectively useless.
- Compile-time constant folding and dead code elimination can make some branches disappear from the output, but as long as the mapping file covers the original files, the eliminated code still leaks along with the source snapshot.
- Private and internal packages carry a higher risk level than public packages if artifacts are not filtered before publishing, because the paths themselves reveal the organizational structure.
3. Why the Leaked Content Is Sensitive: From CLI to Agent Platform
Based on the public description, the exposed content went far beyond a command-line shell and was close to a complete agent runtime platform. It can be abstracted into four layers of sensitive information:
Layer 1: Permission and audit design. The tool’s interfaces have many fields, and the permission decision chain contains more than a dozen checkpoints. Once this information is in hand, an attacker can craft inputs to probe the boundaries of those decisions, while the defender loses the natural barrier of “design details are not public.”
Layer 2: Multi-agent orchestration strategy. There is a coordination module that plays a pure orchestration role and holds only a few tools (create agent, send message, stop task, subscribe to status). Its core decision is “keep reusing an existing agent or start a new one,” based on context overlap. This scheduling strategy is key to system efficiency and security isolation; once leaked, it is easy to replicate or bypass in a targeted way.
Layer 3: Undisclosed capability switches. Internal codenames are controlled by feature flags and evaluated at bundle time. Branches that return false are removed by dead code elimination, so they are invisible in the artifact, but the mapping file makes them fully visible. This shows that “invisible in the artifact” does not mean “the code does not exist.”
Layer 4: Extension ecosystem conventions. The plugin and skill system describes available tools, effort levels, and other attributes through declaration files with metadata. Implementation details of modules such as voice interaction and terminal UI rendering were also exposed. Leaking ecosystem conventions directly affects the trust model of third-party extensions.
4. Risk Grading: Why It Must Be Rated as a Design Leak, Not a Code Leak
Many teams treat source code leaks as an intellectual property issue, but they should pay more attention to security design leaks. Grading by the following dimensions is recommended:
- Permission model and decision chain exposed: High. Directly lowers the attacker’s cost.
- Internal codenames and unreleased capabilities exposed: Medium-high. Affects the roadmap and competitive position.
- Extension mechanism and trust boundaries exposed: Medium-high. Affects ecosystem security.
- Directory structure and naming conventions exposed: Medium. Provides material for speculating about future versions.
- Dependency manifest exposed: Medium. Can be mapped to known vulnerability databases for bulk scanning.
Secondary risks also need attention: an attacker can use the leaked source to build a “same-origin fork” and lure users into installing a counterfeit with a backdoor; they may also launch precise social engineering attacks based on paths and module names.
5. Defenses: Make Mapping File Governance a Pipeline Gate
The core of defense is not “deleting the package after the fact,” but “not producing it beforehand, being able to verify it during the process, and being able to audit it afterward.”
1. Make the artifact policy explicit. Explicitly disable inlining source contents in the build configuration, keep only the necessary line mappings, or output mapping files to a separate private artifact repository, physically isolated from release artifacts.
// Illustrative: a security baseline for build config (field names vary slightly by bundler)module.exports = {productionSourceMap: false, // do not emit maps in production buildsdevtool: false, // disable inline mappings// if you need online troubleshooting, upload to a private artifact repo with access control instead};
2. A pre-release gate. Add artifact scanning to continuous integration: detect whether mapping files are included, whether sourcesContent is present, whether a single file is abnormally large, and whether internal codenames or sensitive path keywords appear. A hit blocks the release.
# Illustrative: pre-release self-check (pseudocode)find dist -name "*.map" -size +1M -print -quit | grep -q . && echo "Large mapping file found, blocking release" && exit 1grep -RIn "sourcesContent" dist && echo "Source snapshot field detected, blocking release" && exit 1
3. Artifact signing and provenance verification. Sign release packages and enforce verification of origin and integrity on the client to reduce the risk of counterfeits and poisoning.
4. Externalize keys and configuration. If the source has already leaked, any hard-coded credential must be considered leaked and rotated immediately; configuration should be injected through environment variables or a key management service.
5. Auditing and drills. Keep traceable records of build artifacts, and regularly rehearse the “assume the source has already leaked” emergency process: impact assessment, credential rotation, dependency vulnerability checks, and external communication messaging.
6. Enterprise Response: A Security Assessment Checklist for AI Coding Tools
For enterprises preparing to introduce AI coding assistants or agent platforms into their R&D workflows, it is recommended to establish fixed assessment items:
- Artifact transparency: whether source maps are off by default, and whether a verifiable build baseline is provided.
- Permission model: whether tool calls follow least privilege, whether there is a human confirmation step, and whether complete audit logs are retained.
- Data flow: whether code snippets are used for training, whether transmission and storage locations are auditable, and whether private or dedicated instance deployment is supported.
- Extension security: whether plugins and skills are signed, whether they declare the permissions they require, and whether they can be revoked.
- Supply chain: whether dependencies are version-locked, whether integrity is verified, and whether a vulnerability response deadline is established.
- Incident response: whether the takedown, rotation, and notification process in the event of a leak is clearly defined.
For implementation, a closed loop can be built on general cloud capabilities: use object storage to hold build artifacts with access policies configured, use a container platform to run isolated build tasks, use log and monitoring services to detect release gate and abnormal download behavior in real time, and use a key management service to centrally manage credentials.
7. Conclusion
This incident is a lesson for every build team: debug information is a convenience during development and a liability in production. Source Maps themselves are not wrong; the mistake is the lack of governance awareness that “artifacts are an attack surface.” Bringing mapping files under a gate, treating permission design as confidential asset management, and making leak response a rehearsable process are the reliable answers to this kind of risk. For consumers, when evaluating an AI coding tool, beyond whether it improves efficiency, they should also look at whether it has a verifiable security engineering baseline.
