Source Map Leak Post-Mortem: How a Coding Agent's Full TypeScript Source Ended Up in a Public Release

    This article reviews a source map exposure incident involving a mainstream AI coding tool whose published package included complete source maps, making the original TypeScript source fully recoverable. It explains why source maps with sourcesContent allow direct source reconstruction, traces the discovery path from an abnormal package size jump to automated extraction, assesses what was exposed across architecture, tool registration, commands, and security implementation details, and outlines practical release safeguards such as artifact allowlists, size baselines, pre-release scanning, and secret management.

    1. Incident Overview: A “Non-Attack” Source Exposure

    Security researchers recently discovered that the latest release of a mainstream AI coding tool (referred to here as “the tool”) shipped complete source map files inside its distribution artifact in a package registry. This made it possible to fully reconstruct the original TypeScript source that the frontend could read. The news spread widely within hours, and the community quickly produced automatically generated mirror repositories of the source, which gained thousands of stars and tens of thousands of forks in a short time.

    Notably, this was not an intrusion or an exploit. There was no man-in-the-middle attack, no dependency poisoning, and no privilege escalation. The actual cause was strikingly simple: the release pipeline bundled debug source maps into the public distribution artifact. In other words, the engineering side handed it over itself.

    More awkwardly, this was not the first time a similar issue had occurred. An earlier version of the tool had experienced an almost identical incident, which was fixed by adjusting the build configuration. The version immediately before the affected release produced a “clean” artifact, which suggests that a build configuration change or dependency upgrade most likely introduced a regression. This pattern of “fixed once, then recurring” is very typical in engineering systems that lack automated gates.

    2. Technical Background: Why a Source Map Equals “Source Code Direct Output”

    To understand the severity of this incident, you first need to understand what a source map actually does.

    Code in modern frontend and Node/Bun ecosystems generally goes through minification, transpilation, and bundling before release: TypeScript is compiled into JavaScript, multiple modules are merged into a few large files, variable names are shortened, and whitespace and comments are removed. The benefit is a smaller size and faster loading; the cost is that readability drops to nearly zero and production error stacks lose their meaning.

    Source maps were created to compensate for that cost. A source map is a JSON text whose core consists of two arrays with one-to-one correspondence:

    1. {
    2. "version": 3,
    3. "sources": ["src/tools/read.ts", "src/tools/edit.ts"],
    4. "sourcesContent": ["import { z } from 'zod'\n...", "..."],
    5. "mappings": "AAAA,CAAC..."
    6. }
    • sources records the original file paths, often directly exposing the directory structure and module layout;
    • sourcesContent directly embeds the full text of the original files;
    • mappings uses VLQ encoding to describe the mapping between generated and original positions.

    The key point is that as long as sourcesContent is present, reconstruction requires no decompilation, no de-obfuscation, and no reverse engineering techniques. A few lines of script can read the JSON and write the content back into files by index, producing a complete source tree. This is also why the extraction script in this incident was only about a dozen lines long.

    It is worth emphasizing that source maps themselves have no security problem; they are infrastructure for the development experience. The problem lies only at the distribution boundary, where debug artifacts and delivery artifacts were treated as the same thing.

    3. Leak Path Review: The Size Anomaly from 17MB to 31MB

    The discovery path of this incident was highly engineering-driven and worth learning from for any team:

    1. Size baseline alert: The distribution package size jumped from about 17MB to about 31MB. The extra content was exactly the .map file of about 57MB (uncompressed). Size is the cheapest and most sensitive anomaly signal.
    2. Artifact manifest check: After unpacking, listing the file manifest revealed a .map file with the same name as the main artifact.
    3. Content sampling: Opening the JSON confirmed that sourcesContent was non-empty and contained readable source code.
    4. Automated reconstruction: A script traversed sources and sourcesContent and wrote the files to disk in batches.

    On this chain, if any step had an automated gate, the incident would never have reached step four. This also explains why “size monitoring + artifact allowlist” should be a default capability of a release system, not an optional one.

    4. Impact Assessment: What Was Exposed and What Was Not

    A relatively accurate judgment in community discussions was that this type of incident usually does not involve model weights or end users’ personal data, and therefore does not pose a direct security risk to ordinary users. The real “loss” lies in the exposure of engineering assets and knowledge assets. Based on the source structure, the exposure surface can be divided into four layers:

    Layer 1: Architecture and technology choices. The directory structure, module boundaries, and dependency list are clear at a glance. Public discussion showed that its tech stack roughly consists of: Bun as the runtime, React combined with a terminal rendering library to build an interactive CLI, a general-purpose parsing library for command-line argument parsing, Zod v4 for runtime validation, a built-in high-performance search tool for file search, MCP protocol and OpenTelemetry telemetry integration, and feature flags controlled by a remote configuration platform. The choice of using React to write a terminal interface is especially instructive—it shows that the “declarative UI + componentization” approach can already cover command-line interaction scenarios.

    Layer 2: Tool registration and permission model. The source contains a tool registration directory with about 39 tool implementations, covering command execution, file read/write, glob and grep search, sub-agent dispatch, web fetching and search, protocol integration, skill loading, and task creation. Each tool’s input validation, permission checks, and error handling logic are clearly readable. For attackers, this is equivalent to obtaining a “capability list + validation weakness map”; for defenders, it is equally an excellent reference.

    Layer 3: Commands and interaction surface. The command directory contains more than fifty slash commands, including diagnostics, diff comparison, cost statistics, and cross-device bridging, as well as several internal or experimental commands. The richer the command surface, the more potential entry points for attack surface and prompt injection.

    Layer 4: “Implementation details” of security mechanisms. This is the most subtle layer. Permission confirmation flows, dangerous command blocking rules, sensitive path protection, and telemetry reporting fields—once these mechanisms are fully read, the cost of bypassing them drops significantly. The value of security design is largely built on the assumption that the implementation is not public, and that assumption was broken in this incident.

    5. Three Things That Actually Matter

    Setting aside the emotion of “the code was seen,” the engineering perspective raises three greater concerns:

    1. Hardcoded sensitive information. The source may contain leftover internal API addresses, test tokens, debug flags, and internal domains. Once public, such information must be considered leaked and rotated immediately.
    2. Bypass paths for security mechanisms. Once permission and confirmation logic is public, attackers can craft inputs specifically to induce the tool to perform unintended operations.
    3. Damaged supply chain trust. The fact that a build configuration could “accidentally” ship debug artifacts shows that the artifact generation process lacks strong constraints; the same gap could also be used to plant more hidden content.

    6. Governance Checklist: How to Avoid Similar Incidents

    The following practices are product-agnostic and apply to any toolchain distributed through package managers:

    • Artifact allowlist: Only explicitly declared files may enter the release package; by default, reject .map files, test snapshots, and internal documentation.
    • Size baseline gate: Set a threshold for artifact size; block the release and alert when it is exceeded.
    • Automated pre-release scanning: Add rules in CI to detect whether sourcesContent is non-empty and whether sensitive keywords (tokens, internal domains, private key headers) are matched.
    • Separate debug and delivery builds: Debug builds with source maps are retained internally only; delivery builds disable this capability. If production observability is needed, use “private source map hosting + authenticated on-demand fetching”.
    • Artifact integrity and signature verification: Release artifacts include signatures and hash manifests, verified on the consumer side to prevent secondary replacement.
    • Secret management: Treat any credential that enters the codebase as public, route it through a secret management service, and establish a rotation mechanism.
    • Regression testing: Write “the artifact must not contain source maps” as an assertion in the pipeline to avoid “fixed once, then recurring”.

    A sample gate assertion can be very short:

    1. # Pre-release gate example
    2. if unzip -l dist.tar.gz | grep -q '\.map$'; then
    3. echo "block: source map found in release artifact"; exit 1
    4. fi
    5. SIZE=$(stat -c%s dist.tar.gz)
    6. [ "$SIZE" -lt 20000000 ] || { echo "block: size baseline exceeded"; exit 1; }

    7. Advice for Users: Turn “Auditability” into a Capability

    For enterprise and team users, this type of incident also highlights evaluation dimensions for AI coding tools: beyond generation quality, look at whether the permission model is explainable, whether tool calls have audit logs, whether sensitive operations require secondary confirmation, and whether telemetry data is controllable. Observability capabilities (logging services, monitoring alerts, audit trails) and permission governance are becoming threshold conditions for such tools to enter production environments.

    In related engineering practices at Baidu AI Cloud, the general approach likewise emphasizes the trio of “minimal deliverables + strong pipeline gates + centralized secret hosting”: completely isolate debug information from delivery information, and write security constraints as executable automated assertions rather than leaving them in specification documents.

    8. Conclusion

    This incident was not technically sophisticated, but it was highly representative: a single build configuration oversight allowed hundreds of thousands of lines of source code to be fully reconstructed within hours. It reminds us that security boundaries are often not at “the layer that is attacked” but at “the layer we actively hand over”. Keeping source maps internal, writing size and content gates into the pipeline, and handing credentials to a secret management service—these three simple things are more effective than any sophisticated protection.