Replies: 1 comment 1 reply
|
Hi, we hit exactly the same issue: Chrome/Chromium strips the port from the Origin header for loopback URLs ( We filed a bug report with the root cause and a suggested fix (compare hostname only, ignore the port): We also maintain a green "double-click to run" launcher distribution that already fixes this with an idempotent patch (Origin check changed to hostname comparison; in LAN mode it also merges the machine's LAN IPs into trustedHosts). Feel free to reference the approach or use it directly:
你好,我们遇到了完全一样的问题:Chrome/Chromium 对回环地址( 同时我们维护的绿色整合版启动器已经解决该问题(自动打幂等补丁:Origin 校验改 hostname 比较,局域网模式自动并入本机局域网 IP),欢迎参考方案或直接使用:
本回复由 AI 辅助撰写 / This reply was drafted with AI assistance. |
Uh oh!
There was an error while loading. Please reload this page.
摘要
Chrome 访问
http://127.0.0.1:3080时,请求的Origin头端口被剥离(http://127.0.0.1),而信任围栏isTrustedApiRequest用new URL(origin).host === hostUrl.host精确比较含端口的 host("127.0.0.1" !== "127.0.0.1:3080")→ 同源请求被误判为不可信 →host.pickDirectory等 API 返回 403,选择工作区失败。Sec-Fetch-Site: same-origin已证明请求同源,却被端口比较先行拒绝。复现步骤
@deepseek-ai/dsh@0.1.0-rc.6,运行dsh web。http://127.0.0.1:3080/。POST /api/host.pickDirectory返回 403,界面提示"无法打开文件夹"。Host: 127.0.0.1:3080、Origin: http://127.0.0.1(端口被剥离)、Sec-Fetch-Site: same-origin;改用http://localhost:3080/则正常。根因(源码定位,rc.6)
@deepseek-ai/dsh-client-connection/lib/index.jsisTrustedApiRequest(L184-198):origin.host(含端口)与hostUrl.host(含端口)必须完全相等;Chrome 对回环地址请求序列化 Origin 时剥离非默认端口(http://127.0.0.1),两者不等 → 403;same-origin标记(浏览器只读 fetch metadata)本已证明请求同源,但 L194 的端口比较先行拒绝。建议修复
方案 A(推荐)· 改为 hostname 级比较:L194 改
new URL(origin).hostname === hostUrl.hostname——容忍 Origin 端口剥离,一行级改动。Origin: http://127.0.0.1:9999的攻击者本可直接发无 Origin 请求;sec-fetch-site由浏览器生成(非浏览器伪造会标记 cross-site/none → L190 拒绝);跨主机(evil.com)hostname 不等仍拒绝。方案 B · 仅 same-origin 时放宽:
sec-fetch-site === "same-origin"时按 hostname 比较,否则保留端口精确比较。更保守,但 same-site 跨端口本地访问仍会被误拒(维持现状)。方案 C · 归一化默认端口:比较前把回环地址的默认端口归一化。复杂化,无必要。
影响
isTrustedApiRequest的两类缺陷;环境
验证材料
dsh-client-connection/lib/index.jsL184-198;First analysis of discussion #1119. Happy to open a PR with fix option A.
All reactions