mirror of
https://github.com/chenyme/grok2api.git
synced 2026-12-05 16:02:12 +00:00
fix(cf): 调换 _resolve_profile 读取优先级 — 扁平 legacy 路径优先
问题: 修复第一版里 _resolve_profile 优先读 proxy.clearance.user_agent(嵌套 v2 路径), fallback 才读 proxy.user_agent(扁平 v1 路径)。但 config.defaults.toml 里 proxy.clearance.user_agent 预设了占位 Chrome 136 UA(非空字符串),所以外部 cf-refresher sidecar 写到 proxy.user_agent 的新鲜 Firefox UA 永远被 defaults 盖掉。 结果 Cookie 里带的 cf_clearance 是用 Firefox UA 获取的,但实际请求 UA 变成了 Chrome 136。 Cloudflare 把 cf_clearance 绑定到首次获取时的 UA,UA 一变即 403。 修复: 扁平 legacy 路径(proxy.xxx)优先, 嵌套(proxy.clearance.xxx) 作为 fallback。 这样 cf-refresher 写扁平路径时能立即覆盖 defaults 的占位值。cf_clearance/cf_cookies 同样遵循此顺序以保持一致。
This commit is contained in:
1 parent
9389515519
commit
0e97d7866d
1 file changed
+19
-10
@@ -167,23 +167,32 @@ def _resolve_profile(lease: ProxyLease | None) -> tuple[str, str, str]:
|
||||
empty string. This prevents bare requests with no User-Agent when running
|
||||
in direct mode or when FlareSolverr has not yet delivered a bundle.
|
||||
|
||||
Backward-compat: cf_clearance is also probed at the legacy ``proxy.cf_clearance``
|
||||
path so that configs migrated from v1.x (where clearance was refreshed by a
|
||||
sidecar writing the flat key) keep working. The legacy ``proxy.cf_cookies``
|
||||
/ ``proxy.user_agent`` paths are similarly honored as a last-resort fallback.
|
||||
Priority order (flat legacy first, nested fallback second):
|
||||
- ``proxy.cf_clearance`` / ``proxy.cf_cookies`` / ``proxy.user_agent``
|
||||
(flat v1.x-style keys, written by external cf-refresher sidecars)
|
||||
- ``proxy.clearance.cf_clearance`` / ``proxy.clearance.cf_cookies`` /
|
||||
``proxy.clearance.user_agent`` (nested v2.x schema, populated by
|
||||
``config.defaults.toml`` and the internal clearance manager)
|
||||
|
||||
Rationale: when an external sidecar refreshes cf_clearance and writes to
|
||||
the flat keys, those values must *override* the stale defaults shipped in
|
||||
``config.defaults.toml`` under ``[proxy.clearance]``. Previously the order
|
||||
was reversed, so a non-empty placeholder UA in defaults shadowed the fresh
|
||||
UA supplied by the refresher, causing a UA/cf_clearance mismatch and a 403
|
||||
from Cloudflare (the cookie is bound to the UA of the acquiring browser).
|
||||
"""
|
||||
cfg = get_config()
|
||||
cfg_cookies = (
|
||||
cfg.get_str("proxy.clearance.cf_cookies", "")
|
||||
or cfg.get_str("proxy.cf_cookies", "")
|
||||
cfg.get_str("proxy.cf_cookies", "")
|
||||
or cfg.get_str("proxy.clearance.cf_cookies", "")
|
||||
)
|
||||
cfg_ua = (
|
||||
cfg.get_str("proxy.clearance.user_agent", "")
|
||||
or cfg.get_str("proxy.user_agent", "")
|
||||
cfg.get_str("proxy.user_agent", "")
|
||||
or cfg.get_str("proxy.clearance.user_agent", "")
|
||||
)
|
||||
cfg_clearance = (
|
||||
cfg.get_str("proxy.clearance.cf_clearance", "")
|
||||
or cfg.get_str("proxy.cf_clearance", "")
|
||||
cfg.get_str("proxy.cf_clearance", "")
|
||||
or cfg.get_str("proxy.clearance.cf_clearance", "")
|
||||
)
|
||||
if lease is not None:
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user