AI Coding CLI Source Code Leak: Timeline and Protection
This article examines a source code leak involving an AI coding CLI tool, reconstructing the timeline of two related incidents within 72 hours: default-public content assets exposed through the vendor's CMS and complete source code recoverable from source map files shipped in the production build. It explains how source maps reconstruct original code, why three layers of protection (build, release, and process) failed simultaneously, and how to build a three-layer verification method, defense-in-depth controls, incident response steps, and a pre-release checklist to keep map files and secrets out of public artifacts.
1. Incident Background: Closed Source Does Not Mean the Source Is Unavailable
An AI coding CLI tool from an AI vendor is one of the more popular products in the AI coding agent space. It is distributed through public package repositories in closed-source form: users receive only compiled, minified, and obfuscated JavaScript files, and the core code is not publicly exposed. Closed-source distribution promises that the code is “incomplete,” not “unobtainable.” Once a source map (referred to below as a map file) is mixed into the release artifact, that promise no longer holds.
Roughly five months later, looking back at this incident, two characteristics stand out:
- Repetition: This was the second leak of the same kind within a little over a year. The first public release exposed source code on the day it shipped due to the same map file issue and was urgently fixed.
- Compounding: A few days before the source code leak, the same vendor experienced another data exposure incident. This shows that leak risk was not an isolated technical mistake, but two break points on the same weak chain.
2. Timeline Recap: A 72-Hour Triple Hit
| Time | Event | Exposure Surface |
|---|---|---|
| February 24, 2025 | On the day of the product’s first public release, source code was exposed due to a map file issue and was urgently fixed | Build artifacts |
| March 26, 2026 | The vendor’s content management system (CMS) had uploaded assets public by default; approximately 3,000 internal assets were publicly accessible | Content asset storage |
| March 31, 2026 | A new version of the product leaked complete source code through a map file, and media outlets followed up | Build artifacts |
| After the incidents | The vendor took down the problematic artifacts and released fixed versions; the incidents entered the review phase | — |
Phase 1 (March 26): Assets public by default. According to media reports, assets uploaded to the vendor’s CMS were public by default, including a draft technical blog post about an unreleased next-generation model and agenda details from an internal executive summit. These materials first came to public attention when they were discovered by financial media reporters and security researchers. The accidental nature of the external discovery does not change the internal cause: if permissions are not proactively restricted, the content is effectively open.
Phase 2 (March 31): Source code leaked via a map file. Users who obtained the tool through the package distribution channel could reconstruct the complete source code using the map file shipped with the release artifact, including the directory structure, original variable names, and comments. Installing the tool was equivalent to obtaining the source code, with the only barrier being a file download. It is worth noting that locating the problem from the outside was not easy, and ordinary users were unlikely to notice it proactively. This is precisely the most dangerous aspect of closed-source distribution: the leak continued in silence, and the exposure duration could not be estimated.
Historical reference: The problem repeated on the first release day. On the day of the product’s first public release, source code was exposed due to the same map file issue. The recurrence of the same type of error after a fix suggests the most likely explanation is not “the fix was incomplete,” but “the fix addressed this specific artifact rather than the process that produces this class of artifacts.” A one-time fix solves an instance problem; only a process-level fix solves a class problem.
The underlying connection between the three stages. The technical forms of the two incidents differ (one occurred in content asset storage, the other in build artifacts), but they are structurally identical:
Internal data was stored in a “default open” form, and external parties only needed to access it through standard paths to obtain content that should not be public.
3. How Source Maps Reconstruct Source Code with One Step
Build tools compress size and improve loading speed by merging multiple modules, shortening variable names, and removing whitespace and comments. The cost is that the artifacts are nearly unreadable, and production error stack traces lose their meaning. A source map is JSON text used to establish a mapping from “artifact location” to “source code location,” originally serving browser developer tools for debugging and online error monitoring platforms for restoring stack traces. A typical map file contains roughly the following fields:
{"version": 3,"file": "cli.min.js","sources": ["../src/core/agent.ts", "../src/commands/init.ts"],"sourcesContent": ["<full original source of src/core/agent.ts>", "<full original source of src/commands/init.ts>"],"names": ["runAgent", "resolveConfig"]}
The key is sourcesContent: many build tools embed the full original source code into this field by default, with the intent of letting debuggers reconstruct offline from the map file without needing to obtain the source separately. As a result, a map file is effectively a bundle of “compressed artifact + original source code.”
There are two common ways for an artifact to reference a map file:
- External file: The artifact retains a
//# sourceMappingURL=cli.min.js.mapcomment at the end; - Inline data: During the build, the map file is Base64-encoded and embedded at the end of the artifact, in the form
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjoz……. In this case, the artifact itself is a single file, and anyone who obtains the artifact can directly decode the full source code.
Neither form changes the same fact: minification and obfuscation change the code’s appearance, not its semantics; variable renaming and string encryption only increase the cost of reading. The map file is the “official answer” and can directly negate these protections. Therefore, once a map file enters a public artifact, closed source exists in name only.
4. Root Cause Analysis: Three Layers of Protection Missing Simultaneously
1. Build layer: Artifact definition is too broad. Two common practices in production builds both bring map files into the release directory:
- Directly enabling full source map output;
- Disabling full output but retaining “mappings only” mode and outputting the .map file to a location that overlaps with the release directory.
Illustrative configuration (field names should follow the actual build tool in use):
// Illustrative build configuration for the release artifactexport default {mode: 'production',// Production builds do not produce source maps; map files needed for production troubleshooting use a separate pipeline (see Section 6)sourcemap: false,// Belt and suspenders: explicitly exclude map filesoutput: { sourcemapExclude: ['**/*.map'] },};
2. Release layer: No artifact allowlist. If packaging does not explicitly declare which files to include, whatever exists in the release directory gets uploaded, and debugging artifacts enter public repositories alongside production artifacts. More critically, past experience shows that the first line of defense (manual inspection and fixes) can fail. This is not an execution problem, but a control point placement problem: if it relies on people remembering, it cannot be correct every time.
3. Process layer: No mandatory gate. The existing pipeline likely has no check that fails when an artifact contains a map file. Without a gate, build configuration regressions, branch merge conflicts, and mistakenly added output paths can all silently bypass manual checks. Combined with the lack of production artifact inspection, problematic versions may remain online and exposed for a long time without being noticed.
Among the three layers, the first two are technical configurations, while the third is fundamental: only by turning “map files must not enter release artifacts” into a rule that machines enforce and that human operation cannot bypass will similar incidents not recur.
5. Detection and Verification: The Three-Layer Confirmation Method
Layer 1: Local scan of build artifacts. Run this after packaging and before release. A hit on any item is treated as a failure:
#!/usr/bin/env bash# Usage: ./verify-artifacts.sh <directory-to-verify>set -euo pipefailtarget="${1:?Specify the directory to verify}"fail=0# 1. No .map files are allowedif find "$target" -type f -name '*.map' | grep -q .; thenecho "[FAIL] .map files found in artifacts"; fail=1fi# 2. No source map reference comments may remain in artifactsif grep -rIl 'sourceMappingURL' "$target" >/dev/null 2>&1; thenecho "[FAIL] sourceMappingURL reference found in artifacts"; fail=1fi# 3. Simple sensitive information screening (API keys, tokens, internal IPs, etc.)patterns='(API[_-]?KEY|SECRET|TOKEN|BEGIN [A-Z ]*PRIVATE KEY|https?://[0-9]{1,3}(\.[0-9]{1,3}){3})'if grep -rIE "$patterns" "$target" >/dev/null 2>&1; thenecho "[FAIL] Possible sensitive information found in artifacts"; fail=1fi[ "$fail" -eq 0 ] && echo "[PASS] Artifact check passed"exit "$fail"
Layer 2: Post-release spot check. Passing locally does not mean safety online; additional packaging and merge compression steps in the release pipeline may still introduce map files. You need to pull the published version from the public repository, run the same script in its package directory, and sample and archive the check results as audit records.
Layer 3: Internal asset inspection. Apply the same “default deny” approach to internal asset systems such as the CMS and object storage: all assets are private by default, and making them public requires explicit declaration with approval records. At the same time, periodically conduct self-checks from the perspective of search engine query syntax and asset discovery services to find content that is “assumed private but actually public” from an external view.
6. Defense in Depth: Keeping Source Code Outside Artifacts
Principle 1: Off by default, on demand. Production builds do not produce any map files by default. When production troubleshooting is genuinely needed, upload the map files to an internal-only error monitoring platform and map them one-to-one with release version numbers. Map files themselves are not the risk; being publicly reachable is.
Principle 2: External and inline each have a bottom line.
- External file bottom line: Released artifacts must never contain both a map file and its reference comment. Leaving only the comment without the file is equivalent to sending the outside world a signpost saying “where the source code is,” which invites targeted probing, so the comment should be removed as well.
- Inline bottom line: Inline map files spread along with the artifact as a whole and are not suitable for any public release scenario; they are only acceptable in controlled internal environments.
Principle 3: Sensitive information never enters source code. Building only changes the form of the code; it does not remove string constants. Hardcoded tokens, internal network addresses, and internal API paths will all leak along with the source code. Sensitive configurations should be retrieved at runtime from a key management service or a controlled configuration center and authorized according to the principle of least privilege.
Principle 4: Release allowlist + pre-release hook. Explicitly declare which files are allowed to be released, and automatically run the verification script before packaging:
{"name": "your-cli","files": ["dist/**", "README.md", "LICENSE"],"scripts": {"prepack": "node scripts/verify-artifacts.js"}}
The prepack hook is automatically triggered before every package, and it can catch changes to the build configuration made after packaging. The script should call the detection logic from Section 5 and exit with a non-zero status code if it fails. Different package managers may use different field names and hook names, but the approach is the same.
Principle 5: Move gates to the front of the pipeline. Any release task targeting a public repository must pass artifact checks before publishing; direct local publishing is prohibited, and all releases must go through the pipeline to avoid bypassing checks. Pipeline illustration:
# Illustrative: mandatory gate for a public release pipelinejobs:build: { steps: [checkout, restore-cache, build] }verify: { needs: build, steps: [run: ./scripts/verify-artifacts.sh ./dist] }publish: { needs: verify, steps: [publish-to-registry] } # Only runs if verify passes
7. Incident Response: Standard Actions After Discovering a Leak
- Stop the bleeding: Immediately withdraw or take down the affected version to block further distribution.
- Clear caches: Submit invalidation requests to the package repository and public CDN. Some public repositories do not allow overwriting a version with the same name and only allow withdrawing the version and publishing a new one; confirm the cache refresh mechanism in advance.
- Credential handling: Thoroughly inspect tokens, keys, and internal network addresses in the source code, treat all of them as leaked, and rotate them immediately.
- Impact assessment: Inventory the leaked directories, modules, and comments, and determine whether any unreleased core logic or internal information was exposed.
- Fix and harden: Turn off production map output and build the allowlist and pipeline gate.
- Review and verify: Revise release standards, add automated checks, and sample-verify that the gate is actually effective in subsequent releases.
In contrast to this incident is the problem on the first release day: an emergency fix was completed, but the problem recurred. This shows that the endpoint of incident response should not be “the version is fixed,” but “the mechanism is effective and has been verified.”
8. Broader Lessons: Configuration Is an Attack Surface
Both incidents point to the anti-pattern of “default open”: assets are public by default, and build artifacts contain debugging information by default. Compared with patching configuration items one by one, a more fundamental line of defense is default deny, meaning all resources are inaccessible by default, and making them accessible requires explicit authorization with audit records. When implementing this principle, you can combine the following general cloud capabilities, most of which provide an access control model of “private by default, access on authorization”:
- Object storage: Store internal assets and build artifacts, private by default;
- Log service: Record access and release audit logs;
- Monitoring and alerting: Alert on abnormal outbound connections and sensitive downloads in a timely manner;
- Key management: Centrally manage tokens and credentials to prevent hardcoding.
In domestic Chinese cloud environments, Baidu AI Cloud’s related products also follow this access control philosophy. However, tools only provide capabilities; whether the defaults are correct still depends on whether users explicitly implement them in the build and release stages.
9. Pre-Release Checklist
- Full source map output is disabled in the production build;
- The release directory explicitly declares an allowlist and does not contain
.mapfiles or any debugging artifacts; - Released artifacts contain no inline map data and no residual reference comments;
- Map files for production troubleshooting are stored on an internal-only error monitoring platform;
- Artifact scanning is integrated into the pipeline and becomes a mandatory gate for releases;
- No hardcoded credentials in source code or artifacts; sensitive configurations are delivered by key management or a configuration center;
- Content assets are private by default, and making them public requires explicit authorization with audit records;
- A post-release sampling review and periodic external self-check mechanism is established.
Conclusion
The essence of the source code leak is not a single build configuration error, but that “closed source” relied on an assumption that any build parameter could easily overturn. The recurrence of the same type of problem within a little over a year shows that the granularity of the fix remained at “the files from this time” rather than “the process that produces this class of files.” Keeping map files outside artifacts, writing the allowlist into the release manifest, and turning checks into a gate on the pipeline that cannot be bypassed is the fundamental way to prevent this type of incident from recurring.
