dsh-pocket 2.10.4 → 2.10.5

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.
Files changed (2) hide show
  1. package/lib/web-rpc.js +12 -3
  2. package/package.json +1 -1
package/lib/web-rpc.js CHANGED
@@ -201,15 +201,24 @@ async function pocketHttpBridge(req, res, fetchHandler, maxBodyBytes) {
201
201
  function mountPocketWebRoute(ctx, { channel, handler, log }) {
202
202
  const webServer = ctx?.webServer;
203
203
  if (!webServer || typeof webServer.register !== 'function') return null;
204
- const requestRejection = ctx?.connection?.requestRejection;
204
+ // 必须持有 connection 本体并以**方法形式**调用 requestRejection(issue #117):
205
+ // dsh 的 HostConnectionService.requestRejection 是类方法,内部读 this.trustedHosts /
206
+ // this.browserAuth。先把方法抽成裸函数(`const fn = ctx.connection.requestRejection`)
207
+ // 再调用会丢失 this → TypeError → 被下面的 catch 兜底成 403,于是**任何**请求
208
+ // (本机、带会话 cookie 的浏览器、移动端)都被判 forbidden,设置页 status RPC 全挂
209
+ // (用户可见症状:局域网区块一直显示「代理未就绪…」,公网隧道开启报 403)。
210
+ // dsh 自己的 /api 路由也是以方法形式调用的(见 client-connection 的 register());
211
+ // 本仓库 lib/index.js 处理 authenticatedUrl 时同样用 fn.call(ctx.connection, ...) 绑定。
212
+ // 等价写法:requestRejection.call(ctx.connection, req)(issue #117 报告者的建议)。
213
+ const connection = ctx?.connection;
205
214
  const fetchHandler = pocketFetchHandler(channel, handler, log);
206
215
  const route = {
207
216
  kind: 'prefix',
208
217
  path: channel,
209
218
  handler: async (req, res) => {
210
219
  let rejection;
211
- if (typeof requestRejection === 'function') {
212
- try { rejection = requestRejection(req); } catch { rejection = 403; }
220
+ if (typeof connection?.requestRejection === 'function') {
221
+ try { rejection = connection.requestRejection(req); } catch { rejection = 403; }
213
222
  } else if (!isTrustedLoopbackRequest(req)) {
214
223
  rejection = 403;
215
224
  }
package/package.json CHANGED
@@ -80,5 +80,5 @@
80
80
  "access": "public",
81
81
  "registry": "https://registry.npmjs.org/"
82
82
  },
83
- "version": "2.10.4"
83
+ "version": "2.10.5"
84
84
  }