Source Map Leak: Post-Mortem of a 510,000-Line Source Code Exposure
An AI coding CLI's latest release accidentally shipped complete source map files to the public npm registry, exposing roughly 1,900 source files and 510,000 lines of code that were mirrored within hours. Because the incident stemmed from a release configuration error rather than an attack, anyone able to download and unpack the package obtained the full implementation for free—and the same defect had recurred a year after being fixed. This article explains why source maps turn published artifacts into a plaintext source delivery channel, why package size anomalies are the earliest and most-overlooked warning signal, what the exposed code revealed across three layers, and how to scope the real risk. It closes with a root-cause analysis, six practical release-pipeline gates (artifact allowlists, size baselines, build separation, secret scanning, source/artifact isolation, and incident response), and checklists for both consumers and teams building similar tools.
1. Incident Recap: A Source Code Leak Caused from the Inside
The latest version of a popular AI coding command-line tool (referred to below as “the CLI”) was found by security researchers to include complete source map files in the artifacts it published to the JavaScript ecosystem’s public package registry. Within hours of the news spreading on social media, a mirrored repository containing the organized, complete source code appeared on code-hosting platforms, quickly accumulating over ten thousand stars and nearly ten thousand forks.
The central finding of this post-mortem is that this was not an external intrusion but a release configuration accident. The attack surface was zero and the attack cost was zero—anyone able to run a download and unpack command could obtain every implementation detail. More troubling still, the same class of defect had already appeared in an early version a year earlier and was fixed at the time. Its recurrence indicates that the problem does not lie in a single person’s mistake but in a release process that lacks mandatory gates.
2. Why a Source Map Becomes a Source Delivery Channel
A source map is a debugging aid produced by compiled frontend toolchains. Once strongly-typed JS, bundling and minification, and code transformation take place, runtime error locations no longer line up with source line numbers. The source map’s job is to maintain a mapping table that lets a debugger translate a column in the minified file back to a specific line and column in the original source.
Its common JSON structure looks like this:
{"version": 3,"sources": ["src/tools/bash.ts", "src/tools/edit-file.ts"],"sourcesContent": ["import ... full original source code ...","import ... full original source code ..."],"mappings": "AAAA,CAAC,OAAO ..."}
Here sources is an array of source file paths, and sourcesContent holds the full source text corresponding to each entry by index. In other words, as long as a .map file exists in the published artifact, there is no need for decompilation, no need for deobfuscation, and no need to reconstruct an AST—the source is already sitting in the JSON in plaintext. The extraction logic can be done in a dozen lines of script:
const fs = require('node:fs');const map = JSON.parse(fs.readFileSync('cli.js.map', 'utf8'));map.sources.forEach((path, i) => {const content = map.sourcesContent[i];if (content == null) return;fs.mkdirSync('recovered/' + path.split('/').slice(0, -1).join('/'), { recursive: true });fs.writeFileSync('recovered/' + path, content);});
There is a point here that is often misunderstood: disabling source maps does not mean disabling debug information. Many bundler configurations still generate maps in production mode; they simply omit the external reference comment for the .map file, while the file itself still ends up in the artifact. What actually determines whether a leak occurs is the “generate or not” setting in the bundler configuration and the “bundle or not” setting in the release process—not the runtime comment.
3. An Abnormal Package Size Is the Earliest and Most-Overlooked Warning Signal
The package size for this version jumped from about 17MB to 31MB, and the newly added map files expanded to 57MB when unpacked. This is a signal that could hardly be missed: for a CLI tool’s published artifact to nearly double in size within a single patch release is itself a serious anomaly.
The problem is that most teams’ release processes only care about “can it be installed, can it run,” with no validation for an artifact size baseline or a file-manifest allowlist. The value of size monitoring is that it catches an entire class of unknown problems—not just map files, but test fixtures bundled in by mistake, debug snapshots, local configuration, cache directories, and even .env files containing credentials. What these problems have in common is “size increasing for no reason.”
4. What Was Visible Once the Source Was Opened
The exposed code contained about 1,900 source files covering the CLI’s complete implementation, which can be grouped into three layers of information.
Layer one: technology choices. The runtime was not a traditional Node environment but a lightweight, high-performance JS runtime; the terminal UI was built on a component-based UI rendering library—the most interesting detail, because it means the cursor in the terminal, interactive selection lists, and streaming output animations are all the result of rendering a component tree rather than hand-assembled ANSI escape sequences. It also included a command-line parsing framework, a runtime type-validation library, a built-in high-performance binary search tool, an SDK for the model context integration protocol, an implementation of the OpenTelemetry standard, and a server-side configuration client used for feature-flag rollouts.
Layer two: tool-layer implementation. Under the core directory there are about 39 tool modules, covering capabilities such as command execution, file reading, file editing, file writing, path matching, content search, sub-agent dispatch, and web fetching and retrieval. Each tool contains three pieces of readable logic: runtime validation of inputs, permission and approval decisions, and execution with error handling. Alongside these are more than 50 slash commands, including hidden capabilities that the public documentation does not fully cover—diagnostics, cost accounting, multi-device bridging, and more.
The typical abstraction of the tool layer can be summarized as:
interface Tool<Input> {name: string;schema: Schema<Input>; // Runtime input validationrequiresApproval(input: Input, ctx: Ctx): boolean; // Permission decisionrun(input: Input, ctx: Ctx): Promise<ToolResult>; // Execution and error handling}
Layer three: policies and internal prompts. Tool description text, system prompts, and the thresholds and exception conditions of approval rules are often exposed along with the source code. This is the part that many teams least want to leak.
5. Risk Assessment: What Leaked Is Security Boundaries, Not User Data
It is important to define the scope of impact objectively: this type of incident does not involve model weights, nor does it involve user data, and ordinary users face no direct account or data risk.
But “no data leak” does not mean “no security impact.” There are three specific points:
- The attack surface shifts from black box to white box. The implementation details of permission checks, command allowlists, and path-escape protections are all now public, so researchers can construct bypass paths offline and then verify them in a real environment. The buffer that defenders previously enjoyed—“implementation opacity”—disappears entirely.
- Hidden capabilities are exposed. Undocumented commands and internal switches become public, and they may include feature branches whose risk controls are not yet complete.
- Supply-chain trust cost. Open source does not equal out of control, and closed source does not equal secure. The real problem is “intended to be closed source but actually public”—this inconsistency will make enterprise buyers reconsider whether the tool’s audit conclusions still hold.
One common misconception needs clarifying: “keeping source code secret” has never been a security control. Security should be guaranteed by input validation, least privilege, sandbox isolation, and auditable logging. Public source code at most improves attack efficiency; it does not create vulnerabilities. But engineering teams have legitimate reasons for not wanting to open their source (intellectual property, iteration cadence, avoiding low-quality false reports), and this is a business and collaboration tradeoff that should not be conflated with a security promise.
6. Root Cause Analysis: Why the Same Problem Recurs
A post-mortem of an isolated incident is easy; preventing recurrence is hard. Recurrence usually points to four gaps at the process level:
- Build configuration has no versioned review. Switches such as whether to emit maps and whether to preserve the source directory structure are scattered across multiple configuration files, and changes to them receive no dedicated review attention.
- The release process has no mandatory gate. Once packaging is done, the artifact is pushed straight to the registry, with no automated “artifact health check” step in between.
- Local validation and production builds are inconsistent. Developers need maps for local debugging, but the production build reuses the same debug configuration; the two paths are not physically separated.
- There is no post-incident regression test. The first fix usually just deleted that map file, without turning “artifacts must not contain source files” into an automated assertion, so the next change to the build configuration reintroduces the problem.
The conclusion is straightforward: when the same problem recurs, that is evidence of a process defect, not evidence of an individual’s mistake.
7. Hardening the Release Pipeline: Six Practical Gates
The following measures are tool-agnostic and apply to the release of any CLI or frontend package in any compiled language ecosystem.
1. Artifact manifest allowlist validation (the most critical)
Before pushing, parse the list of files to be published and abort the pipeline directly on any unexpected file:
// Release pipeline gate (illustrative)const files = listPackageContents(); // List of files to be publishedconst banned = files.filter(p =>p.endsWith('.map') ||p.startsWith('src/') ||/\.test\.[jt]sx?$/.test(p) ||/(^|\/)\.env/.test(p));if (banned.length) {throw new Error('Artifact contains files that must not be published: ' + banned.join(', '));}
2. Size baseline alerts
Maintain an artifact size baseline for each package; fail and require manual confirmation once it exceeds a threshold (for example, patch-version variation greater than 10%). This catches all the unexpected files that the manifest did not anticipate.
3. Separate production builds from debug builds
Generate debug source maps only locally or in an internal artifact repository, and produce production artifacts in an independent build task. The two paths use different configuration files, and reuse through environment variables is prohibited.
4. Artifact scanning: secrets and source files, both checked
Add a general secret-pattern scan to the pipeline (high-entropy strings, private key headers, token prefixes), and also recursively unpack the archive and scan again—many leaked files hide inside nested dependencies.
5. Physical isolation of source and artifact repositories
Ensure that version-control directories, test cases, and internal documentation are not within the packaging scope at the package root, and replace the “exclude list” with an explicit “include list.” The problem with an exclude list is that when a new directory is added, no one remembers to update it.
6. Incident response plan
Once a leak is discovered, the standard actions are: immediately pull the affected version → preserve the scene for forensics → assess the exposed policies and secrets and rotate them → add an automated assertion targeting the failure point in the release process. Deleting the file and publishing another patch version is only stopping the bleeding, not a fix.
8. Two Checklists: One for Users, One for Teams Building Similar Tools
If you are using this kind of AI coding CLI:
- Do not treat the tool’s permission approval as a security boundary; run it in a container or restricted account and mount only the necessary working directories.
- Deny network access, credential reading, and package-manager installation operations by default, and enable them on demand.
- Retain session-level audit logs, especially records of command execution and file writes.
- Watch the change notes before upgrading versions, and be cautious about versions with abnormal size growth.
- Keep undocumented “hidden commands” and feature flags in a default-off posture; undocumented capabilities should not be available by default.
If you are building a similar tool yourself:
- Write “artifacts must not contain source files” as a CI assertion, not as a team convention.
- The design goal for the permission model should be “deny by default + explicit authorization + traceable,” not reliance on implementation opacity.
- As the number of tools grows, build a centralized registry for tool descriptions and permission declarations to avoid rules being scattered.
- Make the auditability of release artifacts part of the delivery standard, with three archived items: file manifest, size baseline, and dependency list.
9. Conclusion
The real lesson of this incident is not “how many lines of code leaked” but that: in an ecosystem where every artifact can be downloaded, unpacked, and compared, any single lapse in build configuration becomes a public disclosure. The reason 510,000 lines across 1,900 files could be fully reconstructed had nothing to do with sophisticated attack techniques; it came down to a release pipeline that lacked gates.
For enterprises and engineering teams, this kind of incident should be treated as a ready-made stress test: if your build artifacts were fully downloaded by someone tomorrow, which policies, which credentials, and which undocumented capabilities would be exposed? Using artifact manifest validation and size baselines to turn that answer into an automated report right now is far cheaper than a post-mortem afterward. Security boundaries should be built on permissions, isolation, and auditing—not on the assumption that “no one will bother to unpack that package.”
