Skip to content

[Bug] 3.5.1 内置规则 billing-header-* 中的 \u{200b} 是字面量,官方 x-anthropic-billing-hdr 始终不被剥离,WorkBuddy 仍 400 Illegal API invocation from an unapproved channel #685

Backlog

Description

@jawide

[Bug] 3.5.1:内置规则 billing-header-* 的 \u{200b} 是固定字面量,官方的 x-anthropic-billing-hdr 永远不会被剥离,WorkBuddy 仍 400 Illegal API invocation from an unapproved channel

版本号

3.5.1(D:\Program Files\Agent2API\agent2api.exe 文件版本 3.5.1,进程启动于 2026-11-24 09:50)

哪一家 / 哪个地区版本

WorkBuddy(provider=workbuddy)。凭证是把 WorkBuddy 账号当作 Claude 用的方式接入的:客户端走 Anthropic Messages 协议(/v1/messages),网关按原生 Anthropic 转发到 WorkBuddy。

同一时间,这一家的官方客户端能正常用吗?

能,官方客户端正常,只有走网关报错。(注意:这不是账号问题,见下面「为什么不是账号问题」。)

你做了什么,看到什么

1. 在 Agent2API 里添加 WorkBuddy 账号
2. 用 Claude(Anthropic Messages 协议)走网关调 workbuddy 模型
3. 返回 400: Illegal API invocation from an unapproved channel(每次都复现)

(本 issue 的代码层复核覆盖了 `hdr` / `header` 两种拼写、以及 ZWSP 与连字符的 4 种组合;见文末「附:本地复核范围」)
{"code":11-128,"msg":"Illegal API invocation from an unapproved channel",
 "displayMsg":{"en":"Request blocked. Please send it again",...},
 "displayTips":{"en":"This call failed channel verification, possibly because it was not sent from an official client. ...",...}}

(这条 error body 与 issue #562 中贴出的上游原文一致,说明命中的是同一类 11-128 渠道校验拦截。)

根因(代码层,已定位到具体行)

desktop-tauri/src-tauri/server/src/server/core/sanitize/rules.rs 里的两条内置规则:

(
    "billing-header-value",
    "x-anthropic-billing-hdr",
    r"(?i)x\u{200b}-anthropic-billing-header:[^;\n]*;?[\t\n\f\r ]*",
    "",
    false,
),
...
(
    "billing-header-name",
    "x-anthropic-billing-hdr",
    r"(?i)x\u{200b}-anthropic-billing-header",
    "x-anthropic-billing-hdr",
    false,
),

这两条规则都是在匹配 x + ZWSP + -anthropic-billing-header 这一段文本,而不是匹配官方实际发出的 x-anthropic-billing-hdr。也就是说,这两条规则对官方 billing header 的两种真实拼写都不生效:

  • 官方 Anthropic SDK / Claude 客户端发的是 x-anthropic-billing-hdr(hdr 拼写、无 ZWSP、一个 -),规则不会命中;
  • Claude Code 旧版本 / 其他兼容实现可能发的是 x-anthropic-billing-header(header、无 ZWSP),规则也不会命中;
  • 唯一能命中的是 x + ZWSP + -anthropic-billing-header(ZWSP 直接跟在 x 之后、只有一个 -、且以 header 收尾 —— ZWSP、连字符、header 三个特征同时满足),而现实中几乎不会有客户端发这种拼写。再算上 x 与 - 之间没 ZWSP、或只有 - + ZWSP + 再一个 - 的变体,当前两条规则也一样不命中(见复核段 4 个样本)。

所以「billing header 剥离」这条防护在 3.5.1 里实际上是始终不命中的(无论走多长的 system 都不会改写到它)。调用方自己手写的 \u{200b}? 可选写法(社区在 #460 里加的补丁)在 Rust regex crate 里也不生效 —— x(?:\u{200b})?anthropic 对 x-anthropic 能命中,但对 x-​anthropic(ZWSP 夹在 - 之后)不会命中,因为 - 位置是硬性的。我本地在 rust regex 1.13.x 上逐字符复核过这两种情况。真正要「让 ZWSP 可选、同时允许 0~N 个 - 或 ZWSP」的类写法是:

r"(?i)x[-\u{200b}]*anthropic-billing-head(?:er|r)"           // 名称
r"(?i)x[-\u{200b}]*anthropic-billing-head(?:er|r):[^;\n]*;?[\t\n\f\r ]*"  // 键值整段删除

为什么这是「不是账号问题」

对当前 Claude + workbuddy 场景的额外证据

我有三条独立线索都把枪口指到「system/billing header 没被剥掉」,而不是「账号有问题」:

  1. 网关代码里已经内置了针对这条 header 的剥离规则(billing-header-value / billing-header-name,见 rules.rs)—— 作者本身就知道 x-anthropic-billing-hdr 这一行需要剥;但按上面定位,这两条规则对 hdr / header 两种真实拼写都不命中,于是 system 里的这条 header 实际上原样透传出网关 → 上游按逐字匹配命中 → 400。这是我在代码层能给出的最直接证据:问题不是「账号被风控」,而是「我们已经想去剥这条 header 了,但剥的动作从没真正执行过」。
  2. 11-128 的 displayTips 原文就是「not sent from an official client」/「渠道校验」,配合 [Bug] 升级 3.4.0 后,DeepSeek Harness 调用 glm-5.3-flash 持续返回 400 "Illegal API invocation from an unapproved channel"(仅 workbuddy 通道) #460 中已核实的结论「上游是逐字匹配固定串」,可以排除「会话 id 缺失 / 凭证失效 / 限额」这一类账号维度原因。
  3. 网关自己已经内置的两条 billing 规则就在 sanitize::default_rules() 里、默认 enabled: true,并且「指纹脱敏」开关默认开 —— 用户在 UI 上看到的开关是「已开启」,可实际上这两条规则从未命中过任何一条 billing header。这是最容易误导用户的一层。

复现(最小化)

# 走 Claude Messages 协议,system 里带官方 billing header
curl -sS http://127.0.0.1:3065/v1/messages \
  -H "x-api-key: $GATEWAY_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-haiku-4-5",
    "max_tokens": 32,
    "stream": false,
    "system": [
      {"type":"text","text":"x-anthropic-billing-hdr: tenant-id=example; plan=pro; region=cn;"},
      {"type": "text", "text": "You are Claude Code, Anthropic\u0027s official CLI tool for Claude"}
    ],
    "messages": [{"role":"user","content":"reply with the single word: ok"}]
  }'
  • 不命中 billing 规则时(例如 system 换成 You are a helpful assistant.)→ 200
  • 保留 x-anthropic-billing-hdr: 行 → 400,error body 如上面的 11-128(注意:3.5.1 的 billing-header-* 规则对它不生效,所以这行在网关上不会被剥离,会原样到达 WorkBuddy)

我建议的修复

  1. 修内置规则的两个 pattern(billing-header-name 与 billing-header-value,各改一处):

    // billing-header-name
    r"(?i)x[-\u{200b}]*anthropic-billing-head(?:er|r)"
    // billing-header-value
    r"(?i)x[-\u{200b}]*anthropic-billing-head(?:er|r):[^;\n]*;?[\t\n\f\r ]*"
  2. 加回归测试(建议放在 server/core/sanitize/tests.rs 或 rules.rs 的 #[cfg(test)] 模块里):至少覆盖以下 4 个样本(全部应命中并被剥离):

    • x-anthropic-billing-hdr: ...(官方 SDK,hdr 拼写、无 ZWSP)
    • x-anthropic-billing-hdr: ...(旧版本,header 拼写、无 ZWSP)
    • x-​-anthropic-billing-header: ...(ZWSP 夹在 x 与 - 之间)
    • x-​-anthropic-billing-header: ...(ZWSP 夹在 - 之后,两侧各一个 -)
  3. 顺手修 x\u{200b}? 的陷阱:社区补丁里这个写法不会让 ZWSP 可选(\u{200b}? 是把 b 字符后面加 ?,语义完全不同)。如果有人在用户侧自建词表里用了它,建议在 README / 设置页提示「若要覆盖 ZWSP,请用 [-\u{200b}]* 字符类写法」,避免用户误以为已经修好。

  4. (可选)对 x-anthropic-billing-* 加一行运行日志:命中时打到 [Upstream] verbose,便于用户确认到底是「这条规则没生效」还是「其他串触发的拦截」。现在 sanitize 命中结果会进 sensitiveHits,但用户很难把「billing header 漏了」与「其他 system 模板」区分开。

补充信息(可选,但可能值得一并考虑)

附:本地复核范围

  • 在 rustc 1.99.1 + regex 1.13.x 上复现:当前两条 pattern 对 x-anthropic-billing-hdr / x-anthropic-billing-header / x-​anthropic-billing-header / x-​-anthropic-billing-header 全部 0 命中。
  • 修正后的 x[-\u{200b}]*anthropic-billing-head(?:er|r) 对以上全部 命中。
  • 未在真实 WorkBuddy 账号上做端到端复测(本 issue 是代码层定位 + 可执行复现脚本);提交者(jawide)可协助提供复现日志 / 抓包。

Activity

  1. emplanetes commented on Nov 24, 2026

    @emplanetes

    我也碰到了

  2. L0NE-6 commented on Nov 26, 2026

    @L0NE-6

    已复核并落地维护分支:L0NE-6/Agent2API-Deploy 的 maintenance/3.5.1-plugin,远端 HEAD 6ceb1e4。

    • 根因:billing-header-* 两条正则把零宽空格写成固定字面量,无法覆盖官方 x-anthropic-billing-hdr 及 header 拼写。
    • 改动:desktop-tauri/src-tauri/server/src/server/core/sanitize/rules.rs 的 name/value 两条规则改为允许 -/ZWSP 组合并覆盖 hdr|header;sanitize.rs 增加行为测试;README 同步说明。
    • 测试:cargo +stable-x86_64-pc-windows-gnu test --target x86_64-pc-windows-gnu -p agent2api-server --lib anthropic_billing_header -- --nocapture,结果 3 passed; 0 failed。
    • 边界:这是规则层和本地回归验证;没有用真实 WorkBuddy 账号做端到端 400 复测,因此 issue 仍保持 OPEN,不冒充已关闭。
  3. L0NE-6 commented on Nov 26, 2026

    @L0NE-6

    补充共存边界:本地 fork 的 main 当前 HEAD 是 9f32965,其中 4b5289a(#685)已是祖先提交;9f32965 同时保留 #706 的 title-route 与 #652 的 forced-zero 改动。git diff --stat be7223e..HEAD 同时列出 sanitize.rs、sanitize/rules.rs、title_routes.rs、title_routing/mod.rs、error_policy_finish.rs、usage_records.rs。同一 HEAD 定向测试:#685 3 passed、#706 1 passed、#652 4 passed,均 0 failed。maintenance/3.5.1-plugin 是独立维护分支,不能整分支 merge 回 main。

  4. L0NE-6 commented on Nov 26, 2026

    @L0NE-6

    补充最终入口:#685 的最终维护入口是 L0NE-6/Agent2API-Deploy 的 main,当前 SHA 9f32965;该提交已包含 b2763ed/4b5289a 的 sanitize 修复与行为测试。旧的 maintenance/3.5.1-plugin 6ceb1e4 只是旧迁移分支,不要整分支合并,否则会回退 #706/#652。维护分支已 rebase 到 main,当前远端 HEAD 也是 9f32965。同一 HEAD 的定向测试仍为 #685 3/3、#706 1/1、#652 4/4,全部通过。

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions