Spoof or remove X-Requested-With header from webview (#1812)

This commit is contained in:
AwkwardPeak7
2025-03-02 20:16:42 +05:00
committed by GitHub
parent b12ee027ea
commit 793d7fbe40
5 changed files with 73 additions and 16 deletions

View File

@@ -219,17 +219,15 @@ class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.Factor
try {
// Override the value passed as X-Requested-With in WebView requests
val stackTrace = Looper.getMainLooper().thread.stackTrace
val chromiumElement = stackTrace.find {
it.className.equals(
"org.chromium.base.BuildInfo",
ignoreCase = true,
)
}
if (chromiumElement?.methodName.equals("getAll", ignoreCase = true)) {
return WebViewUtil.SPOOF_PACKAGE_NAME
val isChromiumCall = stackTrace.any {
it.className.startsWith("org.chromium.") &&
it.methodName in setOf("getAll", "getPackageName", "<init>")
}
if (isChromiumCall) return WebViewUtil.spoofedPackageName(applicationContext)
} catch (_: Exception) {
}
return super.getPackageName()
}