Skip to content

fix(release-download): 修复带方括号的 IPv6 代理地址解析失败 - #3836

Merged
deepcoldy merged 2 commits into
deepcoldy:masterfrom
Vince-9:fix/ipv6-proxy-address
Nov 25, 2026
Merged

deepcoldy merged 2 commits into
deepcoldy:masterfrom
Vince-9:fix/ipv6-proxy-address

Conversation

@Vince-9

@Vince-9 Vince-9 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

改了什么

  • 在 src/core/release-download.ts 新增 stripHostBrackets(),对通过 new URL(hopProxy) 解析出的代理 hostname 去除 IPv6 字面量方括号(如 [::1] → ::1)后再传给 node:http 的 httpRequest({ host })(覆盖 HTTPS CONNECT 隧道与明文 HTTP 代理两条分支)。
  • 在 HTTPS CONNECT 建立 TLS 握手时,对 IP 字面量目标省略 servername(遵循 RFC 6066,与 https-proxy-agent 保持一致),域名目标行为不变。
  • 在 test/update-check-proxy.test.ts 补齐 stripHostBrackets 单测以及绑定真实 ::1 代理的 HTTP(含 Basic 鉴权)与 HTTPS CONNECT 回归测试;在 test/settings-http-proxy-ui.test.ts 与 test/settings-write-applier.test.ts 补充带方括号 IPv6 代理地址的校验用例。

为什么

WHATWG URL.prototype.hostname 会保留 IPv6 地址的方括号(例如 new URL('http://[2001:db8::1]:3128').hostname === '[2001:db8::1]'),而 node:http 在 Node 与 Bun 下都会将 options.host 直接传给 net.connect / dns.lookup,导致配置标准 IPv6 代理地址时始终以 getaddrinfo ENOTFOUND [...] 失败。

仓库内其他代理/回环路径(loopback-fetch.ts、sandbox-network-proxy.ts、hook-installer.ts 以及 https-proxy-agent / http-proxy-agent)均已剥离方括号,Dashboard 的 httpProxy 校验也允许带方括号的 IPv6 地址,本次修复使 release-download 与之保持一致。

影响面评估

  • 涉及模块:src/core/release-download.ts 及其全部调用方——版本检查(src/core/update-check.ts)、独立二进制自更新(src/core/binary-self-update.ts)、预编译 tmux 下载(src/setup/tmux-prebuilt.ts)。
  • 兼容性:非 IPv6 代理地址(域名、IPv4)与直连路径行为完全不变;Linux / macOS、Node / Bun 双运行时行为一致;不涉及会话类型或 CLI 适配器改动。

测试验证

  • bun run test -- test/update-check-proxy.test.ts test/settings-http-proxy-ui.test.ts test/settings-write-applier.test.ts test/binary-self-update.test.ts test/test-hygiene.test.ts:5 个文件、320 个用例全部通过(包含真实 ::1 HTTP 代理与 HTTPS CONNECT 代理用例)
  • bun test test/update-check-proxy.test.ts test/settings-http-proxy-ui.test.ts test/settings-write-applier.test.ts:Bun 1.4.4 下 215 pass, 0 fail
  • bun run build:域名审计、tsc、typecheck、Dashboard 打包与产物审计全部通过

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审结论:有 1 个阻断项

[P2] Node 下 IP 目标的证书被按 localhost 校验,IPv4 CONNECT 场景出现回归

位置:src/core/release-download.ts:124

const tls = tlsConnect({ socket, ...(isIP(targetHost) ? {} : { servername: targetHost }) }, () => {

这里对 IP 字面量省略 servername 是正确方向,但同时没有传 host。Node 在 tls.connect({ socket }) 未提供 host / servername 时,会使用默认的 localhost 做证书身份校验,而不是 CONNECT 的目标 IP。因此,目标证书即使包含正确的 IP SAN,也会被拒绝。

用真实本地 HTTP 代理、200 Connection Established、本地 HTTPS 目标和仅含目标 IP SAN 的 CA/证书跑完整链路,结果如下:

  • PR 前(8d41c3e5^):Node 访问 https://127.0.0.1:<port>,经 IPv4 HTTP 代理 CONNECT,响应正文正确且 authorized=true;仅有预期的 DEP0123 告警。
  • 当前 head(8d41c3e5):相同 IPv4 场景报 ERR_TLS_CERT_ALTNAME_INVALID: Hostname/IP does not match certificate's altnames: Host: localhost;IPv6 目标也以同样原因失败。
  • 当前 head 在 Bun 下通过,说明这里存在运行时差异,不能由 Bun 探针推断 Node 也正确。

影响边界:域名目标不受影响;但 PR 前可用的“HTTPS IPv4 目标 + HTTP 代理 CONNECT”会发生回归,且本 PR 想覆盖的 HTTPS IPv6 目标在 Node 下仍不可用。该路径由自定义 HTTPS registry / 下载 URL 经 getReleaseStream 触达。

建议保留目标身份但仅对域名发送 SNI:

const tls = tlsConnect({
  socket,
  host: targetHost,
  ...(isIP(targetHost) ? {} : { servername: targetHost }),
}, () => {

已在隔离副本验证此修法:Node / Bun 的 IPv4、IPv6 CONNECT 成功链路均返回正确正文且 authorized=true。建议再补一条 CONNECT 200 + IP SAN 证书的端到端回归用例;现有 403 用例只覆盖拨号与 CONNECT 线格式,触达不到这段 TLS 逻辑。

其余复核与验证

  • 代理 host 去括号覆盖 HTTPS CONNECT 与明文 HTTP 两个拨号分支;CONNECT authority / Host 头仍保留 IPv6 方括号,未见其它拨号点遗漏。
  • bun run test -- test/update-check-proxy.test.ts test/settings-http-proxy-ui.test.ts test/settings-write-applier.test.ts test/binary-self-update.test.ts test/test-hygiene.test.ts:5 files / 320 tests 全绿。
  • bun test test/update-check-proxy.test.ts test/settings-http-proxy-ui.test.ts test/settings-write-applier.test.ts:215 pass / 0 fail。
  • bun run build:通过。
  • 远端 head 仍为 8d41c3e5c3f85a634d95b2a5d598a43a766963d3;本地 rebase 提交与其 stable patch-id 一致(5330cd91…)。GitHub 上 build、test 4 shards、bun-test 4 shards、三平台 binary 与聚合检查现均已通过,但上述场景不在现有测试覆盖内。

结论:先修复 Node 下 CONNECT TLS 的目标身份传递,再合并。

- tls.connect 补传 host,避免 Node 对 IP 目标回退到 localhost 校验证书

- 增加 IPv4/IPv6 CONNECT 200 与 IP-only SAN 证书的端到端回归

Co-Authored-By: Claude Code <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner

阻断项已在追加提交 f7576128708c7dd42220d947188d38a390e28d2c 中修复,作者分支由 8d41c3e5 fast-forward 到新 head,未改写历史。

修复

  • src/core/release-download.ts:CONNECT 后的 tls.connect 补传 host: targetHost,让 Node 按实际目标 IP 校验证书;IP 字面量仍不发送 SNI,域名分支仍传 servername。
  • test/update-check-proxy.test.ts:新增 IPv4、IPv6 两条完整 CONNECT 200 + TLS + HTTP 响应回归。测试使用真实本地代理和 HTTPS 源站,证书只含目标 IP SAN;客户端子进程启动时通过 NODE_EXTRA_CA_CERTS 信任该 CA,没有关闭证书校验,并断言 authorized=true、CONNECT authority、目标 Host 和响应正文。

验证

  • bun run test -- test/update-check-proxy.test.ts test/settings-http-proxy-ui.test.ts test/settings-write-applier.test.ts test/binary-self-update.test.ts test/test-hygiene.test.ts:5 files / 322 tests 全绿。
  • bun test test/update-check-proxy.test.ts test/settings-http-proxy-ui.test.ts test/settings-write-applier.test.ts:217 pass / 0 fail。
  • bun run build:通过。
  • 变异复验:临时删除 host: targetHost 后,Node 下新增的 IPv4、IPv6 用例精确变红(均为 ERR_TLS_CERT_ALTNAME_INVALID,实际身份为 localhost),其余 28 个用例仍通过;恢复守卫后全绿。

新 head 的 CI 已触发,当前各检查排队中。

@deepcoldy
deepcoldy merged commit 3dffe94 into deepcoldy:master Nov 25, 2026
14 checks passed
@deepcoldy

Copy link
Copy Markdown
Owner

感谢贡献,已合入 master(squash 提交 3dffe94d)。

这个修复让标准写法的 IPv6 代理地址(如 http://[::1]:3128)在版本检查、二进制自更新和 tmux 预编译下载三条下载链路都能正常拨号;评审中另补齐了 CONNECT 隧道内 TLS 目标身份传递在 Node 下的回归防护,并新增了 IPv4/IPv6 两条真实 CONNECT + TLS 端到端回归用例。域名、IPv4 代理和直连路径行为不变。

这是自动评审的初步意见落地结果,后续发版节奏以维护者安排为准,欢迎继续贡献。

@github-actions

Copy link
Copy Markdown

@Vince-9 @deepcoldy 合入 master 后的 Midscene E2E 失败:Feishu live Midscene 失败。

这次运行覆盖 350ce55…6389a341d(8 个提交),同批合入的还有 #3835 #3832 #3838 #3795 #3837 #3827 #3840,失败不一定由本 PR 引起。

用例 跑道 状态 失败信息
Thread /status and /close commands feishu-core-conversation failed Timed out after 1500000ms waiting for shared chat lease dm:Claude
Claude DM thread mode gives each message its own topic and session feishu-core-dm-modes-claude failed Reply "ACK-e2e-dmthread-claude-1-1795645386433 RECALL ACK-e2e-dmthread-claude-1-1795645386433" appeared 0 time(s) within 240000ms, expected 1 (clicked 直接开启会话 2×; re-opened 1×; repo card buttons 0 vis…

@github-actions

Copy link
Copy Markdown

🚀 Released in v3.59.34

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants