我收到来自 Google Play 管理中心的警告,提示我 this page因为我在我的应用程序中使用了 JavaScript 接口(interface)并建议了两个选项来解决问题。
选项 1 告诉:
Ensure that there are no objects added to the JavaScript interface of any WebView that loads untrusted web content. You can do this in two ways:
Ensure that no objects are ever added to the JavaScript interface via calls to addJavascriptInterface.
Remove objects from the JavaScript interface in shouldInterceptRequest via removeJavascriptInterface before untrusted content is loaded by the WebView.
但我不明白 google 到底在什么地方特别说:
Remove objects from the JavaScript interface in shouldInterceptRequest via removeJavascriptInterface before untrusted content is loaded by the WebView
谁能告诉我更多的解释?
最佳答案
您可以通过以下方式解决此问题:
- 如果您的网站支持 HTTPS,请在 loadUrl 方法中使用“https://”前缀。
- 您可以在您的 list 中将 android:usesCleartextTraffic 设置为 false,或者设置一个不允许 HTTP 流量的网络安全配置。这也意味着您的网站应该在 HTTPS 上运行。
现在,关于“在 WebView 加载不受信任的内容之前通过 removeJavascriptInterface 从 shouldInterceptRequest 中的 JavaScript 接口(interface)中删除对象”的问题:这意味着您的应用程序应该删除(或禁用)JavaScriptInterface每当在 WebView 中加载任何非 HTTPS URL 时。
完成其中任何一项后,您需要在 Play 管理中心更新 APK。
结论是,如果你想使用 JavaScriptInterface,最好在你的网站上使用 HTTPS。如果您使用 HTTP,则 Google Play 将不允许使用 JavaScriptInterface。
关于android - JavaScript 接口(interface)注入(inject)漏洞修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53679624/