Source Map Leak Post-Mortem: How a Debug Artifact Exposed 1,900 TypeScript Files
This article reviews a source map leak in a popular AI coding tool's public npm package, where a 59.8 MB map file exposed roughly 1,900 TypeScript source files and over 512,000 lines of code. It explains why source maps are dangerous only when their publishing boundary is drawn incorrectly, walks through the five layers of build pipeline protection (artifact allowlisting, manifest diff gates, secret scanning, environment isolation, and signing with provenance), and gives a prioritized response sequence for teams that have already leaked source, plus governance advice for adopting AI coding tools.
1. Incident Overview: A Configuration Gap, Not an Attack
On March 31, 2026, a security researcher disclosed on social media that a public npm package for a mainstream AI coding tool shipped a source map file of roughly 59.8 MB. Parsing that file reconstructed about 1,900 TypeScript source files and more than 512,000 lines of code, including internal module names, feature flags, routing tables, and implementation details of unreleased capabilities. A mirror repository of the code gained thousands of followers within half an hour.
The critical point: this had nothing to do with a hacker intrusion. No authentication was bypassed, no memory vulnerability was exploited, and no privilege escalation occurred. All of the data was packaged, signed, and pushed to a public registry by the publisher itself. The incident is a textbook consequence of a release pipeline that performs no allowlist validation on the contents of its final artifact.
From an engineering standpoint, these incidents are frequent because there is no automated gate between “the build succeeded” and “the build is correct”: build scripts care whether the output runs, not what extra content it carries.
2. Root Cause: Why Source Maps Are So Dangerous
A source map is a debug mapping file generated by the compiler during minification or transpilation. It records the correspondence between line and column positions in the transformed code and the original source. It serves browser debugging, production stack trace restoration, and performance profiling. It is observability infrastructure, not a dangerous technology.
The danger comes from drawing its publishing boundary in the wrong place. Debug artifacts should exist only in error monitoring backends and local development environments, yet here they were placed in a public-facing artifact registry. Once a source map ships alongside its minified output, anyone can use generic de-obfuscation logic to reconstruct the directory structure, original variable names, and comments:
// Wrong: debug maps published together with executable output{"files": ["dist/cli.js","dist/cli.js.map" // plaintext source index shipped with the package],"files_explicit": ["dist/cli.js", "dist/cli.js.map"]}
The correct approach is separate storage plus controlled access:
// package.json: the artifact keeps only files required at runtime{"name": "demo-cli","files": ["dist/cli.js", "dist/**/*.LICENSE"],"scripts": {"build": "tsup src/index.ts --sourcemap --minify","prepublishOnly": "node scripts/assert-artifact.mjs"}}
// scripts/assert-artifact.mjs: mandatory gate before publishingimport { execSync } from 'node:child_process';const packed = JSON.parse(execSync('npm pack --dry-run --json').toString())[0];const forbidden = packed.files.map(f => f.path).filter(p => /\.(map|d\.ts|ts|tsx|log|env)$/i.test(p) || p.startsWith('src/'));if (forbidden.length) {console.error('[RELEASE BLOCKED] Sensitive files matched the denylist:', forbidden);process.exit(1);}console.log('[OK] Artifact file manifest passed validation');
Uploading map files to a private error monitoring backend and linking them to outputs by release id and artifact fingerprint preserves full observability without exposing source code.
3. What Is Lost First Is Not Code, but Three Other Things
1. Expanded exposure of private information
Configuration constants, internal service addresses, feature flag key names, A/B experiment identifiers, and canary and allowlist logic all become public along with the source. If the build process lacked environment isolation, test tokens, object storage access strings, and third-party API keys inlined into the output are exposed too. The first action after such an incident should be reverse-scanning the leaked code for credentials by string, not publishing an announcement.
2. Premature exposure of the attack surface
Attackers obtain the complete call graph, parameter validation locations, gaps in exception handling, and local cache structure without any reverse engineering. The cost of attack drops from weeks of reverse engineering to hours of auditing, and attackers can write automation scripts targeting weak validation points directly.
3. Trade secret and compliance risk
Implementations of unreleased capabilities, algorithm details, internal architecture decisions, and roadmap information all lose confidentiality. The leak may also trigger open source license audits (third-party code and license text were packaged together), breach confidentiality clauses in customer contracts, and invite data compliance review.
4. Deep Analysis: Security Weaknesses Inferred from the Leaked Content
Several broadly applicable lessons can be drawn from the publicly reported details:
- Overly long monolithic files: core scheduling logic concentrated in a single file of more than 40,000 lines indicates the module lacks interface isolation and separation of responsibilities, making test coverage and permission boundaries hard to refine and audit granularity extremely coarse.
- Hidden capabilities without flag governance: capabilities with persistent lifecycles, such as long-running background processes, background sessions and memory consolidation, and redaction of commit records, expose both misuse and abuse paths once their implementations become public, unless there is unified feature flagging with a default-off policy.
- Internal codenames and performance metrics leaked alongside code: internal naming and evaluation data left in comments, log strings, and test cases show that information belonging only in internal systems was mixed into the source.
This reduces to one principle: only what belongs in version control is source code; everything else is configuration or a secret and should not appear in any artifact.
5. Five Layers of Protection for the Build Pipeline
Layer 1: Artifact allowlist
Do not maintain a denylist; use an explicit allowlist instead. Only paths declared in the files field of package.json may enter the final artifact, and everything else is rejected by default.
Layer 2: Manifest diff gate
The release job runs npm pack --dry-run or an equivalent after packaging and compares the actual file manifest against the expected one as a set difference. Any discrepancy halts the pipeline immediately.
Layer 3: Secret scanning
Wire credential scanning into the commit, build, and release stages separately, covering high-entropy strings, common token prefixes, and private key headers. A match blocks the pipeline rather than only raising an alert.
Layer 4: Environment isolation
Use short-lived build credentials scoped to “write to the artifact registry only,” forbid the build stage from accessing the production data plane, and inject secrets through controlled mechanisms instead of writing them into artifacts.
Layer 5: Artifact signing and provenance
Generate a software bill of materials and an artifact signature, recording the source commit, build job, and dependency versions, so the affected version range can be determined quickly after an incident and fixes can be rolled out.
Illustrative pipeline fragment:
# Pseudocode: key gates in the release pipelinestages:- build # compile + generate source maps (kept internal to the artifact)- scan # secret scanning + dependency vulnerability scanning, abort on failure- artifact # allowlisted packaging + manifest comparison- upload # upload maps to private error monitoring, never to the public registry- sign # generate SBOM and signature- publish # canary release with one-click rollback preserved
6. If a Leak Has Already Happened: Response and Remediation Order
- Stop the bleeding: unpublish the affected versions from the public registry or publish superseding versions, stating the affected scope and version ranges explicitly in the notes.
- Clear credentials: work through the strings, comments, and test data in the leaked source one by one, and rotate every potentially related key and token, including CI variables and local development configuration.
- Assess exposure: compile a list of unreleased capabilities, judge whether they create abuse risk, and if necessary disable the corresponding capabilities directly via server-side flags.
- Fix the pipeline: add the allowlist and gate, and redirect source map output to private storage.
- Post-mortem and institutionalize: write “artifact content review” into the release standard with a named owner, and add legal and compliance assessment for anything involving trade secrets.
- Be transparent internally: explain the facts, impact, actions taken, and follow-up improvements to consumers, avoiding information asymmetry that amplifies loss of trust.
7. Governance Advice for Consumers
For enterprises and teams adopting AI coding tools, four measures reduce similar risk:
- Routine artifact review: before adopting a dependency, inspect its install scripts, file manifest, and network behavior, and be wary of unexpectedly large artifacts.
- Least privilege: grant the tool a separate code repository access scope, and forbid it from holding production environment or key management capabilities.
- Auditable output: bring the tool’s call chains and change records into a unified logging service with monitoring and alerting, making anomalous behavior traceable.
- Keep sensitive local data local: for repositories containing core business logic, adopt self-hosted or isolated deployment so sensitive code never leaves the internal network.
Conclusion
This incident was not technically sophisticated, yet it was highly destructive, because it drew the boundary between “debug assets” and “release assets” on the same side. Source maps are good tools, and secret scanning, allowlisted packaging, and artifact signing are all mature practices; what was missing was fixing them as gates that cannot be skipped in the pipeline. For engineering teams, a more important capability than “never having an incident” is: being able to locate the scope, cut off the risk, and restore delivery within hours of any incident. That recoverability is the true measure of engineering maturity.
