dsh-notify-me 1.21.0 → 1.21.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/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  All notable changes to **dsh-notify-me** are documented here.
4
4
 
5
+ ## [1.21.1] — 2026-11-16
6
+
7
+ 宿主 HTTP 路由补齐 DSH 的访问准入:浏览器里打开的网页不能再借着对本机回环的访问直接调用插件的路由。
8
+
9
+ ### 修复
10
+
11
+ - **宿主 HTTP 路由缺少 DSH 的 Host / Origin 准入**:focus、macOS 通知、Windows Toast、页面桥接、host-fallback 健康探针、同源中继这六条 `webServer.register` 路由原来只由插件自己的 `gateRequest` 把守;DSH 对这张路由表之外的路由不做围栏,所以浏览器里打开的网页可以按地址调用它们。现在每条 handler 都先调宿主的 `connection.requestRejection(req)`(DSH 自己的路由同款:Host / Origin 围栏 + 浏览器登录态),401 / 403 原样回(`reason` 为 `unauthenticated` / `untrusted`),放行后再过原有 `gateRequest`;宿主不提供 `connection` 服务(旧版 DSH、纯 Node、离线测试)时退回原逻辑,行为不变。这一层收在 `lib/page-bridge.js` 新增的 `guardRequest()` 里,六条路由共用。
12
+
13
+ ### 测试
14
+
15
+ - `smoke/host-route-test.mjs`:新增 admission 用例——假 `connection` 返回 403 → `untrusted`、返回 401 → `unauthenticated`、放行后仍被插件自己的 `Host` 闸门拒绝,并断言每个请求都先问 `requestRejection`。
16
+ - `smoke/win-toast-test.mjs`:新增 3g 用例——带 deny 头 → 401 `unauthenticated`、正常 `GET` 仍 200、非回环 peer 仍 403 `bad-remote`(admission 之后插件闸门继续生效)。
17
+
5
18
  ## [1.21.0] — 2026-11-16
6
19
 
7
20
  点桌面通知的正文现在真能把 DSH 从最小化和托盘里拉回来;macOS 在 DSH 已经处于前台时点原生通知也会立即切到对应会话。
package/README.en.md CHANGED
@@ -397,6 +397,8 @@ Security-wise the plugin opens exactly one exact route. Requests outside the voc
397
397
 
398
398
  That header is only a "this came from the page" marker, not the defence — a DNS-rebinding page is same-origin with the address it resolved, so it can send any custom header and triggers no preflight. The real gate is three checks: the peer address must be loopback, or exactly the address the listener itself is bound to; `Host` must be a loopback name (`127.0.0.1` / `localhost` / `[::1]`, port optional) or that same bind address, because the shell deletes `host` when forwarding and fetch refills it from the URL it dialled, while a rebound page still has the attacker's domain in `Host`; and an `Origin`, when present, must be same-origin with that `Host`. Any failure answers `403`, with `reason` set to `bad-remote` / `bad-host` / `cross-origin`. A `GET` returns only `{ok, route, enabled, desktop, platform}`, so after installing you can open it in a browser to confirm the route is there. Calls within 400 ms coalesce into one, and a script that has not answered after 8 s is killed and counted as a failure.
399
399
 
400
+ All six host routes (focus, macOS notifications, Windows toasts, the page bridge, the host-fallback health probe and the same-origin relay) now also pass through a DSH admission step: when the host exposes a `connection` service, the handler first calls `connection.requestRejection(req)` — the same call DSH's own routes make, covering the Host / Origin fence and the browser session check. A 401 / 403 is relayed verbatim (`reason` `unauthenticated` / `untrusted`); only then does the plugin's own gate above run. Hosts without that service (older DSH, plain Node, the offline tests) skip it and fall back to the plugin gate, so their behaviour is unchanged. The step lives in `guardRequest()` in `lib/page-bridge.js`.
401
+
400
402
  The cases where it will not raise are the same ones listed under [Known limitations](#known-limitations) (elevated window, another virtual desktop, a foreground repeatedly stolen); they all answer `202` truthfully and the conversation switch still happens. A main window hidden to the tray with `SW_HIDE` used to answer `202` outright; since 1.21.0 it is `ShowWindow(SW_SHOW)`-ed first and then goes through the same activation steps ([#40](https://github.com/chromoany/dsh-notify-me/issues/40)).
401
403
 
402
404
  </details>
@@ -504,7 +506,7 @@ powershell -NoProfile -File lib/focus-window.ps1 -ProcessId 0 # the last line
504
506
  | <a href="https://github.com/RiZhiZhaoYi"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/RiZhiZhaoYi.png" width="40" height="40" alt="@RiZhiZhaoYi"></a> | [#12](https://github.com/chromoany/dsh-notify-me/issues/12): external notification forwarding (Discord / Bark / Gotify / custom webhook) |
505
507
  | <a href="https://github.com/yuexian7"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/yuexian7.png" width="40" height="40" alt="@yuexian7"></a> | [#17](https://github.com/chromoany/dsh-notify-me/issues/17): the ask for Android delivery, which led to the Feishu / ServerChan / WxPusher targets |
506
508
  | <a href="https://github.com/shrekcg"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/shrekcg.png" width="40" height="40" alt="@shrekcg"></a> | [#16](https://github.com/chromoany/dsh-notify-me/pull/16): away detection (`idleMinutes`), reply-done routing (`donePolicy`), auto-dismiss (`autoDismiss`) |
507
- | <a href="https://github.com/Donald-Yip"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/Donald-Yip.png" width="40" height="40" alt="@Donald-Yip"></a> | [#18](https://github.com/chromoany/dsh-notify-me/issues/18): the report that a Windows notification tag over the 64-character cap made the platform silently reject the approval test toast |
509
+ | <a href="https://github.com/Donald-Yip"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/Donald-Yip.png" width="40" height="40" alt="@Donald-Yip"></a> | #18 (the original issue has been deleted): the report that a Windows notification tag over the 64-character cap made the platform silently reject the approval test toast |
508
510
  | <a href="https://github.com/dunxuan"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/dunxuan.png" width="40" height="40" alt="@dunxuan"></a> | [#20](https://github.com/chromoany/dsh-notify-me/issues/20): the report that alerts for the open session showed a placeholder instead of the session title |
509
511
  | <a href="https://github.com/unnamed42"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/unnamed42.png" width="40" height="40" alt="@unnamed42"></a> | [#21](https://github.com/chromoany/dsh-notify-me/issues/21) / [#22](https://github.com/chromoany/dsh-notify-me/pull/22): the Linux `dsh://open` raise-path report and patch, which brought the deep link back on macOS / Linux in 1.14.4 |
510
512
  | <a href="https://github.com/LIEGU0317"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/LIEGU0317.png" width="40" height="40" alt="@LIEGU0317"></a> | [#24](https://github.com/chromoany/dsh-notify-me/issues/24) / [#25](https://github.com/chromoany/dsh-notify-me/pull/25): the host-side fallback push and same-origin relay modules (optional, off by default), with tests and docs; [#29](https://github.com/chromoany/dsh-notify-me/issues/29) / [#30](https://github.com/chromoany/dsh-notify-me/pull/30): the host fallback ignored the "Forward to external targets" switch (the heartbeat and pagehide now carry `external`), landing in 1.19.0 |
@@ -515,6 +517,8 @@ powershell -NoProfile -File lib/focus-window.ps1 -ProcessId 0 # the last line
515
517
  | <a href="https://github.com/Inh-ui"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/Inh-ui.png" width="40" height="40" alt="@Inh-ui"></a> | [#33](https://github.com/chromoany/dsh-notify-me/issues/33): the report that Windows Desktop approval notifications carry no Approve / Reject buttons, with the source-level finding that Electron drops `actions` and Desktop cannot register a Service Worker — fixed in 1.19.0 |
516
518
  | <a href="https://github.com/sakurakugu"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/sakurakugu.png" width="40" height="40" alt="@sakurakugu"></a> | [#34](https://github.com/chromoany/dsh-notify-me/pull/34): the custom JSON body template for the same-origin relay (`relay.bodyTemplate`), with tests and docs — supported since 1.20.0 |
517
519
  | <a href="https://github.com/AlbertDope"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/AlbertDope.png" width="40" height="40" alt="@AlbertDope"></a> | [#36](https://github.com/chromoany/dsh-notify-me/issues/36): the root-cause analysis (WSH decoding the handler in the ANSI code page) and fix verification for the `800A004C` approval-button error under a non-ASCII Windows user name — fixed in 1.20.1 |
520
+ | <a href="https://github.com/TianqiCai"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/TianqiCai.png" width="40" height="40" alt="@TianqiCai"></a> | [#38](https://github.com/chromoany/dsh-notify-me/pull/38): the fix for macOS toast clicks not switching sessions while DSH is already frontmost (1-second polling), with a smoke test — landed in 1.21.0 |
521
+ | <a href="https://github.com/MVennn"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/MVennn.png" width="40" height="40" alt="@MVennn"></a> | [#40](https://github.com/chromoany/dsh-notify-me/issues/40): the report and diagnosis of Windows native approval toasts not raising minimized/tray windows — fixed in 1.21.0 |
518
522
 
519
523
  Attribution policy: external PRs are landed as maintainer commits — the original commit is not reused and no Co-authored-by trailer is added, so GitHub's contributors graph lists the maintainer only and contributors are credited above.
520
524
 
package/README.md CHANGED
@@ -397,6 +397,8 @@ Windows 的激活顺序是实的:已经在前台就什么都不做(最常见
397
397
 
398
398
  那个头只是「这是页面发来的」标记,不是防线——DNS rebinding 的恶意页对目标地址而言是同源的,能带任意自定义头、也不触发预检。真正的闸门是三层:对端地址必须是 loopback,或恰好是监听器自己绑定的那个 IP;`Host` 必须是 loopback 名(`127.0.0.1` / `localhost` / `[::1]`,可带端口)或同一个绑定地址,因为壳转发时 `host` 已被删掉、由 fetch 按它拨号的 URL 重填,而 rebinding 的页面 Host 仍是攻击者域名;带了 `Origin` 就必须和 `Host` 同源。任一条不符回 `403`,`reason` 分别是 `bad-remote` / `bad-host` / `cross-origin`。`GET` 只回 `{ok, route, enabled, desktop, platform}`,装完可以先用浏览器打开确认路由在不在。400 毫秒内的重复调用合并成一次,脚本超过 8 秒没回话就 kill 掉按失败处理。
399
399
 
400
+ 这六条宿主路由(focus、macOS 通知、Windows Toast、页面桥接、host-fallback 健康探针、同源中继)现在还共用一层 DSH 准入:宿主若提供 `connection` 服务,handler 会先调 `connection.requestRejection(req)`——DSH 自己的路由也走这里,包含 Host / Origin 围栏和浏览器登录态校验;它返回 401 / 403 就原样转发(`reason` 为 `unauthenticated` / `untrusted`),通过后才轮到上面这套插件自己的闸门。宿主没有这个服务(旧版 DSH、纯 Node、离线测试)时跳过前者、退回插件闸门,行为与之前相同。这一层收在 `lib/page-bridge.js` 的 `guardRequest()` 里。
401
+
400
402
  抬不起来的几种场合与[已知限制](#已知限制)里列的一致(提权窗口、另一虚拟桌面、前台被反复抢走),一律如实回 `202`、对话照常切。`SW_HIDE` 到托盘的隐藏主窗原来直接回 `202`,1.21.0 起先 `SW_SHOW` 再走同一套激活步骤([#40](https://github.com/chromoany/dsh-notify-me/issues/40))。
401
403
 
402
404
  </details>
@@ -504,7 +506,7 @@ powershell -NoProfile -File lib/focus-window.ps1 -ProcessId 0 # 末行应是 F
504
506
  | <a href="https://github.com/RiZhiZhaoYi"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/RiZhiZhaoYi.png" width="40" height="40" alt="@RiZhiZhaoYi"></a> | [#12](https://github.com/chromoany/dsh-notify-me/issues/12):外部通知转发(Discord / Bark / Gotify / 自定义 Webhook) |
505
507
  | <a href="https://github.com/yuexian7"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/yuexian7.png" width="40" height="40" alt="@yuexian7"></a> | [#17](https://github.com/chromoany/dsh-notify-me/issues/17):安卓端收消息的诉求,促成飞书 / Server酱 / WxPusher 三种目标 |
506
508
  | <a href="https://github.com/shrekcg"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/shrekcg.png" width="40" height="40" alt="@shrekcg"></a> | [#16](https://github.com/chromoany/dsh-notify-me/pull/16):离开判定 `idleMinutes`、「回复完成」判定 `donePolicy`、自动消失 `autoDismiss` |
507
- | <a href="https://github.com/Donald-Yip"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/Donald-Yip.png" width="40" height="40" alt="@Donald-Yip"></a> | [#18](https://github.com/chromoany/dsh-notify-me/issues/18):Windows 通知 tag 超过 64 字符上限、审批测试通知被平台静默拒收的报告 |
509
+ | <a href="https://github.com/Donald-Yip"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/Donald-Yip.png" width="40" height="40" alt="@Donald-Yip"></a> | #18(原 issue 已删除):Windows 通知 tag 超过 64 字符上限、审批测试通知被平台静默拒收的报告 |
508
510
  | <a href="https://github.com/dunxuan"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/dunxuan.png" width="40" height="40" alt="@dunxuan"></a> | [#20](https://github.com/chromoany/dsh-notify-me/issues/20):当前会话的通知正文用占位符、未取会话标题的报告 |
509
511
  | <a href="https://github.com/unnamed42"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/unnamed42.png" width="40" height="40" alt="@unnamed42"></a> | [#21](https://github.com/chromoany/dsh-notify-me/issues/21) / [#22](https://github.com/chromoany/dsh-notify-me/pull/22):Linux 上 `dsh://open` 抬窗失效的报障与补丁,1.14.4 起 macOS / Linux 恢复深链抬窗 |
510
512
  | <a href="https://github.com/LIEGU0317"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/LIEGU0317.png" width="40" height="40" alt="@LIEGU0317"></a> | [#24](https://github.com/chromoany/dsh-notify-me/issues/24) / [#25](https://github.com/chromoany/dsh-notify-me/pull/25):页面关闭后由宿主兜底推送、同源中继两个可选模块(默认关),含测试与文档;[#29](https://github.com/chromoany/dsh-notify-me/issues/29) / [#30](https://github.com/chromoany/dsh-notify-me/pull/30):宿主兜底漏读「转发外部通知」开关(心跳与 pagehide 带 `external`),1.19.0 起生效 |
@@ -515,6 +517,8 @@ powershell -NoProfile -File lib/focus-window.ps1 -ProcessId 0 # 末行应是 F
515
517
  | <a href="https://github.com/Inh-ui"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/Inh-ui.png" width="40" height="40" alt="@Inh-ui"></a> | [#33](https://github.com/chromoany/dsh-notify-me/issues/33):Windows 桌面端审批通知没有「同意 / 拒绝」按钮的反馈,以及 Electron 丢弃 `actions` / 桌面端注册不了 Service Worker 的源码级定位,1.19.0 起支持 |
516
518
  | <a href="https://github.com/sakurakugu"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/sakurakugu.png" width="40" height="40" alt="@sakurakugu"></a> | [#34](https://github.com/chromoany/dsh-notify-me/pull/34):同源中继自定义 JSON 请求体模板(`relay.bodyTemplate`),含测试与文档,1.20.0 起支持 |
517
519
  | <a href="https://github.com/AlbertDope"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/AlbertDope.png" width="40" height="40" alt="@AlbertDope"></a> | [#36](https://github.com/chromoany/dsh-notify-me/issues/36):Windows 中文用户名下审批按钮必弹 `800A004C` 的根因定位(WSH 按 ANSI 代码页解码处理器脚本)与修复验证,1.20.1 起修复 |
520
+ | <a href="https://github.com/TianqiCai"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/TianqiCai.png" width="40" height="40" alt="@TianqiCai"></a> | [#38](https://github.com/chromoany/dsh-notify-me/pull/38):macOS 已在前台时点通知不切会话的修复(1 秒轮询),含冒烟测试,1.21.0 起收编 |
521
+ | <a href="https://github.com/MVennn"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/MVennn.png" width="40" height="40" alt="@MVennn"></a> | [#40](https://github.com/chromoany/dsh-notify-me/issues/40):Windows 原生审批 Toast 点正文不唤醒最小化/托盘窗口的报障与定位,1.21.0 起修复 |
518
522
 
519
523
  署名口径:本仓库收编外部 PR 时以维护者提交落地——不沿用原 commit、不挂 Co-authored-by,GitHub 的 contributors 图只显示维护者,贡献者以上面的致谢署名。
520
524
 
package/lib/client.js CHANGED
@@ -3355,7 +3355,7 @@
3355
3355
  });
3356
3356
  } catch (e) {}
3357
3357
  // keep in sync with package.json "version" on every release
3358
- api.version = "1.21.0";
3358
+ api.version = "1.21.1";
3359
3359
  api.setConfig = function (patch) { return setConfigLocal(patch); };
3360
3360
  api.resetConfig = function () {
3361
3361
  try {
@@ -32,7 +32,7 @@ import {
32
32
  createPresence,
33
33
  copyFor,
34
34
  deliverNote,
35
- gateRequest,
35
+ guardRequest,
36
36
  pickLanguage,
37
37
  sessionName,
38
38
  clip,
@@ -291,9 +291,13 @@ export function mountHostFallback(ctx, config, shared) {
291
291
  respond(res, 405, { ok: false, reason: "method-not-allowed" });
292
292
  return;
293
293
  }
294
- const refusal = gateRequest(req, { bindHost: shared?.bindHost, allowedOrigins: shared?.allowedOrigins });
295
- if (refusal !== null) {
296
- respond(res, 403, { ok: false, reason: refusal });
294
+ const guard = guardRequest(req, {
295
+ bindHost: shared?.bindHost,
296
+ allowedOrigins: shared?.allowedOrigins,
297
+ connection: shared?.connection,
298
+ });
299
+ if (guard !== null) {
300
+ respond(res, guard.status, { ok: false, reason: guard.reason });
297
301
  return;
298
302
  }
299
303
  const page = presence.snapshot();
package/lib/index.js CHANGED
@@ -42,7 +42,7 @@ import {
42
42
  BRIDGE_ROUTE,
43
43
  bindHostOf,
44
44
  createPresence,
45
- gateRequest,
45
+ guardRequest,
46
46
  pickLanguage,
47
47
  readBody,
48
48
  respond,
@@ -473,23 +473,45 @@ function raiseWindow() {
473
473
  return pendingRaise;
474
474
  }
475
475
 
476
+ /**
477
+ * The composition's DSH connection service, when this host has one.
478
+ *
479
+ * `webServer.register` routes sit outside DSH's route table, so the composition
480
+ * never fences them for us; `connection.requestRejection` is the call its own
481
+ * routes make, and it carries both the Host/Origin fence and the browser
482
+ * session / API authentication. Read it lazily because a host that predates the
483
+ * service (or the route tests) must keep working without it.
484
+ * @param ctx - host cordis context.
485
+ * @returns the `connection` service, or `undefined` when this host has none.
486
+ */
487
+ function connectionOf(ctx) {
488
+ try {
489
+ return typeof ctx?.get === "function" ? ctx.get("connection") : Reflect.get(ctx, "connection");
490
+ } catch {
491
+ return undefined;
492
+ }
493
+ }
494
+
476
495
  /**
477
496
  * Build the focus-route handler. The GET form is a probe the page may use to
478
497
  * find out whether activation is available at all; only the POST form touches
479
498
  * the OS.
480
- * @param bindHost - the listener's configured bind address, when known.
499
+ * @param shared - `{ bindHost, connection }` from {@link apply}.
481
500
  * @returns the web-server route handler.
482
501
  */
483
- function createHandler(bindHost) {
502
+ function createHandler(shared) {
484
503
  return function handleFocus(req, res) {
485
504
  const method = req.method ?? "GET";
486
505
  if (method !== "GET" && method !== "HEAD" && method !== "POST") {
487
506
  respond(res, 405, { ok: false, reason: "method-not-allowed" });
488
507
  return;
489
508
  }
490
- const refusal = gateRequest(req, { bindHost });
491
- if (refusal !== null) {
492
- respond(res, 403, { ok: false, reason: refusal });
509
+ const guard = guardRequest(req, {
510
+ bindHost: shared.bindHost,
511
+ connection: shared.connection,
512
+ });
513
+ if (guard !== null) {
514
+ respond(res, guard.status, { ok: false, reason: guard.reason });
493
515
  return;
494
516
  }
495
517
  if (method === "GET" || method === "HEAD") {
@@ -626,9 +648,13 @@ function createBridgeHandler(state, shared) {
626
648
  respond(res, 405, { ok: false, reason: "method-not-allowed" });
627
649
  return;
628
650
  }
629
- const refusal = gateRequest(req, { bindHost: shared.bindHost, allowedOrigins: shared.allowedOrigins });
630
- if (refusal !== null) {
631
- respond(res, 403, { ok: false, reason: refusal });
651
+ const guard = guardRequest(req, {
652
+ bindHost: shared.bindHost,
653
+ allowedOrigins: shared.allowedOrigins,
654
+ connection: shared.connection,
655
+ });
656
+ if (guard !== null) {
657
+ respond(res, guard.status, { ok: false, reason: guard.reason });
632
658
  return;
633
659
  }
634
660
  if (method === "GET" || method === "HEAD") {
@@ -695,6 +721,7 @@ export function apply(ctx, config) {
695
721
  bindHost: undefined,
696
722
  allowedOrigins: state.allowedOrigins,
697
723
  presence: createPresence({ leaseMs: state.hostFallback.pageLeaseMs }),
724
+ connection: () => connectionOf(ctx),
698
725
  };
699
726
 
700
727
  // Both are mounted whenever they are enabled, even if the configuration is
@@ -712,7 +739,7 @@ export function apply(ctx, config) {
712
739
  shared.bindHost = bindHostOf(webCtx.webServer);
713
740
 
714
741
  webCtx.effect(
715
- () => webCtx.webServer.register({ kind: "exact", path: FOCUS_ROUTE, handler: createHandler(shared.bindHost) }),
742
+ () => webCtx.webServer.register({ kind: "exact", path: FOCUS_ROUTE, handler: createHandler(shared) }),
716
743
  "dsh-notify-me: window focus route",
717
744
  );
718
745
 
package/lib/mac-notify.js CHANGED
@@ -20,7 +20,7 @@ import { tmpdir } from "node:os";
20
20
  import { join } from "node:path";
21
21
  import { fileURLToPath } from "node:url";
22
22
 
23
- import { gateRequest, readBody, respond } from "./page-bridge.js";
23
+ import { guardRequest, readBody, respond } from "./page-bridge.js";
24
24
 
25
25
  export const MAC_NOTIFY_ROUTE = "/__dsh-notify-me/mac-notify";
26
26
  const HEADER = "x-dsh-notify-me-mac";
@@ -123,9 +123,13 @@ export function mountMacNotify(webCtx, config, shared, logger, deps = {}) {
123
123
  respond(res, 405, { ok: false, reason: "method-not-allowed" });
124
124
  return;
125
125
  }
126
- const refusal = gateRequest(req, { bindHost: shared.bindHost, allowedOrigins: shared.allowedOrigins });
127
- if (refusal !== null) {
128
- respond(res, 403, { ok: false, reason: refusal });
126
+ const guard = guardRequest(req, {
127
+ bindHost: shared.bindHost,
128
+ allowedOrigins: shared.allowedOrigins,
129
+ connection: shared.connection,
130
+ });
131
+ if (guard !== null) {
132
+ respond(res, guard.status, { ok: false, reason: guard.reason });
129
133
  return;
130
134
  }
131
135
  if (method === "GET") {
@@ -11,7 +11,11 @@
11
11
  * Those three sit on the same few primitives, and every one of them is a
12
12
  * correctness or security decision that must not drift apart:
13
13
  *
14
- * - {@link gateRequest}: the boundary the focus route has always used. It
14
+ * - {@link guardRequest}: every web-server route enters through this. When the
15
+ * host composition exposes its `connection` service, this is the same
16
+ * `requestRejection` call DSH's own routes make (Host/Origin fence plus
17
+ * browser authentication); a host without that service falls back to
18
+ * {@link gateRequest}, the boundary the focus route has always used. It
15
19
  * moved here when a second and a third route needed the same gate, and grew
16
20
  * the permitted-origin list so a tunnel-fronted host accepts the public
17
21
  * name its own page dials.
@@ -255,6 +259,41 @@ export function gateRequest(req, options) {
255
259
  return null;
256
260
  }
257
261
 
262
+ /**
263
+ * Refuse a request the DSH composition itself does not admit, then fall back to
264
+ * {@link gateRequest} for the part DSH leaves to the route.
265
+ *
266
+ * A `webServer` route is outside the composition's own route table, so DSH does
267
+ * not fence it: `connection.requestRejection` is the composition's Host/Origin
268
+ * fence plus its browser-session/API authentication, and every DSH route calls
269
+ * it before touching a payload. Hosts without a `connection` service (older DSH
270
+ * releases, plain Node, the route tests) have no such fence to apply and use
271
+ * {@link gateRequest} alone.
272
+ * @param req - the incoming request.
273
+ * @param options - `{ bindHost, allowedOrigins, connection }`; `connection` is
274
+ * the service, a getter returning it, or `undefined`.
275
+ * @returns `{ status, reason }` when refused, or `null` when the request may
276
+ * proceed.
277
+ */
278
+ export function guardRequest(req, options) {
279
+ const connection = typeof options?.connection === "function" ? options.connection() : options?.connection;
280
+ if (connection !== undefined && connection !== null && typeof connection.requestRejection === "function") {
281
+ let status;
282
+ try {
283
+ status = connection.requestRejection(req);
284
+ } catch {
285
+ // A composition that cannot answer for this request must not open the
286
+ // route: fail closed here rather than falling through to the weaker gate.
287
+ status = 403;
288
+ }
289
+ if (typeof status === "number") {
290
+ return { status, reason: status === 401 ? "unauthenticated" : "untrusted" };
291
+ }
292
+ }
293
+ const refusal = gateRequest(req, options);
294
+ return refusal === null ? null : { status: 403, reason: refusal };
295
+ }
296
+
258
297
  /**
259
298
  * @param webServer - the host web server service.
260
299
  * @returns its configured bind address when it exposes one.
package/lib/relay.js CHANGED
@@ -27,7 +27,7 @@
27
27
  * {@link RELAY_HEADER}, which a cross-site form post cannot set.
28
28
  */
29
29
 
30
- import { bindHostOf, createCredentialReader, deliverNote, gateRequest, readBody, respond } from "./page-bridge.js";
30
+ import { bindHostOf, createCredentialReader, deliverNote, guardRequest, readBody, respond } from "./page-bridge.js";
31
31
 
32
32
  /** Reject oversized bodies instead of buffering them. */
33
33
  const MAX_BODY_BYTES = 64 * 1024;
@@ -206,14 +206,13 @@ function createHandler(config, credentials, shared, logger) {
206
206
  respond(res, 405, { ok: false, reason: "method-not-allowed" });
207
207
  return;
208
208
  }
209
- // The gate covers every verb, the read-only probe included: the path of
210
- // this route is a capability, so an ungated probe would tell anyone who
211
- // guessed it that the guess was right. The allow-list is the one shared by
212
- // the bridge route and the health probe — one list of public names, not one
213
- // per route.
214
- const refusal = gateRequest(req, { bindHost: shared?.bindHost, allowedOrigins: shared?.allowedOrigins });
215
- if (refusal !== null) {
216
- respond(res, 403, { ok: false, reason: refusal });
209
+ const guard = guardRequest(req, {
210
+ bindHost: shared?.bindHost,
211
+ allowedOrigins: shared?.allowedOrigins,
212
+ connection: shared?.connection,
213
+ });
214
+ if (guard !== null) {
215
+ respond(res, guard.status, { ok: false, reason: guard.reason });
217
216
  return;
218
217
  }
219
218
  if (method === "GET" || method === "HEAD") {
package/lib/win-toast.js CHANGED
@@ -26,7 +26,7 @@ import { join } from "node:path";
26
26
  import { fileURLToPath } from "node:url";
27
27
  import { randomBytes } from "node:crypto";
28
28
 
29
- import { gateRequest, readBody, respond } from "./page-bridge.js";
29
+ import { guardRequest, readBody, respond } from "./page-bridge.js";
30
30
 
31
31
  export const WIN_TOAST_ROUTE = "/__dsh-notify-me/win-toast";
32
32
  const HEADER = "x-dsh-notify-me-win";
@@ -263,9 +263,13 @@ export function mountWinToast(webCtx, config, shared, logger, deps = {}) {
263
263
  respond(res, 405, { ok: false, reason: "method-not-allowed" });
264
264
  return;
265
265
  }
266
- const refusal = gateRequest(req, { bindHost: shared.bindHost, allowedOrigins: shared.allowedOrigins });
267
- if (refusal !== null) {
268
- respond(res, 403, { ok: false, reason: refusal });
266
+ const guard = guardRequest(req, {
267
+ bindHost: shared.bindHost,
268
+ allowedOrigins: shared.allowedOrigins,
269
+ connection: shared.connection,
270
+ });
271
+ if (guard !== null) {
272
+ respond(res, guard.status, { ok: false, reason: guard.reason });
269
273
  return;
270
274
  }
271
275
  if (method === "GET") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-notify-me",
3
- "version": "1.21.0",
3
+ "version": "1.21.1",
4
4
  "description": "离开 DSH 页面也能收到提醒:需要你操作 / 后台回复完成时发系统通知、标题标记与提示音,支持审批快捷裁决与外部推送,Web 版与桌面版均可用。",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -63,13 +63,13 @@ function decodePayload(call) {
63
63
  return JSON.parse(Buffer.from(call.args[at + 1], 'base64').toString('utf8'));
64
64
  }
65
65
 
66
- function mount(config = {}, deps = {}) {
66
+ function mount(config = {}, deps = {}, shared = { bindHost: undefined, allowedOrigins: [] }) {
67
67
  const routes = [];
68
68
  const ctx = {
69
69
  effect(fn) { fn(); return () => {}; },
70
70
  webServer: { register(route) { routes.push(route); return () => {}; } },
71
71
  };
72
- win.mountWinToast(ctx, config, { bindHost: undefined, allowedOrigins: [] }, undefined, {
72
+ win.mountWinToast(ctx, config, shared, undefined, {
73
73
  spawn: fakeSpawn,
74
74
  execFile: fakeExec,
75
75
  psPath: psPath,
@@ -211,6 +211,31 @@ try {
211
211
  writeAction('a5.txt', 'dsh-notify-me://approve?token=' + aged.token);
212
212
  assert(JSON.parse((await call(clocked[0].handler, 'GET')).body).actions.length === 0, 'an expired token is ignored');
213
213
 
214
+ // 3g. The composition's admission fence runs first when the host exposes its
215
+ // connection service: an unauthenticated browser session never reaches the
216
+ // action files or the toast helper, and an admitted request still gets the
217
+ // plugin's own loopback gate.
218
+ let admissionCalls = 0;
219
+ const fenced = mount({}, {}, {
220
+ bindHost: undefined,
221
+ allowedOrigins: [],
222
+ connection: () => ({
223
+ requestRejection(req) {
224
+ admissionCalls += 1;
225
+ return req.headers['x-test-deny'] ? 401 : undefined;
226
+ },
227
+ }),
228
+ });
229
+ assert(fenced.length === 1, 'fenced mount registers the toast route');
230
+ const fencedDenied = await call(fenced[0].handler, 'GET', { 'x-test-deny': '1' });
231
+ assert(fencedDenied.status === 401 && JSON.parse(fencedDenied.body).reason === 'unauthenticated',
232
+ 'a connection 401 is relayed before the toast route answers');
233
+ const fencedProbe = JSON.parse((await call(fenced[0].handler, 'GET')).body);
234
+ assert(fencedProbe.ok === true && admissionCalls === 2, 'an admitted probe answers normally after one admission call');
235
+ const fencedPeer = await call(fenced[0].handler, 'GET', {}, undefined, '10.0.0.9');
236
+ assert(fencedPeer.status === 403 && JSON.parse(fencedPeer.body).reason === 'bad-remote',
237
+ 'the plugin gate still refuses a non-loopback peer after admission');
238
+
214
239
  // 3f. Removal: withdraw by page tag, resolved to the history tag.
215
240
  spawned.length = 0;
216
241
  const removed = await post(handler, { remove: 'tag-1' });