Repository navigation
fix(web): whoami 校验失败短缓存(防平台 IP 风控)+ EASEL_EXTRA_HOSTS 端口归一化 - #207
Merged
Merged
Conversation
- whoami 校验失败(风控/超时)此前不缓存,前端每次开页都重新起
headless 浏览器打平台,高频时触发 IP 风控(实测小红书 300012,
登录二维码无法获取)。失败结果带 verifyError 标记入 _WHOAMI_CACHE,
WHOAMI_FAILURE_TTL=120s 短过期;登录态标记变化时既有等式检查
自动失效重验,force=true 仍绕过缓存。
- EASEL_EXTRA_HOSTS 条目剥掉 ":端口":starlette TrustedHostMiddleware
按 Host 头去端口后的主机名比对(host.split(':')[0]),条目带端口
会永不匹配,反代域名一律 400 且无提示。
Collaborator
|
感谢问题复现和修复!已确认两处缺陷,审查后准备了补修:失败校验单独短缓存 120 秒,继续返回原有 502/504 错误,保留已验证的登录状态、昵称、头像,不把失败缓存作为已核实身份返回;超时和浏览器启动错误也进入短缓存。新登录、退出、标记/ Cookie 变化使缓存失效,手动 force 重试仍可绕过;同一平台保留并发合并校验。 Host 仅剥离明确的数字端口,避免误拆 IPv6 字符串;Origin 仍使用完整协议和端口。相关缓存、超时、身份保留及登录变化回归已通过,组合源码回归 2400 项通过;合并后会在真实仓库再次跑全量及 CI。本轮为替身验证,没有访问真实账号或复现平台风控。准备合并并带上补修,感谢贡献! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题一:whoami 失败不缓存,反复起浏览器触发平台 IP 风控
GET /api/accounts/{platform}/whoami的真校验(起 headless 浏览器,数秒)对成功结果有_WHOAMI_CACHE+WHOAMI_TTL,但失败路径(not confident)直接 raise 502、不写缓存。前端账号页 + 工作台开页都会调 whoami,于是每次开页都重新起浏览器访问平台。实测后果(自部署环境,2026-11-15)
POST /api/login/xiaohongshu连二维码都拿不到,账号无法绑定修复
失败结果同样写入
_WHOAMI_CACHE,带verifyError: true标记,WHOAMI_FAILURE_TTL = 120s短过期。不影响既有语义:_account_logged_in)变化时,既有的等式检查令缓存自动失效重验(绑号/退号即时生效)force=true仍绕过缓存(重试按钮语义不变)附带收益:缓存命中返回的
loggedIn取自持久化标记,风控期账号页显示「未绑定」而非 502 报错,控制台不再刷屏。问题二:
EASEL_EXTRA_HOSTS带端口时静默失效starlette
TrustedHostMiddleware.__call__按headers.get("host", "").split(":")[0](去端口)比对,而EASEL_EXTRA_HOSTS条目原样进allowed_hosts。用户按 URL 习惯写example.com:8443会永不匹配,所有反代请求一律 400Invalid host header,且没有任何提示。修复:读取环境变量时剥掉
:端口(EASEL_EXTRA_ORIGINS不动——Origin 本来就要带完整端口)。测试
python3 -m py_compile web/app.py通过