From 7551941ef22b6dda64f532e89ade19a8148cad13 Mon Sep 17 00:00:00 2001 From: DitFranXX <45893338+DitFranXX@users.noreply.github.com> Date: Sat, 23 Mar 2019 03:25:21 +0900 Subject: [PATCH] [Cloudflare] Fix recent CF JS Challenge error that calls DOM (#1919) * [Cloudflare] Fix recent CF JS Challenge error that calls DOM * Replace `atob` to pure js version. (was node.js API which invalid) * Use `atob` as native function `Base64.decode()`` * Use okio Base64 decoder instead of Android one. --- .../network/CloudflareInterceptor.kt | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt index 7c432f4294..641cdd9602 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt @@ -14,8 +14,20 @@ class CloudflareInterceptor : Interceptor { private val sPattern = Regex("""name="s" value="([^"]+)""") + private val kPattern = Regex("""k\s+=\s+'([^']+)';""") + private val serverCheck = arrayOf("cloudflare-nginx", "cloudflare") + private interface IBase64 { + fun decode(input: String): String + } + + private val b64: IBase64 = object : IBase64 { + override fun decode(input: String): String { + return okio.ByteString.decodeBase64(input)!!.utf8() + } + } + @Synchronized override fun intercept(chain: Interceptor.Chain): Response { val response = chain.proceed(chain.request()) @@ -49,17 +61,28 @@ class CloudflareInterceptor : Interceptor { val pass = passPattern.find(content)?.groups?.get(1)?.value val s = sPattern.find(content)?.groups?.get(1)?.value + // If `k` is null, it uses old methods. + val k = kPattern.find(content)?.groups?.get(1)?.value ?: "" + val innerHTMLValue = Regex("""