mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-15 23:22:59 +08:00
chatgpt.com 的 Cloudflare 会对 req 内置的 ImpersonateChrome(TLS/HTTP2 指纹与 UA 均为 Chrome/120)返回 403 cf-mitigated=challenge,导致 accounts/check、subscriptions、 account_user_setting 三个 backend-api 调用长期失败:订阅到期时间不再更新、隐私开关显示 Fail。 仅改 UA 版本号无效(指纹仍是 120),Firefox 伪装在同一出口下稳定通过,故切换。 同时: - 用 cf-mitigated 响应头识别质询页,隐私设置失败时正确标记为 training_set_cf_blocked - accounts/check / subscriptions 失败日志由 Debug 提升为 Warn 并附 cf_challenge 字段,不再静默 Closes #4825 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
26 lines
779 B
Go
26 lines
779 B
Go
package service
|
|
|
|
import "testing"
|
|
|
|
func TestIsCloudflareChallengeResponse(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
cfMitigated string
|
|
body string
|
|
want bool
|
|
}{
|
|
{"cf-mitigated challenge header", "challenge", "<html>...</html>", true},
|
|
{"header case-insensitive with spaces", " Challenge ", "", true},
|
|
{"body marker only", "", "<title>Just a moment...</title>", true},
|
|
{"plain json error", "", `{"detail":"Unauthorized"}`, false},
|
|
{"empty", "", "", false},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
if got := isCloudflareChallengeResponse(tc.cfMitigated, tc.body); got != tc.want {
|
|
t.Fatalf("isCloudflareChallengeResponse(%q, %q) = %v, want %v", tc.cfMitigated, tc.body, got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|