Skip to content

修复在有nhentai账号的情况下,验证cf时cookie 同步失败导致无限循环的bug#273

Open
FC383 wants to merge 2 commits into
Pacalini:masterfrom
FC383:fix-nhentai-Cloudflare
Open

修复在有nhentai账号的情况下,验证cf时cookie 同步失败导致无限循环的bug#273
FC383 wants to merge 2 commits into
Pacalini:masterfrom
FC383:fix-nhentai-Cloudflare

Conversation

@FC383

@FC383 FC383 commented May 24, 2026

Copy link
Copy Markdown

##问题
nhentai 触发 CF 验证时,用户点击「继续」进入 WebView 后,自动弹出.

##根因
passCloudflare() 中检测 CF 验证成功的机制有两层缺陷:

  1. cookie 保存的触发条件错误:Desktop/Mobile 均以验证失败作为 cookie 保存的触发条件,验证成功时反而跳过。
  2. 检测目标错误(根本原因):检测对象为 DOM 元素 #challenge-success-text,该元素仅存在于 CF 验证通过的瞬时过渡页(<1 秒),而 onTitleChange 触发时页面已重定向到真实的 nhentai 页面,元素已消失,永远检测不到。
  3. Mobile onStarted 在 WebView 刚创建时无条件保存 cookie,此时 CF 页面未加载,拿不到 cf_clearance。

##修复
将检测机制从脆弱的 DOM 元素改为 Cloudflare 标准 cookie cf_clearance,该 cookie 在 CF 验证通过后持久存在于 WebView 的 cookie store 中。

位置 改动概述
Desktop onTitleChange 将检测方式从 JS 查询 DOM 元素 #challenge-success-text 改为直接检查 WebView cookie store 中是否存在 cf_clearance,同时删除 if 块内冗余的二次 cookie 检查
Mobile onTitleChange 同上
Mobile onStarted 将无条件 saveCookies 改为仅在 cf_clearance 存在时才保存,作为二次进入 WebView 时的快速同步路径

选择 cf_clearance 作为检测目标的理由:它是 Cloudflare 标准验证 cookie,验证通过后跨页面持久存在,不受页面重定向影响,且二次进入 WebView 时可直接命中。

FC383 added 2 commits May 24, 2026 23:05
上个修改:如果cf cookie过期,则会退出

###修复方案
一处 — Desktop onTitleChange
将「JS 查 DOM 元素判断成功」改为「先查 cookie 是否存在,再查页面是否为 CF 挑战页」:

getCookies 检查 cf_clearance 是否存在
evaluateJavascript 检查 typeof _cf_chl_opt !== 'undefined' 确认不在挑战页
两项都通过 → 保存 cookie + 关闭 WebView + 触发重试
二处 — Mobile onTitleChange
同上,JS 返回值类型适配为 Dart bool。

三处 — Mobile onStarted
回归为仅保存 UA。cookie 检测逻辑统一放在 onTitleChange 中处理,避免 onStarted 阶段页面未渲染导致 _cf_chl_opt 检查不可靠。
@FC383

FC383 commented May 24, 2026

Copy link
Copy Markdown
Author

等cookie过期后再测试一次
测试通过

@FC383 FC383 changed the title nhentai Cloudflare 验证通过后 cookie 同步失败导致无限循环 修复在有nhentai账号的情况下,验证cf时cookie 同步失败导致无限循环的bug May 24, 2026
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