creditdaddy 1.7.1 → 1.7.2

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.
@@ -77,6 +77,12 @@ export async function getWorkbuddyMasterKey(clientPath) {
77
77
  if (masterKeyInflight) return masterKeyInflight;
78
78
  const exe = clientPath || detectWorkbuddy().clientPath;
79
79
  if (!exe) return null;
80
+ // #52 防线:被污染的缓存值(如 workbuddy-switch 的 exe)绝不能拉起——非 Electron
81
+ // 程序不消费 -e 参数,会弹出自己的 GUI 窗口 2 秒后被 kill(报告者实测复现现象)。
82
+ if (!looksLikeWbElectronClient(exe)) {
83
+ masterKeyFailAt = Date.now();
84
+ return null;
85
+ }
80
86
 
81
87
  const code = [
82
88
  "const b = process._linkedBinding('electron_browser_workbuddy_storage');",
@@ -320,6 +326,28 @@ const CLIENT_CANDIDATES = process.platform === 'win32'
320
326
  let discoveredClientPath = null; // 异步发现到的自定义安装路径(进程内缓存)
321
327
  let discoverPromise = null; // 在途去重
322
328
 
329
+ /** 候选 exe 是否像「真 WorkBuddy/CodeBuddy Electron 客户端」(issue #52 防误判闸):
330
+ * - 文件名排除:同厂工具(workbuddy-switch 等)名字里带产品词但不是客户端;
331
+ * - Electron 二进制校验:真客户端内嵌 electron.exe 图标资源,Rust/原生 GUI 程序没有——
332
+ * 零子进程(读文件字节,不起进程),误判的代价是 getWorkbuddyMasterKey 把
333
+ * 非 Electron exe 当 Electron 拉起来(弹自己的 GUI 窗口 2 秒后被 kill,#52 现象)。 */
334
+ function looksLikeWbElectronClient(exePath) {
335
+ const p = String(exePath || '');
336
+ const base = path.basename(p).replace(/\.exe$/i, '');
337
+ // 文件名黑名单:第三方/衍生工具(不区分大小写,workbuddy-switch / wb-switch-rust 等全拦)
338
+ if (/switch|launcher|uninstall|setup|crashpad|updater|squirrel/i.test(base)) return false;
339
+ // Electron 指纹:官方客户端由 electron-builder 打包,exe 内嵌 'Electron' 的 PE 资源段。
340
+ // 读文件头 2MB 扫 ASCII 'Electron'——Electron exe 必中,Rust/Go/原生 GUI 基本不会误含。
341
+ try {
342
+ const fd = fs.openSync(p, 'r');
343
+ try {
344
+ const buf = Buffer.alloc(2 * 1024 * 1024);
345
+ const bytes = fs.readSync(fd, buf, 0, buf.length, 0);
346
+ return buf.slice(0, bytes).includes('Electron');
347
+ } finally { fs.closeSync(fd); }
348
+ } catch { return false; }
349
+ }
350
+
323
351
  /** 异步预热:注册表 / 进程探测(唯一允许起子进程的地方,且绝不阻塞调用方)。
324
352
  * 契约:**永远返回 Promise**(已发现 / 非 win32 时 resolve 现状)——调用方都挂 .catch,
325
353
  * 返回 null/undefined 会在 NAS 与已预热的 Windows 机器上直接 TypeError(1.7.0 审计发现)。 */
@@ -328,7 +356,10 @@ export function warmWorkbuddyClientPath() {
328
356
  if (discoverPromise) return discoverPromise;
329
357
  discoverPromise = (async () => {
330
358
  try {
331
- // ① 注册表 Uninstall 键:DisplayIcon / InstallLocation 指向真实安装目录
359
+ // ① 注册表 Uninstall 键:DisplayIcon / InstallLocation 指向真实安装目录。
360
+ // /f 模糊搜索会误命中名字含产品词的第三方工具(#52:workbuddy-switch 的
361
+ // DisplayIcon 指 wb-switch-rust.exe,曾被当客户端缓存 → 反复弹窗),
362
+ // 所以命中后必须过 looksLikeWbElectronClient 双闸才入缓存。
332
363
  const out = await new Promise((resolve) => {
333
364
  cp.execFile('reg', ['query', 'HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall', '/s', '/f', 'WorkBuddy', '/d'],
334
365
  { encoding: 'utf8', windowsHide: true, timeout: 4000, maxBuffer: 2 * 1024 * 1024 },
@@ -345,9 +376,9 @@ export function warmWorkbuddyClientPath() {
345
376
  for (const line of hits) {
346
377
  // DisplayIcon 常见值:D:\Apps\WorkBuddy\WorkBuddy.exe / "...\WorkBuddy.exe",0
347
378
  const raw = line.replace(/^DisplayIcon\s+REG_SZ\s+/i, '').trim().replace(/^"(.*)"(?:,\d+)?$/, '$1').replace(/,\d+$/, '');
348
- if (/\.exe$/i.test(raw) && fs.existsSync(raw)) { discoveredClientPath = raw; return; }
379
+ if (/\.exe$/i.test(raw) && fs.existsSync(raw) && looksLikeWbElectronClient(raw)) { discoveredClientPath = raw; return; }
349
380
  }
350
- // ② 运行中的进程路径(客户端已启动但注册表没写 DisplayIcon 的情况)
381
+ // ② 运行中的进程路径(客户端已启动但注册表没写 DisplayIcon 的情况)——同闸
351
382
  const ps = await new Promise((resolve) => {
352
383
  cp.execFile('powershell', ['-NoProfile', '-NonInteractive', '-Command',
353
384
  "Get-Process -Name 'WorkBuddy','WorkBuddyAI','CodeBuddy*' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Path -Unique"],
@@ -356,7 +387,7 @@ export function warmWorkbuddyClientPath() {
356
387
  });
357
388
  for (const line of String(ps).split(/\r?\n/)) {
358
389
  const p = line.trim();
359
- if (/\.exe$/i.test(p) && fs.existsSync(p)) { discoveredClientPath = p; return; }
390
+ if (/\.exe$/i.test(p) && fs.existsSync(p) && looksLikeWbElectronClient(p)) { discoveredClientPath = p; return; }
360
391
  }
361
392
  } catch { /* 探测失败只是保持「未发现」,不影响既有候选路径判定 */ }
362
393
  })().finally(() => { discoverPromise = null; });