一句话引爆AI圈:
“不是黑客攻破,不是内鬼泄密——就因为一个.map文件,Anthropic把未来三年的AI编程蓝图免费送给了全世界。”


🔥 事件速览:低级失误,顶级灾难

2026年3月31日(就在昨天),AI安全研究员Chaofan Shou在检查npm包时发现:Anthropic最新发布的@anthropic-ai/claude-code v2.1.88中,竟包含一个59.8MB的cli.js.map文件!

这个本该只出现在开发环境的Source Map调试文件,却在生产包里完整嵌入了:

  • 1906个TypeScript源文件
  • 512,000+行未混淆代码
  • 40+核心工具模块 & 50+斜杠命令
  • 8大未发布功能(Kairos助手、Buddy虚拟宠物、Proactive主动模式等)

更讽刺的是——这已是13个月内第二次犯同样错误! 去年2月v0.2.8版本就因相同原因泄露,如今重蹈覆辙。


💥 源码泄露细节:不只是代码,是“AI工程师”的大脑

1️⃣ Source Map 是什么?为什么这么危险?

Source Map 是前端/Node.js 开发中用于将压缩/编译后的代码映射回原始源码的调试文件。正常生产构建应完全剥离它。

但在 cli.js.map 中,Anthropic 错误地启用了 sourcesContent: true 配置,导致所有原始 .ts 文件内容被内联嵌入.map 文件中:

// cli.js.map (节选)
{
  "version": 3,
  "file": "cli.js",
  "sourceRoot": "",
  "sources": [
    "src/index.ts",
    "src/core/agent.ts",
    "src/tools/fileSystem.ts",
    "src/security/sandbox.ts",
    // ... 1900+ files
  ],
  "sourcesContent": [
    "import { createAgent } from './core/agent';\n\nasync function main() { ... }",
    "export class ClaudeCodeAgent { ... }",
    "export class FileSystemTool { async read(path: string) { ... } }",
    "export class Sandbox { constructor(opts: { allowNetwork: boolean }) { ... } }",
    // ... 512,000+ 行原始代码!
  ],
  "names": [...],
  "mappings": "..."
}

只需一行命令,即可还原全部源码:

# 安装 source-map-explorer
npm install -g source-map-explorer

# 解包并提取源码
npm pack @anthropic-ai/claude-code@2.1.88
tar -xzf anthropic-ai-claude-code-2.1.88.tgz
source-map-explorer --html cli.js > claude_code_source.html

2️⃣ 泄露的核心架构(附关键代码片段)

▶ 多智能体协作系统 (src/core/multiAgent.ts)
// 泄露代码显示:Claude Code 使用“主Agent + 工具Agent”分层架构
export class MultiAgentOrchestrator {
  private planner: PlanningAgent;     // 负责任务分解
  private executor: ExecutionAgent;   // 负责调用工具
  private verifier: VerificationAgent; // 负责结果校验

  async executeTask(task: UserTask): Promise<ExecutionResult> {
    const plan = await this.planner.createPlan(task);
    const steps = await this.executor.runSteps(plan.steps);
    return await this.verifier.validate(steps);
  }
}
▶ 安全沙箱设计 (src/security/sandbox.ts)
// 问题:权限控制存在逻辑漏洞!
export class RestrictedSandbox {
  constructor(private allowedPaths: string[]) {}

  async writeFile(path: string, content: string): Promise<void> {
    // BUG: 只检查路径前缀,未处理 "../" 路径穿越!
    if (!this.allowedPaths.some(allowed => path.startsWith(allowed))) {
      throw new SecurityError("Path not allowed");
    }
    // 危险!攻击者可构造 "../../etc/passwd" 绕过检查
    await fs.promises.writeFile(path, content);
  }
}
▶ 未发布功能:Kairos 主动助手模式 (src/features/kairos.ts)
// Kairos 能主动监控项目状态并提供建议
export class KairosAssistant {
  private fileWatcher: chokidar.FSWatcher;
  
  start() {
    this.fileWatcher = chokidar.watch('./src', { ignoreInitial: true });
    this.fileWatcher.on('change', async (path) => {
      if (this.isTestFile(path)) {
        const coverage = await this.analyzeCoverage(path);
        if (coverage < 0.7) {
          // 主动建议:”检测到测试覆盖率不足,是否生成补充用例?“
          this.suggestAction("generate_test_cases", { target: path });
        }
      }
    });
  }
}

🌍 行业地震:国产Agent直接“开天眼”

过去,国产团队需花2-3年摸索Agent工程化路径。现在,GitHub上已出现多个基于泄露代码的开源项目:

  • OpenClaudeCode:100%复刻核心架构,支持VS Code插件
  • MiniAgent:轻量化版本,仅5000行代码实现多工具调用
  • SecureSandbox:修复原版沙箱漏洞的安全增强版

某国内大模型公司CTO私下透露:“我们原计划Q3上线类似产品,现在直接基于泄露代码重构,6周内就能发布。”


⚠️ 安全警报:你的电脑可能已被“后门化”

泄露代码暴露了三个高危漏洞,可能导致RCE(远程代码执行):

漏洞 风险等级 利用方式
路径穿越写文件 🔴 高危 通过/write命令写入任意路径
工具命令注入 🔴 高危 /shell参数中注入; rm -rf /
网络请求伪造 🟠 中危 诱导Agent访问内网敏感接口

临时解决方案

  1. 立即卸载 @anthropic-ai/claude-code <=2.1.88
  2. 升级至 v2.1.89+(Anthropic已在4月1日凌晨紧急修复)
  3. 如必须使用旧版,在沙箱中运行:
    # 使用Firejail限制权限
    firejail --private --net=none npx claude-code
    

💡 血泪教训:给所有开发者的 Checklist

1. 构建配置必须禁用 Source Map

Webpack:

// webpack.config.prod.js
module.exports = {
  mode: 'production',
  devtool: false, // 关键!禁止生成 .map 文件
  optimization: {
    minimize: true,
    minimizer: [new TerserPlugin({ sourceMap: false })] // 再次确认
  }
};

Vite:

// vite.config.ts
export default defineConfig({
  build: {
    sourcemap: false, // 默认为 false,但务必显式声明
    minify: 'terser'
  }
});

Bun:

# Bun 构建命令
bun build ./src/index.ts --minify --no-sourcemap --outfile ./dist/cli.js

2. 发布前自动化扫描

在 CI/CD 中加入检查步骤:

# .github/workflows/publish.yml
- name: Check for sensitive files
  run: |
    npm pack
    tar -tzf *.tgz | grep -E "\.(map|ts|log|env)$" && echo "ERROR: Sensitive files found!" && exit 1 || echo "Clean package"

3. 最小权限原则

任何AI工具执行系统命令必须:

  • 限制工作目录(chroot或容器)
  • 禁用网络访问(除非明确需要)
  • 敏感操作需用户二次确认

🌐 结语:被动开源,还是主动革命?

有人称这是“AI史上最贵的实习生失误”,也有人欢呼“这是送给开发者的圣诞礼物”。无论如何,2026年3月31日注定载入AI史册——它宣告了一个事实:

在AI Agent时代,代码即战略,细节定生死。

而Anthropic,正为自己的傲慢与疏忽付出代价。当护城河被一个配置文件冲垮,或许整个行业该重新思考:真正的壁垒,究竟是代码,还是快速迭代与用户信任?


🔥 转发提醒你的CTO:检查你们的npm包,别让下一个“裸奔”的是你!

Logo

欢迎加入DeepSeek 技术社区。在这里,你可以找到志同道合的朋友,共同探索AI技术的奥秘。

更多推荐