Skip to content

[Bug] DSH 0.1.5-rc.1:requestRejection 丢失 this 绑定 → /dsh-pocket/* 全部 403(局域网二维码不显示、公网隧道无法启动) #119

Description

@diego7808

环境

项 值
dsh-pocket 2.10.4
DSH 0.1.5-rc.1
@deepseek-ai/cordis 4.0.2
Node v24.19.0
OS Windows 10.0.19045
profile ~/.dsh/profiles/web

症状

  1. 设置 → 手机访问 →「局域网访问」永远停在 代理未就绪…(lanStarting 状态),二维码始终不显示
  2. 「公网访问」点击后约 76 秒报错:transport failure for /dsh-pocket/tunnel.start: HTTP 403
  3. 实测所有插件路由均失败(无 cookie 直接请求,返回 403 而非 401):
GET/POST http://127.0.0.1:3080/dsh-pocket/status        -> 403
GET/POST http://127.0.0.1:3080/dsh-pocket/tunnel.status -> 403
GET/POST http://127.0.0.1:3080/dsh-pocket/tunnel.start  -> 403
GET/POST http://127.0.0.1:3080/dsh-pocket/devices       -> 403
GET/POST http://127.0.0.1:3080/dsh-pocket/settings      -> 403

根因

lib/web-rpc.js 把 DSH 的方法从对象上抽出来后以裸函数调用,丢失了 this 绑定:

// L204
const requestRejection = ctx?.connection?.requestRejection;
// L212
try { rejection = requestRejection(req); } catch { rejection = 403; }   // this === undefined

而 DSH 0.1.5-rc.1 的实现是依赖 this 的:

// @deepseek-ai/dsh-client-connection/lib/index.js
requestRejection(request) {
  if (!isTrustedApiRequest(request, this.trustedHosts)) return 403;   // this.trustedHosts -> TypeError
  return this.browserAuth.isAuthenticated(request) ? void 0 : 401;
}

this 为 undefined 时访问 this.trustedHosts 抛 TypeError → 被 catch 一律转成 403 → 插件全部 RPC 失效 → 前端取不到状态(卡 lanStarting、二维码算不出)→ 隧道启动同样 403。

为什么 0.1.5-alpha.1 时没暴露:该方法的 alpha 版实现不依赖(或以不同方式依赖)this;rc.1 改为读取 this.trustedHosts / this.browserAuth 后才触发。

旁证(同文件同模式):lib/index.js L328 处理 authenticatedUrl 时写法是正确的 —— fn.call(ctx.connection, \http://127.0.0.1:${dshPort}\`)`,即作者已知需要绑定 this,唯独 requestRejection 处漏了。

修复建议

-        try { rejection = requestRejection(req); } catch { rejection = 403; }
+        try { rejection = requestRejection.call(ctx.connection, req); } catch { rejection = 403; }

本地按此修改后 node --check 通过。该改动是恢复方法的正常调用语义,并非绕过鉴权,信任栅栏(Host/Origin + cookie)保持不变。

已排除的可能

  • 非代理/VPN 干扰:HTTP_PROXY / HTTPS_PROXY / ALL_PROXY / NO_PROXY 在 Process / User / Machine 三处均为空;本机无常见代理端口监听;Windows 系统代理为关闭状态
  • 非 cookie 会话失效:若仅未认证,DSH 的 requestRejection 会返回 401;实测得到 403,说明卡在 isTrustedApiRequest 之前就已因异常被改写
  • 非 host/origin 配置问题:同一浏览器会话下,其他非插件路由工作正常

影响面

DSH ≥ 0.1.5-rc.1 的环境下,dsh-pocket 的手机访问功能完全不可用(局域网与公网均无法启用)。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions