claude-leak-check 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,7 +15,7 @@
15
15
  1. **终端与后台辅助进程不吃系统代理**:如果只开了 Clash 的「系统代理」没开 TUN 虚拟网卡,浏览器走的是海外节点,但终端里的 `claude` 以及桌面端底层的辅助进程会直接走本地宽带出去。
16
16
  2. **第三方监控与反欺诈域名漏配直连**:除了 `claude.ai` 和 `api.anthropic.com`,客户端还会请求 `statsig.anthropic.com`、`featuregates.org`、`prodregistryv2.org`、`o1158394.ingest.us.sentry.io`、`us5.datadoghq.com`、`browser-intake-us5-datadoghq.com`(注意它是横杠不是子域名,`*.datadoghq.com` 通配符匹配不到)、`siftscience.com`、`r.stripe.com`、`api-iam.intercom.io` 等二十多个关联地址。这些第三方域名在国内没有被墙,分流规则漏掉任何一个,或者被国内白名单误放行,后台就会一边挂着海外会话一边用国内宽带 IP 上报遥测。
17
17
  3. **OAuth 授权登录时的双出口错位**:首次登录或重新授权时,桌面端会拉起系统默认浏览器。如果浏览器里开了代理扩展走节点 A,跳回桌面端走 TUN 节点 B(或直连),同一个登录流程一秒内切了两个 IP。
18
- 4. **`npm` 版 CLI 的防火墙盲区与隐藏二进制**:通过 `npm install -g` 装的 Claude Code 底层进程名叫 `node`,按应用名拦截的防火墙(如 LuLu)没法单独拦它;另外 `~/Library/Application Support/Claude/claude-code/` 以及 VS Code / Cursor 扩展目录里还会各自带一份独立的原生二进制,只拦 `/Applications/Claude.app` 会漏掉它们。
18
+ 4. **旧版 `node` 脚本盲区与多路径隐藏二进制**:早期纯 JS 版或未完成 `postinstall` 原生替换的 CLI 底层驻留进程是 `node`,防火墙没法按签名把它和普通前端进程区分开;而新版(2.1.x)虽已落地原生二进制,但 `~/Library/Application Support/Claude/claude-code/`、npm/pnpm 全局目录与 VS Code / Cursor 扩展目录会各自存一份独立副本,如果防火墙只按 `/Applications/Claude.app/*` 路径拦截而没配签名规则,其他入口照样会漏。
19
19
  5. **代理闪退、休眠唤醒与开机抢跑**:只靠 Clash 内部规则防不住 Clash 自己崩溃退出,也防不住重启电脑时 Claude 比 Clash 早启动两秒。没有系统防火墙兜底的话,断梯子那几秒重连就会直接走物理网卡连上 Sentry / Datadog。
20
20
 
21
21
  ## 检查内容
@@ -79,6 +79,10 @@ npx claude-leak-check --json
79
79
  - **官方域名默认零发包**:对 Anthropic 官方域名默认仅通过系统本地 DNS 解析、内核路由表(`route -n get`)与分流规则做本地核验,不向官方接口发探测请求。
80
80
  - **导出图片强制打码**:点击右上角「导出体检卡」生成的 16:9 / 3:4 PNG 图片在画布层强制对公网 IP(如 `198.51.*.*`)和本地路径(`~/...`)做脱敏处理。
81
81
 
82
+ ## 致谢
83
+
84
+ 感谢 [LINUX DO](https://linux.do) 社区在网络分流与本地安全实践上的技术交流支持。
85
+
82
86
  ## License
83
87
 
84
88
  MIT
package/SKILL.md CHANGED
@@ -52,6 +52,6 @@ npx claude-leak-check
52
52
  - 物理网卡存在可直通外网的国内运营商公网 IPv6(`240e:` / `2408:` / `2409:`)。
53
53
  - 默认浏览器出口与终端出口不一致(OAuth 授权跳回桌面端时产生双 IP 切换)。
54
54
  2. **次要风险与加固建议**:
55
- - 全局 `claude` 若由 `npm` 安装,系统内核看到的进程名为 `node`,LuLu 等按应用拦截的防火墙无法单独锁定它,建议改用官方原生签名二进制。
55
+ - 全局 `claude` 若仍为旧版纯 JS 脚本或未完成原生替换的 `node` 包装器(底层驻留进程为 `node`),应用防火墙无法按 Anthropic 签名单独隔离,建议升级至包含原生 Mach-O 二进制的新版或改用官方独立安装器;若为新版原生二进制,则需确认防火墙已按 `com.anthropic.claude-code` 代码签名锁定。
56
56
  - 若检测到运行中的旧版 `user != root` PF 脚本,提醒其在 macOS 上容易触发内核 socket 锁死锁导致 Wi-Fi 卡死,建议改用 LuLu 等 Network Extension 防火墙。
57
57
  - 若用户决定修改网络或防火墙规则,提醒先退出 Claude Desktop 与所有登录态的 Claude Code 终端再操作。
@@ -6,5 +6,5 @@ export const BRAND = {
6
6
  authorHandle: "@Ajax-1",
7
7
  // 可选:后续可填入防封配置指南长文或社群链接,留空则界面隐藏外链按钮
8
8
  guideUrl: "",
9
- version: "0.1.0",
9
+ version: "0.1.1",
10
10
  };
@@ -469,16 +469,16 @@ export function evaluateAuditScores(input) {
469
469
  pointsDeducted: 10,
470
470
  triggersRedline: false,
471
471
  title: {
472
- zh: `发现 npm / Node.js 脚本版全局 claude (${npmCli.displayPath})`,
473
- en: `Detected npm / Node.js script-based global 'claude' (${npmCli.displayPath})`,
472
+ zh: `发现基于 Node.js 解释器运行的全局 claude 脚本 (${npmCli.displayPath})`,
473
+ en: `Detected Node.js-interpreted global 'claude' script (${npmCli.displayPath})`,
474
474
  },
475
475
  detail: {
476
- zh: "通过 npm 安装的 Claude Code 在系统内核与防火墙眼里进程名叫 `node` 而非 `claude`!这意味着 LuLu / Little Snitch 等应用级防火墙根本无法单独拦截它(除非把你电脑上所有前端/Node 开发工具一起断网)。",
477
- en: "npm-installed Claude Code executes as `node`, making it impossible for per-app firewalls like LuLu to block it without blocking all Node.js development on your machine.",
476
+ zh: "该入口实际驻留进程为 `node`(常见于旧版纯 JS 包或未完成原生二进制替换的 fallback 脚本),LuLu / Little Snitch 等防火墙无法通过 Anthropic 签名将其与普通前端 Node 进程区分开。",
477
+ en: "This entrypoint executes inside the generic `node` runtime rather than Anthropic's signed native binary, preventing signature-based firewall isolation.",
478
478
  },
479
479
  remediation: {
480
- zh: "建议卸载全局 npm 版 (`npm uninstall -g @anthropic-ai/claude-code`),改用 Anthropic 官方带独立 Apple 代码签名的原生二进制安装方式。",
481
- en: "Uninstall the global npm package and switch to Anthropic's official native signed binary installer.",
480
+ zh: "建议升级至包含原生 Mach-O 二进制的新版 `@anthropic-ai/claude-code`(确保未开启 `--ignore-scripts` / `--omit=optional`),或改用官方独立安装器。",
481
+ en: "Upgrade to a modern native-binary release (without `--ignore-scripts` / `--omit=optional`) or use Anthropic's standalone installer.",
482
482
  },
483
483
  });
484
484
  }
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export { runFullAudit, stripLocalToggleRawFields, type RunAuditConfig } from "./
4
4
  export { maskIp, sanitizePath, scrubFreeText, parseClashYamlMetadataSafely, } from "./core/privacy.js";
5
5
  export { inspectClaudeSettingsAndProxyEnv, type SettingsAndProxyEnvInput, type SettingsAndProxyEnvResult, } from "./core/settings-env-inspector.js";
6
6
  export { evaluateAuditScores } from "./core/scorer.js";
7
- export { classifyAsnOrg, extractListeningLoopbackPortsMac } from "./platforms/darwin.js";
7
+ export { classifyAsnOrg, extractListeningLoopbackPortsMac, inspectCliBinaryKind, type CliBinaryInspection, } from "./platforms/darwin.js";
8
8
  export { parseAppleXmlPlist, unarchiveNsKeyedPlist, parseLuluRules, parseLuluRulesJson, hasMacosPfDeadlockPattern, extractLaunchDaemonLabelAndScripts, isLaunchDaemonActive, } from "./platforms/lulu-parser.js";
9
9
  export { startLocalReportServer, type LocalServerHandle } from "./server/local-server.js";
10
10
  export { renderReportHtml } from "./ui/render-html.js";
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ export { runFullAudit, stripLocalToggleRawFields } from "./core/engine.js";
4
4
  export { maskIp, sanitizePath, scrubFreeText, parseClashYamlMetadataSafely, } from "./core/privacy.js";
5
5
  export { inspectClaudeSettingsAndProxyEnv, } from "./core/settings-env-inspector.js";
6
6
  export { evaluateAuditScores } from "./core/scorer.js";
7
- export { classifyAsnOrg, extractListeningLoopbackPortsMac } from "./platforms/darwin.js";
7
+ export { classifyAsnOrg, extractListeningLoopbackPortsMac, inspectCliBinaryKind, } from "./platforms/darwin.js";
8
8
  export { parseAppleXmlPlist, unarchiveNsKeyedPlist, parseLuluRules, parseLuluRulesJson, hasMacosPfDeadlockPattern, extractLaunchDaemonLabelAndScripts, isLaunchDaemonActive, } from "./platforms/lulu-parser.js";
9
9
  export { startLocalReportServer } from "./server/local-server.js";
10
10
  export { renderReportHtml } from "./ui/render-html.js";
@@ -20,3 +20,14 @@ export declare class DarwinPlatformAdapter implements PlatformAdapter {
20
20
  runKillSwitchProbe(): Promise<KillSwitchProbeSnapshot>;
21
21
  }
22
22
  export declare function extractListeningLoopbackPortsMac(netstatOut: string): number[];
23
+ export interface CliBinaryInspection {
24
+ isNodeScript: boolean;
25
+ isMachO: boolean;
26
+ viaShellExecWrapper: boolean;
27
+ resolvedBinaryPath: string;
28
+ }
29
+ /**
30
+ * 追踪软链接与包管理器(pnpm / yarn / fnm)生成的 POSIX Shell `exec` 启动脚本,
31
+ * 准确区分「最终直接 exec 原生 Mach-O 签名二进制(新版 2.1.x npm/pnpm 分发包)」与「真正驻留 node 解释器的 JS 脚本」
32
+ */
33
+ export declare function inspectCliBinaryKind(filePath: string, depth?: number): CliBinaryInspection;
@@ -1,8 +1,8 @@
1
1
  import { execFile } from "node:child_process";
2
2
  import { lookup } from "node:dns/promises";
3
- import { closeSync, existsSync, openSync, readdirSync, readFileSync, readlinkSync, readSync, statSync, } from "node:fs";
3
+ import { closeSync, existsSync, openSync, readdirSync, readFileSync, readlinkSync, realpathSync, readSync, statSync, } from "node:fs";
4
4
  import { homedir, networkInterfaces } from "node:os";
5
- import { basename, dirname, join } from "node:path";
5
+ import { basename, dirname, join, resolve } from "node:path";
6
6
  import { promisify } from "node:util";
7
7
  import { REGION_NAMES, RESTRICTED_REGIONS } from "../core/domains.js";
8
8
  import { hashIpForComparison, isFakeIpv4, isGlobalUnicastIpv6, isMainlandCarrierIpv6, isPrivateOrLoopbackIpv4, maskIp, parseClashYamlMetadataSafely, sanitizePath, } from "../core/privacy.js";
@@ -569,14 +569,19 @@ export class DarwinPlatformAdapter {
569
569
  if (existsSync(extra))
570
570
  globalCandidates.add(extra);
571
571
  }
572
+ const seenResolvedCliTargets = new Set();
572
573
  for (const cliPath of globalCandidates) {
573
574
  if (!existsSync(cliPath))
574
575
  continue;
575
576
  const binType = inspectCliBinaryKind(cliPath);
577
+ const dedupeKey = binType.resolvedBinaryPath || cliPath;
578
+ if (seenResolvedCliTargets.has(dedupeKey))
579
+ continue;
580
+ seenResolvedCliTargets.add(dedupeKey);
576
581
  if (binType.isNodeScript) {
577
582
  binaries.push({
578
583
  id: `global-npm-${cliPath}`,
579
- name: "全局终端 claude (npm / Node.js 脚本版)",
584
+ name: "全局终端 claude (Node.js 脚本运行时)",
580
585
  displayPath: sanitizePath(cliPath),
581
586
  kind: "global-cli-npm-node",
582
587
  exists: true,
@@ -584,18 +589,22 @@ export class DarwinPlatformAdapter {
584
589
  firewallCovered: false,
585
590
  riskLevel: "critical",
586
591
  note: {
587
- zh: "高危盲区:底层联网进程名为 node,LuLu 等按应用名防火墙无法单独拦截(除非把整机 Node 开发环境全断网),强烈建议改用官方原生签名安装包!",
588
- en: "High risk: runs under 'node' process, so per-app firewalls cannot block it without breaking all local Node dev tools. Switch to native signed installer!",
592
+ zh: "底层实际驻留进程为 node(常见于旧版 JS 包或未拉取原生二进制的 fallback 包装器),应用防火墙无法按签名单独隔离,建议升级至包含原生 Mach-O 二进制的新版或使用官方独立安装器。",
593
+ en: "Runs inside the 'node' runtime (legacy JS build or fallback wrapper), preventing per-app firewall isolation without blocking all Node dev tools.",
589
594
  },
590
595
  });
591
596
  }
592
597
  else {
593
- const codesignOut = await runCmd("/usr/bin/codesign", ["-dv", cliPath], 1500);
598
+ const signCheckTarget = binType.resolvedBinaryPath || cliPath;
599
+ const codesignOut = await runCmd("/usr/bin/codesign", ["-dv", signCheckTarget], 1500);
594
600
  const signed = /anthropic|Q6L2SF6YDW/i.test(codesignOut) || binType.isMachO;
601
+ const viaPkgManager = /node_modules|pnpm/i.test(signCheckTarget) || binType.viaShellExecWrapper;
595
602
  const covered = luluActive && luluSummary.coversAnthropicSigningId;
596
603
  binaries.push({
597
604
  id: `global-native-${cliPath}`,
598
- name: "全局终端 claude (官方原生二进制)",
605
+ name: viaPkgManager
606
+ ? "全局终端 claude (npm/pnpm 分发原生二进制)"
607
+ : "全局终端 claude (官方原生二进制)",
599
608
  displayPath: sanitizePath(cliPath),
600
609
  kind: "global-cli-native",
601
610
  exists: true,
@@ -604,10 +613,13 @@ export class DarwinPlatformAdapter {
604
613
  firewallCovered: covered,
605
614
  riskLevel: covered ? "pass" : "warn",
606
615
  note: covered
607
- ? { zh: "官方原生签名二进制,已受防火墙代码签名规则锁定", en: "Native signed Mach-O binary covered by firewall" }
616
+ ? {
617
+ zh: "最终执行文件为带官方签名的原生 Mach-O 二进制,已受防火墙代码签名规则锁定",
618
+ en: "Executes Anthropic-signed native Mach-O binary covered by firewall signing rule",
619
+ }
608
620
  : {
609
- zh: "官方原生二进制(优于 npm 版),建议在防火墙中按签名 com.anthropic.claude-code 锁定",
610
- en: "Native binary (better than npm); add signing ID rule in firewall",
621
+ zh: "最终执行文件为带 Anthropic 签名的原生 Mach-O 二进制(无 node 驻留),可在防火墙中按签名 com.anthropic.claude-code 单独锁定",
622
+ en: "Executes Anthropic-signed native Mach-O binary (no Node runtime); lock via signing ID com.anthropic.claude-code in firewall",
611
623
  },
612
624
  });
613
625
  }
@@ -936,44 +948,123 @@ function extractPortFromProxyEnv(proxyUrl) {
936
948
  return undefined;
937
949
  }
938
950
  }
939
- function inspectCliBinaryKind(filePath) {
951
+ function hasMachOMagic(filePath) {
952
+ try {
953
+ const fd = openSync(filePath, "r");
954
+ const buf = Buffer.alloc(4);
955
+ const bytesRead = readSync(fd, buf, 0, 4, 0);
956
+ closeSync(fd);
957
+ if (bytesRead < 4)
958
+ return false;
959
+ const magic = buf.readUInt32BE(0);
960
+ return (magic === 0xcffaedfe ||
961
+ magic === 0xfeedfacf ||
962
+ magic === 0xcafebabe ||
963
+ magic === 0xbebafeca);
964
+ }
965
+ catch {
966
+ return false;
967
+ }
968
+ }
969
+ /**
970
+ * 追踪软链接与包管理器(pnpm / yarn / fnm)生成的 POSIX Shell `exec` 启动脚本,
971
+ * 准确区分「最终直接 exec 原生 Mach-O 签名二进制(新版 2.1.x npm/pnpm 分发包)」与「真正驻留 node 解释器的 JS 脚本」
972
+ */
973
+ export function inspectCliBinaryKind(filePath, depth = 0) {
974
+ if (depth > 4) {
975
+ return {
976
+ isNodeScript: false,
977
+ isMachO: false,
978
+ viaShellExecWrapper: false,
979
+ resolvedBinaryPath: filePath,
980
+ };
981
+ }
982
+ let realTarget = filePath;
940
983
  try {
941
- let realTarget = filePath;
984
+ realTarget = realpathSync(filePath);
985
+ }
986
+ catch {
942
987
  try {
943
988
  const linked = readlinkSync(filePath);
944
- if (linked.includes("node_modules") || linked.endsWith(".js") || linked.endsWith(".mjs")) {
945
- return { isNodeScript: true, isMachO: false };
946
- }
947
- realTarget = linked.startsWith("/") ? linked : join(filePath, "..", linked);
989
+ realTarget = linked.startsWith("/") ? linked : resolve(dirname(filePath), linked);
948
990
  }
949
991
  catch {
950
- // not a symlink
992
+ // 普通文件非软链
951
993
  }
994
+ }
995
+ try {
996
+ // 1. 先直接读取文件头判断是否为原生 Mach-O 可执行文件(新版 @anthropic-ai/claude-code postinstall 会把原生二进制写入 bin/claude.exe)
997
+ if (hasMachOMagic(realTarget)) {
998
+ return {
999
+ isNodeScript: false,
1000
+ isMachO: true,
1001
+ viaShellExecWrapper: depth > 0,
1002
+ resolvedBinaryPath: realTarget,
1003
+ };
1004
+ }
1005
+ // 2. 非二进制文件:读取前 4KB 检查 Shebang 与 Shell exec 链路
952
1006
  const fd = openSync(realTarget, "r");
953
- const buf = Buffer.alloc(128);
954
- const bytesRead = readSync(fd, buf, 0, 128, 0);
1007
+ const buf = Buffer.alloc(4096);
1008
+ const bytesRead = readSync(fd, buf, 0, 4096, 0);
955
1009
  closeSync(fd);
956
- if (bytesRead >= 4) {
957
- const magic = buf.readUInt32BE(0);
958
- if (magic === 0xcffaedfe ||
959
- magic === 0xfeedfacf ||
960
- magic === 0xcafebabe ||
961
- magic === 0xbebafeca) {
962
- return { isNodeScript: false, isMachO: true };
963
- }
964
- }
965
- const head = buf.subarray(0, bytesRead).toString("utf8");
966
- if (head.startsWith("#!") && /\b(node|bun|deno)\b/i.test(head)) {
967
- return { isNodeScript: true, isMachO: false };
1010
+ const text = buf.subarray(0, bytesRead).toString("utf8");
1011
+ const firstLine = (text.split(/\r?\n/, 1)[0] || "").trim();
1012
+ // 2a. 直接由 node / bun / deno 解释执行的 JS 脚本(如旧版 cli.js 或 cli-wrapper.cjs)
1013
+ if ((firstLine.startsWith("#!") && /\b(node|bun|deno)\b/i.test(firstLine)) ||
1014
+ /\.(c?js|mjs)$/i.test(realTarget)) {
1015
+ return {
1016
+ isNodeScript: true,
1017
+ isMachO: false,
1018
+ viaShellExecWrapper: depth > 0,
1019
+ resolvedBinaryPath: realTarget,
1020
+ };
968
1021
  }
969
- if (realTarget.includes("node_modules")) {
970
- return { isNodeScript: true, isMachO: false };
1022
+ // 2b. pnpm / npm cmd-shim 生成的 POSIX Shell 包装脚本(如 #!/bin/sh ... exec "$basedir/.../bin/claude.exe" "$@")
1023
+ if (firstLine.startsWith("#!") && /\b(sh|bash|zsh|dash)\b/i.test(firstLine)) {
1024
+ const baseDir = dirname(realTarget);
1025
+ const lines = text
1026
+ .split(/\r?\n/)
1027
+ .map((l) => l.trim())
1028
+ .filter((l) => l && !l.startsWith("#"));
1029
+ for (const line of lines) {
1030
+ if (!line.startsWith("exec "))
1031
+ continue;
1032
+ // 若 exec 调用的是 node / bun / deno 解释器,则运行时确实驻留 node 进程
1033
+ if (/^exec\s+(?:["']?[^"'\s]*\/)?(?:node|bun|deno)(?:\.exe)?["']?\s/i.test(line) ||
1034
+ /\.(c?js|mjs)["']?(?:\s|$)/i.test(line)) {
1035
+ return {
1036
+ isNodeScript: true,
1037
+ isMachO: false,
1038
+ viaShellExecWrapper: true,
1039
+ resolvedBinaryPath: realTarget,
1040
+ };
1041
+ }
1042
+ // 提取 exec 指向的目标可执行路径(替换 $basedir / ${basedir})
1043
+ const quotedTarget = /^exec\s+"([^"]+)"/.exec(line) || /^exec\s+'([^']+)'/.exec(line);
1044
+ const bareTarget = !quotedTarget ? /^exec\s+(\S+)/.exec(line) : null;
1045
+ const rawExecExpr = quotedTarget?.[1] || bareTarget?.[1];
1046
+ if (rawExecExpr) {
1047
+ const expanded = rawExecExpr
1048
+ .replace(/\$\{?basedir\}?/g, baseDir)
1049
+ .replace(/\$\(dirname\s+[^)]+\)/g, baseDir);
1050
+ const candidatePath = expanded.startsWith("/") ? expanded : resolve(baseDir, expanded);
1051
+ if (existsSync(candidatePath) && candidatePath !== realTarget) {
1052
+ const inner = inspectCliBinaryKind(candidatePath, depth + 1);
1053
+ return { ...inner, viaShellExecWrapper: true };
1054
+ }
1055
+ }
1056
+ }
971
1057
  }
972
1058
  }
973
1059
  catch {
974
1060
  // ignore
975
1061
  }
976
- return { isNodeScript: false, isMachO: false };
1062
+ return {
1063
+ isNodeScript: false,
1064
+ isMachO: false,
1065
+ viaShellExecWrapper: depth > 0,
1066
+ resolvedBinaryPath: realTarget,
1067
+ };
977
1068
  }
978
1069
  async function detectDefaultBrowserMac(home) {
979
1070
  const lsPlist = join(home, "Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-leak-check",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Local read-only IP leak, split-routing, and firewall diagnostic tool for Claude Desktop and Claude Code.",
5
5
  "keywords": [
6
6
  "claude",