Skip to content

fix: stop replaying poisoned Cloudflare __cf_bm cookie#583

Merged
icebear0828 merged 1 commit into
devfrom
fix/cf-bm-cookie
May 17, 2026
Merged

fix: stop replaying poisoned Cloudflare __cf_bm cookie#583
icebear0828 merged 1 commit into
devfrom
fix/cf-bm-cookie

Conversation

@icebear0828
Copy link
Copy Markdown
Owner

Summary

修复个别账号被 Cloudflare Bot Management __cf_bm cookie 反噬导致 /codex/responses 全 404、/codex/usage 仍正常的"配额没限却用不了"假死状态。根因是 proxy 在 warmup GET /codex/usage 时通过 captureCookies 把 CF 偶发下发的 __cf_bm 收进 jar,而 __cf_bm 绑死 (IP + UA + TLS fingerprint + 时序) 30 分钟会话指纹,fingerprint 一漂 CF 就用空 body 404 在重保护路径 stealth-deny。

Changes

两层修复:

  • Cookie 白名单:src/proxy/cookie-jar.ts 新增 CAPTURABLE_COOKIE_NAMES = {cf_clearance}captureRaw 主动丢弃 __cf_bm 等非白名单 cookie。admin API 手动 set() 不受限。
  • CF block 检测 + 自动隔离:src/proxy/error-classification.ts 新增 isCfPathBlockError(404 + 空 body);src/auth/cf-path-block-tracker.ts 1h 滑动窗口计数;src/routes/shared/proxy-error-handler.ts 命中时清 cookie + fail over 到其他账号,同号 1h 内 ≥3 次自动 disable + 记 Errors tab;src/services/account-mutation.ts re-enable 时 reset 计数。

测试覆盖:

  • tests/unit/auth/cf-path-block-tracker.test.ts(4 个 - 计数 / 窗口过期 / reset / peek)
  • tests/unit/proxy/error-classification.test.ts 新增 isCfPathBlockError section(4 个分支)
  • tests/unit/routes/shared/proxy-error-handler.test.ts CF block retry/disable 路径(2 个)
  • tests/unit/proxy/cookie-jar.test.ts 改写为白名单语义

Test Plan

  • Pre-push hook validation (test + build targets) — passed
  • Full suite per original commit (2258 tests green)
  • 本地 codex-proxy 重启后 /health 返回 200

Notes

Cherry-picked from fix/mac-x64-smoke-timeout (commit dd5fc96) onto a fresh branch off origin/dev. 原分支上还有重复的 mac x64 smoke 修复(已通过 #560 squash 进 dev)和本地 fingerprint bump,没带进来。

Cookie jar was auto-capturing CF's Bot Management session cookie from
warmup responses, then replaying it on /codex/responses where CF
returns an empty-body 404 once the bound (IP+UA+TLS+timing) drifts.
This produced the diagnostic contradiction of "quota fine, path 404".

Restrict auto-capture to a whitelist (cf_clearance only); manual admin
set() is unaffected. Add empty-body 404 detection that clears the
account's cookies and retries on a different account, auto-disabling
the account after 3 consecutive blocks within a 1h sliding window.
@icebear0828 icebear0828 merged commit 781e5b2 into dev May 17, 2026
2 checks passed
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.

1 participant