【问题标题】:Google Play warning: Your app contains a File-based XSS issue? JavaScript Enable = TrueGoogle Play 警告:您的应用包含基于文件的 XSS 问题? JavaScript 启用 = 真
【发布时间】:2018-06-11 06:03:17
【问题描述】:

我们最近收到了一封来自 google 的电子邮件,内容是关于我们在 google play store 上发布的应用程序。

以下是他们在邮件中声明的内容。

Hello Google Play Developer,

The apps listed at the end of this email have a WebView File-based Cross-Site Scripting issue which can allow a malicious network to access any file accessible to your app.

What's happening

One or more of your apps contain a File-based Cross-Site Scripting vulnerability that must be fixed. Please refer to the notice on your Play Console for the deadline to fix this vulnerability. After this deadline, updates to affected apps will be blocked if the vulnerability is still present. Your published APK version will remain unaffected.

Action required

WebViews with WebSettings that set either setAllowFileAccessFromFileURLs orsetAllowUniversalAccessFromFileURLs to true must not load any untrusted web content. This includes content from trusted domains that is loaded over HTTP. Malicious web content or networks can inject scripts to redirect the WebView to a malicious file and launch a Cross-Site Scripting attack to access private local files or cookies.

You should prevent this vulnerability in one of the following ways:

Ensure that WebViews do not have dangerous settings - You can update yourandroid:targetSdkVersion in your Manifest to be at least 16 to use safe default settings for WebView. Otherwise, you can callsetAllowFileAccessFromFileURLs(false) andsetAllowUniversalAccessFromFileURLs(false) to ensure that their WebViews are safe.
Ensure that WebViews cannot load file:// URLs or execute JavaScript - You can call setAllowFileAccess(false) to prevent WebViews with dangerous settings from loading file:// URLs or call setJavaScriptEnabled(false) to prevent WebViews with dangerous settings from executing JavaScript code.
Ensure that WebViews with dangerous settings not load untrusted web content - If a WebView needs to enable these dangerous settings, you must ensure that it does not load untrusted web content.
We recommend that you also ensure that WebViews with dangerous settings do not load web content over HTTP. You can set android:usesCleartextTraffic=false or set aNetwork Security Config that disallows HTTP traffic in your Manifest. Alternatively, you can ensure that any WebViews with dangerous settings do not load any URLs with HTTP schemes.

Lastly, you should also ensure that WebViews with dangerous settings do not load URLs obtained from untrusted sources.

Next steps

Update your app using the steps highlighted above.
Sign in to your Play Console and submit the updated version of your app.
Check back after five hours; we will show a warning message if the app hasn't been updated correctly.

现在的问题是我们实际上在我们的应用程序中加载了本地 html 文件,这需要一些 javascript 交互以及需要访问本地资源,因此我们必须保持以下权限为真。

callsetAllowFileAccessFromFileURLs(true)。 setAllowUniversalAccessFromFileURLs(false)。 setJavaScriptEnabled(true)。

对此有什么可能的解决方案以及如何安全地防止我的应用程序中的漏洞?

【问题讨论】:

  • 你有什么解决办法吗?
  • @MuhammadUmair 还没有,我们正计划与 Google 团队聊天,您是否遇到过同样的问题?
  • 是的,我已经解决了我发布答案的问题

标签: android webview xss android-security


【解决方案1】:

首先,如果您使用的是网页视图,请添加以下代码:

webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setInitialScale(1);
webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setBuiltInZoomControls(false);
webView.getSettings().setDisplayZoomControls(false);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setAllowFileAccess(true);

您还必须将以下代码添加到manifest.xml

<meta-data android:name="android.webkit.WebView.EnableSafeBrowsing"
            android:value="true" />

希望它能解决你的问题。

【讨论】:

  • 感谢您发布答案。想问一下您是否收到了来自 google 的相同消息?因为我没有看到 callsetAllowFileAccessFromFileURLs(true) 的任何变化。 setAllowUniversalAccessFromFileURLs(false)。 setJavaScriptEnabled(true).
  • 是的,我收到了同样的错误。通过在清单中添加元数据,问题得到了解决。试试看。
  • 我不清楚第一个代码块的许多行的目的。也许这是从您的特定解决方案中复制的? meta-data 虽然看起来很合理,但我发现推荐它的消息来源在 2021 年仍然有效 developer.android.com/guide/webapps/managing-webview
猜你喜欢
  • 1970-01-01
  • 2019-04-05
  • 2020-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-21
  • 2017-07-03
  • 2011-08-26
相关资源
最近更新 更多