Skip to content

[PR] fix(launcher): bypass loopback proxying for claude and unwrap absolute /bili/ URLs - #2746

Closed
130014 wants to merge 1 commit into
ranxianglei:masterfrom
130014:fix-claude-launcher-proxy-loop
Closed

130014 wants to merge 1 commit into
ranxianglei:masterfrom
130014:fix-claude-launcher-proxy-loop

Conversation

@130014

@130014 130014 commented Oct 11, 2026

Copy link
Copy Markdown

Summary

Fixes an HTTP 403 tunnel_destination_denied ("the bili tunnel may not target the proxy itself") error when launching Claude Code via bili claude.

Root Cause

  1. Missing NO_PROXY in ENV_CLIENTS.claude:
    bili claude sets HTTPS_PROXY (for cert-MITM) and ANTHROPIC_BASE_URL (loopback rewrite to http://127.0.0.1:<port>/bili/https://api.anthropic.com). Without LAUNCHER_LOOPBACK_NO_PROXY, Claude's HTTP client (undici/EnvHttpProxyAgent) treats the loopback target as a proxied destination, emitting absolute-form HTTP requests (POST http://127.0.0.1:<port>/bili/... HTTP/1.1).
  2. Absolute-form /bili/ URL handling in resolveUpstream:
    resolveUpstream checked reqUrl.startsWith("/bili/"), failing to match absolute-form URLs (http://127.0.0.1:<port>/bili/...) and falling through to the general forward-proxy handler. This set upstream to the proxy itself (http://127.0.0.1:<port>), which checkTunnelDestination Layer 1 rejected with 403.

Changes

  • src/launcher.ts: Injected LAUNCHER_LOOPBACK_NO_PROXY (localhost,127.0.0.1,::1) into ENV_CLIENTS.claude via extras, aligning it with qwen, jcode, aider, and zed.
  • src/server.ts: Normalized incoming URLs in resolveUpstream so absolute URLs targeting /bili/ unwrap the embedded upstream path instead of proxying to the local host.
  • tests/launcher.test.ts: Added assertions verifying NO_PROXY and no_proxy in buildClaudeEnv.
  • tests/zero-config-routing.test.ts: Added unit tests for absolute-form /bili/ URLs (with/without query parameters and explicit protocols) and standard forward-proxy URLs.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,正在按 review 规范审查本 PR:方向核实(bug 是否真实存在)、回归清点、代码与测试有效性、diff 整洁度。分支已拉取(基于当前 master,无落后)。结论稍后以结构化八问给出。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 结论:代码通过;CI 红是 master 存量断言漂移(已在 master 修掉),与 PR 无关。rebase/re-run 后可合。

结构化八问

  1. 是什么问题:bili claude 启动的较新版本 Claude Code(undici EnvHttpProxyAgent,遵守代理 env)把 ANTHROPIC_BASE_URL=http://127.0.0.1:<port>/bili/https://api.anthropic.com 这个 loopback 目标当作代理目的地,发出 absolute-form 请求行(POST http://127.0.0.1:<port>/bili/... HTTP/1.1);bili 的 resolveUpstream 只认相对 /bili/ 前缀,absolute-form 落进通用 forward-proxy 分支,upstream 被设成 bili 自己 → tunnel-guard Layer 1(self)拒绝 → 403 tunnel_destination_denied。
  2. 什么原因导致的:两层。产生层:ENV_CLIENTS.claude 缺 NO_PROXY(qwen/jcode/aider/zed 都有,claude 漏了)——这是 absolute-form 请求行的生产者;cc 版本相关(旧版 desktop-embedded CC 忽略代理 env,见 README Claude Desktop (Code tab) overrides ANTHROPIC_BASE_URL: claude native lane never sees traffic, and auto-compact is left disabled #2290 field-note,所以是特定条件下触发)。判定层:resolveUpstream 的 /bili/ 前缀匹配不覆盖 absolute-form URL(误分类决策点,与 bug: 标准 HTTP 代理请求被误判为自身请求,导致上游模型窗口配置失效 #562 Host-header 修复同族)。修法分别打在两层,不是遮症状。
  3. 影响范围与严重程度:用 bili claude 且 CC 为遵守代理 env 的新版本的用户:每个 Anthropic API 请求都 403,该路径完全不可用;旧版 CC 或其他客户端不受影响。
  4. 怎么修复的:① launcher 给 claude 注入 NO_PROXY/no_proxy=localhost,127.0.0.1,::1(复用既有 LAUNCHER_LOOPBACK_NO_PROXY 常量,无条件覆盖契约与 jcode/aider/zed/kimi 一致);② server 在 resolveUpstream 匹配 /bili/ 之前先归一化 absolute-form URL,unwrap 出嵌入的上游 path(query 保留),embedded destination 仍走完整 checkTunnelDestination。即使 ① 因客户端差异失效,② 也保证正确路由——双保险互为兜底。
  5. 是否有回归问题:无。A/B 验证(master vs PR 分支同一探测脚本):相对形式请求两分支结果逐字段一致(零漂移);非-/bili/ absolute-form(forward-proxy 正当用途)两分支一致;MITM socket 路径先于该逻辑检查、未触碰;唯一行为差集是「absolute-form /bili/ → 本地 unwrap」vs 旧「转发到外层 host」——后者要求客户端拿 bili 当 forward proxy 同时向另一台主机要 /bili/ 路径,概率近零,且 embedded destination 仍过完整 tunnel-guard(self/linkLocal/private 各层),无新 SSRF 面。nudge side-channel(runNudgeDecision)复用同一 route,行为一致。typecheck 干净;定向测试 launcher+zero-config-routing 300 pass / 0 fail / 1 skip。
  6. 是否破坏缓存:不涉及(prefix-cache/system 字节面、重试、游标均未触碰)。
  7. 是否改了设计方向:不涉及(沿用现有 /bili/ rewrite 机制与 env-preset 单写者契约)。
  8. 是否引入新配置:无(仅使用既有常量,无新 env/config/默认值)。

CI 状态与归因(关键)

四个 test leg(ubuntu/windows × Node 22/24)全红,但每个 leg 恰好只有 2 个失败,均为 tests/issue2658-dsh-anthropic-google-compaction.test.ts:198(assertRebased:期望 3 refs,实际 4)——master 存量断言漂移,与本 PR 无关:

需要的动作:作者 rebase 到当前 master(≥ b67d7d5)或直接 re-run 失败的 test job(会按最新 base merge 重建)→ 变绿即可合并。本 PR 触碰 src/server.ts wire routing,属 human-only tier,由人合并。

两点补充

  1. 此 PR 没有关联 issue(仓库规范 §4:bare PR without issue 不合格)。请补一个记录该问题的 issue 并在 PR 里 Fixes #N 关联,或请 owner 裁定豁免。
  2. 建议 PR 描述补一句复现用的 Claude Code 版本号——该问题按 CC 版本表现不同(旧版忽略代理 env,新版经 undici 遵守),对后续维护是重要上下文。

判定:代码质量通过、方向正确、无回归;CI 存量红已在 master 修复,rebase/re-run 转绿后可合。

@ranxianglei

Copy link
Copy Markdown
Owner

(ai: zhipuai-lb/glm-5.3)

孤儿票清理:提交两周未更新、无 issue 关联,且相关领域已有后续修复落地。为避免重复劳动关闭;如果你想继续推进,请 reopen 并补一个关联 issue(Fixes #N),我们会优先审查。感谢贡献!

@ranxianglei ranxianglei changed the title fix(launcher): bypass loopback proxying for claude and unwrap absolute /bili/ URLs [PR] fix(launcher): bypass loopback proxying for claude and unwrap absolute /bili/ URLs Oct 24, 2026
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