Source Code Leak Postmortem: How Publish Configs Expose AI Coding Tools
A recent source code leak from a closed-source AI coding assistant was caused by exposed source map files in an npm package. This postmortem explains the underlying build configuration issue, details how to verify your build artifacts, and categorizes the three main risks of source leaks: business logic exposure, vulnerability discovery, and supply chain threats. It also provides a pre-publish checklist, a CI integration script, an emergency response plan, and actionable security advice for developers.
Disclaimer
This article is compiled based on public reports and community discussions. As some details remain independently unverified, it avoids citing unconfirmed statistics and focuses solely on the technically explainable aspects of the incident.
Incident Overview
A closed-source AI coding assistant from an AI lab included debug source map files in an npm package release. Source maps are used to map minified or bundled code back to the original source code for debugging purposes. If the sourcesContent field is embedded, the original source code can be directly restored.
The root cause lies in the build configuration. The bundler’s source map option was not turned off, and the publish configuration lacked rules to exclude .map files. Different bundlers have different default behaviors for source maps—some are off by default, others are on. Teams must rely on their actual versions and configurations rather than past experience.
After the exposure, discussions spread rapidly. Numerous mirror repositories emerged in a short time, making it significantly harder to delete the original links. This demonstrates that once source code leaves an internal environment, there is very little room for post-incident remediation.
How to Verify Your Artifacts for Leaks
Perform a check both before and after publishing using the following methods:
- Search for
.mapfiles in the build output directory (e.g.,dist). - Search JS files for
sourceMappingURLcomments, which point to the corresponding map files. - Open the map file and check if the
sourcesContentfield exists and if it contains the original source code. - Use
npm packto generate a tarball and extract it. Inspect the final published content rather than just checking the local build directory.
After the Leak: Risks of Cloned Projects
Following the leak, cloned projects based on the exposed code appeared in the community. These projects require heightened vigilance.
“Clean room” rewrites require implementers to independently complete the implementation based on functional specifications without accessing the original code. Cloned projects based on leaked code do not meet this premise. Even changing the programming language or adjusting the code structure cannot eliminate copyright and licensing risks.
Cloned projects also pose security issues. Maintainer identities are often unclear, code audits are impossible to verify, and subsequent updates may contain malicious logic. For enterprises, the safest approach is to prohibit the introduction of such projects and use Software Bills of Materials (SBOM) and provenance audits to check if teams are already using them.
Three Categories of Source Leak Risks
The impact of a source leak needs to be assessed in layers, rather than generalized.
First category: Business logic exposure. Designs such as system prompts, tool calling sequences, and context management strategies can be referenced or replicated by competitors once exposed. The magnitude of this risk depends on the inherent value of these designs.
Second category: Easier vulnerability discovery. Once source code is public, security researchers can use static analysis tools (like Semgrep or CodeQL) to locate suspicious code more quickly. However, finding suspicious code does not equate to an existing vulnerability; exploitability depends on the specific deployment environment and access conditions. The leak itself does not prove the system has vulnerabilities.
Third category: Supply chain risks (often misunderstood). To pollute an already published software package, an attacker typically needs to steal publish credentials, compromise maintainer accounts, or breach the build pipeline. A source code leak alone does not allow third parties to rewrite already published versions. Automated dependency updates also have prerequisites: a new version is only installed automatically if the version number falls within the semver range and the lockfile policy permits it. Therefore, locking dependency versions and verifying the integrity field are effective measures against such risks.
Pre-Publish Checklist
- Explicitly turn off source maps in the bundler config, or only upload map files to a controlled symbol server.
- Scan artifacts to prevent
.map,.env,.pemfiles, internal paths, andsourcesContentfields from appearing. - Use the
fileswhitelist to restrict published content; do not rely solely on the.npmignoreblacklist. - Grant only publish permissions to the npm token used for publishing, enable two-factor authentication, and prefer short-lived credentials or trusted publishing workflows.
- After publishing, download the tarball in a clean environment and re-verify the final content.
- Commit lockfiles and verify the
integrityfield of dependencies. - Generate a hash manifest for artifacts and sign it for post-incident verification.
Here is a check script that can be integrated into CI to block publishing when sensitive files are detected:
#!/bin/bashset -euo pipefail# The build directory must exist, otherwise the check is meaningless[ -d dist ] || { echo "dist directory does not exist, check aborted"; exit 1; }# Find files that should not appear in the published artifactif find dist -type f \( -name "*.map" -o -name "*.env" -o -name "*.pem" \) | grep . >/dev/null; thenecho "Publish blocked: artifact contains sensitive or debug files"find dist -type f \( -name "*.map" -o -name "*.env" -o -name "*.pem" \)exit 1fi# Check if sourceMappingURL references remain in JS filesif grep -rl "sourceMappingURL" dist --include="*.js" | grep . >/dev/null; thenecho "Publish blocked: sourceMappingURL reference found"exit 1fiecho "Artifact check passed"
Incident Response Plan
Triage. First, determine the sensitivity of the leaked content. If it contains secrets, database connection strings, or user data, handle it at the highest level. If it is only source code, categorize it based on business value and scope of impact.
Immediate Action. Confirm the scope of the leak, rotate all potentially exposed credentials, and assess whether to deprecate the affected versions. npm has time and condition limits on unpublishing versions, so teams should understand these rules in advance.
External Communication. Publish a statement within a short timeframe explaining the confirmed facts, as well as what remains unconfirmed. An information vacuum easily breeds rumors; a clear statement can mitigate this risk.
Legal Action. Copyright notices and DMCA takedown notices should be evaluated and issued by the legal department. Note that takedowns by hosting platforms only handle content on their platforms; copies mirrored elsewhere are difficult to completely remove.
Postmortem. If similar incidents recur, the problem usually lies in the process rather than a single configuration. After the first incident, teams should integrate check steps into the release pipeline rather than just patching the immediate configuration item.
Advice for Developers
- Do not install cloned projects from unknown sources; prioritize obtaining dependencies from official channels.
- Before installing a dependency, review newly added lifecycle scripts like
postinstallin the package to confirm their behavior. - Commit lockfiles to your project and review changes item by item when upgrading dependencies.
Conclusion
Software security relies on continuously executed processes, not one-off patches. Every build, every release, and every dependency update can introduce new attack surfaces. The more teams rely on default configurations, the more they need to proactively check whether these defaults meet their security requirements.
