Override X-Requested-With header value in WebView requests (closes #6781)
(cherry picked from commit 996f770935de78e6b0f4dfa13996c59f0f3dbac4) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/App.kt
This commit is contained in:
parent
4482ab4a68
commit
989119af17
@ -46,6 +46,7 @@ import eu.kanade.tachiyomi.network.NetworkHelper
|
|||||||
import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegate
|
import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegate
|
||||||
import eu.kanade.tachiyomi.util.preference.asImmediateFlow
|
import eu.kanade.tachiyomi.util.preference.asImmediateFlow
|
||||||
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil
|
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil
|
||||||
|
import eu.kanade.tachiyomi.util.system.WebViewUtil
|
||||||
import eu.kanade.tachiyomi.util.system.animatorDurationScale
|
import eu.kanade.tachiyomi.util.system.animatorDurationScale
|
||||||
import eu.kanade.tachiyomi.util.system.logcat
|
import eu.kanade.tachiyomi.util.system.logcat
|
||||||
import eu.kanade.tachiyomi.util.system.notification
|
import eu.kanade.tachiyomi.util.system.notification
|
||||||
@ -183,6 +184,23 @@ open class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getPackageName(): String {
|
||||||
|
try {
|
||||||
|
// Override the value passed as X-Requested-With in WebView requests
|
||||||
|
val stackTrace = Thread.currentThread().stackTrace
|
||||||
|
for (element in stackTrace) {
|
||||||
|
if ("org.chromium.base.BuildInfo".equals(element.className, ignoreCase = true)) {
|
||||||
|
if ("getAll".equals(element.methodName, ignoreCase = true)) {
|
||||||
|
return WebViewUtil.SPOOF_PACKAGE_NAME
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
|
return super.getPackageName()
|
||||||
|
}
|
||||||
|
|
||||||
protected open fun setupNotificationChannels() {
|
protected open fun setupNotificationChannels() {
|
||||||
try {
|
try {
|
||||||
Notifications.createChannels(this)
|
Notifications.createChannels(this)
|
||||||
|
@ -101,7 +101,6 @@ class CloudflareInterceptor(private val context: Context) : Interceptor {
|
|||||||
|
|
||||||
val origRequestUrl = request.url.toString()
|
val origRequestUrl = request.url.toString()
|
||||||
val headers = request.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }.toMutableMap()
|
val headers = request.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }.toMutableMap()
|
||||||
headers["X-Requested-With"] = WebViewUtil.REQUESTED_WITH
|
|
||||||
|
|
||||||
executor.execute {
|
executor.execute {
|
||||||
val webview = WebView(context)
|
val webview = WebView(context)
|
||||||
|
@ -105,7 +105,6 @@ class WebViewActivity : BaseActivity() {
|
|||||||
headers = source.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }.toMutableMap()
|
headers = source.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }.toMutableMap()
|
||||||
binding.webview.settings.userAgentString = source.headers["User-Agent"]
|
binding.webview.settings.userAgentString = source.headers["User-Agent"]
|
||||||
}
|
}
|
||||||
headers["X-Requested-With"] = WebViewUtil.REQUESTED_WITH
|
|
||||||
|
|
||||||
supportActionBar?.subtitle = url
|
supportActionBar?.subtitle = url
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import android.webkit.WebView
|
|||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
|
|
||||||
object WebViewUtil {
|
object WebViewUtil {
|
||||||
const val REQUESTED_WITH = "com.android.browser"
|
const val SPOOF_PACKAGE_NAME = "com.android.chrome"
|
||||||
|
|
||||||
const val MINIMUM_WEBVIEW_VERSION = 95
|
const val MINIMUM_WEBVIEW_VERSION = 95
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user