fix(multi.kagane): work around Cloudflare challenge on all API routes - #679
fix(multi.kagane): work around Cloudflare challenge on all API routes#679CtrlAltElite97 wants to merge 10 commits into
Conversation
kkantan
left a comment
There was a problem hiding this comment.
I think we have seen with other sources doing this that this is not a good solution. the while loop eval to wait for an async result leads to deadlocks in the app. at the very least, we would want to use the async eval api (though it appears to be broken current, so we would need to wait until it is fixed). however, having to spawn a web view and run all this js for requests is not a good solution regardless, since I believe things like rakuyomi don't support it.
the cf_clearance cookie not being given to the source after passing cloudflare with the app sounds like an app issue to me. is kagane handling cloudflare in a special way, or does this need to be reported to aidoku?
Thanks for the review. The Cloudflare challenge is site-wide rather than page-specific. If I open kagane.to in a fresh browser session, it clears itself after a few seconds without any interaction. Once that's done, everything the source uses, including search, series pages, covers, and the chapter API, works fine for the rest of that session. So the idea of solving it once and then reusing that session is valid. I also looked into whether we could solve the challenge once and then make normal requests using the clearance cookie instead of routing everything through the web view. Unfortunately, that doesn't seem possible. The cf_clearance cookie is intentionally inaccessible to JavaScript, and as far as I can tell there's no way to retrieve it through Aidoku's current source API either. Given those limitations, keeping requests inside the web view isn't really a design choice. It's the only approach that's currently possible. As for the busy-wait loop, I agree that's not something we should merge as-is. I've been experimenting with replacing it using the web view's async APIs instead of polling in a loop, but I haven't verified that implementation yet. I didn't want to push something untested, so I'll update the PR once I have a solution I'm confident in. |
|
It is funny because the internal webview and the safari doesn’t work for me. But the aidoku app works. |
|
If you want to do this, make an option for opt-in because the invisible webview cannot solve captcha. That will prevent some people from using it. Of course cf challenges changes for everyone so some can, some cannot. Best to be optional so everyone can use it. |
|
@CtrlAltElite97 Have you tried clearing source cache? I did play around a bit switching between my mobile carrier and wifi. The error would continue to persist until I clear the cache to reset all cookies. Of course to trigger the webview, you had to click retry once. |
Did everything you mentioned resulting in no success which let me to this PR |


Problem
Why the simple fix doesn't work
Changes
Testing
Known tradeoff