android - JavaScript 接口(interface)注入(inject)漏洞修复

标签 android webview android-webview google-play-console

我收到来自 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

谁能告诉我更多的解释?

最佳答案

您可以通过以下方式解决此问题:

  1. 如果您的网站支持 HTTPS,请在 loadUrl 方法中使用“https://”前缀。
  2. 您可以在您的 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/

相关文章:

android - anchor 导航不适用于三星 Android 设备

android - 如何保存和恢复android WebView的WebBackForwardList?

java - 如何隐藏或删除 Android HoneyComb 中的状态栏?

安卓 & SDL : "called unimplemented OpenGL ES API"

ios - 带有 uiwebview swift 的 Gif

ios - 如何在 searchBar 中设置 http 不区分大小写?

Android WebView,如何在应用程序中处理重定向而不是打开浏览器

android - 如何更改列表 simple_list_item_multiple_choice 中的颜色

android - 如何更改 MPAndroidchart 中 Y 轴标签的间距?

android - 网页 View 不缓存