fix(proxy): restore HTML injection for real browsers, make remote settings editable (Closes #58) - #130
Open
JanEickholt wants to merge 4 commits into
Conversation
… opt-in (shaobeichen#58) 问题(issue shaobeichen#58 + 本地排查): 1. 注入对真实浏览器从未生效:代理只注入未压缩 HTML(isCompressed 跳过), 而 dsh web 对浏览器导航返回 gzip 压缩文档 → polyfill 与 transport shim 全部落空。此前历次注入类修复(shaobeichen#3/shaobeichen#53/shaobeichen#96)实际都是死代码。 2. 远程设置不可用(issue shaobeichen#58):dsh-client-connection 以 location.hostname 判 isLoopback;经代理访问时是局域网 IP/隧道域名 → settings mirror 降级 memory 只读 → 插件配置/模型管理报 settings unavailable。 shaobeichen#87 的 location 伪装方案因 shaobeichen#105 回退;作者等待的「可注入 loopback 标记」 其实已存在:transport?.ownsHost === true。 修复: 1. HTML 导航请求向上游要求 accept-encoding: identity,注入分支恢复生效; 压缩透传行为不变(上游忽略 identity 时仍原样透传,无损坏风险)。 2. 新增 TRUSTED_TRANSPORT_SHIM(仅当 __DSH_TRANSPORT__ 缺失时创建 { ownsHost: true },桌面端宿主自带的 transport 不受影响),默认关闭, 由设置页「远程设置」开关(trustProxiedClients)控制;开启后远程页面的 插件配置/模型管理恢复 host 持久化。安全边界回落到访问密码(公网强制)。 测试:test/proxy.test.js 新增 2 例(identity 注入恢复 + 信任开关默认值/ 运行时切换);既有「压缩 HTML 不注入」用例不变全绿。
…close the default-off proxy in finally - README.md / README.en.md:功能表新增一行 + 局域网区块补充说明(默认关闭, 开启后远程可编辑插件配置/模型管理,信任边界为访问密码) - test:信任开关用例里默认关闭的代理改在 finally 中关闭,断言失败不再悬挂 测试进程
…iption Leave the decision to the user: state what the switch does and that the access PIN is the only safeguard, instead of 'mandatory for public, recommended for LAN'.
…models Strip the PIN trust-boundary wording from the switch description and the READMEs; the toggle's job is one sentence: allow remote edits or not.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
手机/远程页面无法编辑设置(Closes #58,v2.10.6 仍存在)。 经 dsh-pocket 代理访问时,DSH 客户端按
location.hostname判isLoopback,局域网 IP / 隧道域名都会判否 → settings mirror 降级 memory 只读 → 插件配置、模型管理报 "settings are unavailable in this browser"。#87 的 location 伪装方案已因 #105 回退。但 #58 结案时维护者等待的「可注入 loopback 标记」其实已经存在:dsh-client-connection里transport?.ownsHost === true就会被当作 loopback,只是 web shell 从不创建__DSH_TRANSPORT__。注入对真实浏览器从未生效。 代理只给未压缩的 HTML 注入(
isCompressed分支),而 dsh web 对浏览器导航返回 gzip 压缩文档 → polyfill(#3/#53)和 transport shim(#96)对真实浏览器全是死代码。现有测试「压缩 HTML(gzip)不注入」锁定的正是这个跳过行为。修复
accept-encoding: identity(lib/proxy.mjs,3 行)。上游忽略 identity 时行为不变:仍按isCompressed原样透传压缩流,无损坏风险;JS/CSS 子资源的压缩透传不受影响。TRUSTED_TRANSPORT_SHIM:仅当__DSH_TRANSPORT__缺失时创建{ ownsHost: true }(桌面端宿主自己会提供 transport,不受影响——这也是 fix(proxy): loopback trust patch so remote browsers can load settings (issue #58) #87/[Bug] LOOPBACK_ENV_PATCH(#87)与 DSH Desktop 2.0.4+ 客户端不兼容:手机/远程浏览器经代理访问主 UI 白屏 #105 白屏场景在本方案中不触发的原因)。默认关闭,由设置页局域网区新开关「远程设置」控制;代理每次请求实时读设置,切换立即生效、无需重启。开启后远程页面的插件配置/模型管理恢复 host 持久化,安全边界回落到访问密码(公网强制)。验证
node --test test/proxy.test.js:38/38 通过。新增 2 例(identity 注入恢复;信任开关默认值与运行时切换立即生效)。既有「压缩 HTML(gzip)不注入」用例未改动,仍绿——上游忽略 identity 的场景行为不变。npm test:180 例中 179 通过。唯一失败fileRead ~/ 展开为用户 HOME在未打补丁的 HEAD 上同样失败(该用例写$HOME,本机环境只读所致,与本改动无关)。与 #87/#105 的关系
本 PR 不伪装
location,也不给桌面端页面注入任何标记,因此不会重蹈 #105(DSH Desktop 2.0.4+ 远程客户端白屏)。开关默认关闭,信任语义与 #87 review 中「真正的信任边界一直是访问密码」一致。