Android应用程序使用web视图/ JavaScript的。有什么方法可以安全问题?有什么、视图、安全问题、应用程序

2023-09-12 08:10:21 作者:阳光宅男

我使用 web视图 Javascript的制作 addJavascriptInterface(真正创造一个Android的Web应用程序)

我的应用程序将内容数据(HTML),将被从外部站点加载。

My App will content data(html) that will be loaded from an external site.

我担心的跨站脚本XSS /我的应用程序的安全性的,因为我使addJavascriptInterface(真)。

I worried about the cross-site-scripting XSS/security of my app as I am enabling addJavascriptInterface(true).

什么事情,我应该照顾,使任何恶意code不应该在我的应用程序运行?

What are the things I should be taking care so that any malicious code should not run on my app ?

推荐答案

有一个在web视图漏洞超过4.2时,您启用JavaScript 吧。

There is vulnerability in webview older than 4.2 when you Enable javascript for it.

使用中启用JavaScript的:

在启用JavaScript,您可以与您的应用程序code和你的JavaScript code创建界面。

Once JavaScript is enabled, you can create interfaces between your application code and your JavaScript code.

addJavascriptInterface(Object对象,字符串名称)方法:

该addJavascriptInterface方法注入所提供的Java对象到web视图。

The addJavascriptInterface method injects a supplied Java object into WebView.

的对象被注入到主框架的JavaScript的上下文中,使用所提供的名称,这允许Java对象的方法可从JavaScript访问。

The object is injected into the JavaScript context of the main frame, using a supplied name and this allows the Java object’s methods to be accessed from JavaScript.

有关运行Android 4.1或以上,所有公共方法(包括继承的)应用程序可以访问的,所以当用户安装的应用程序与addJavascriptInterface方法加载外部网页,它可以使用的WebView和JavaScript调用Java对象(如一的Javascript管道和反射调用其他任何未注册的Java类的使用),它允许攻击者调用Android的Java方法。

For applications running Android 4.1 or older, all public methods (including the inherited ones) can be accessed, so when a user’s installed application with addJavascriptInterface method loads an external webpage it can use WebView and javascript to call a java object (like a ‘Javascript pipeline’ and usage of reflection to invoke any other unregistered Java class) which allows attackers to call Android’s Java methods.

解决方法:

有关运行Android 4.2的所有公共方法的应用程序被注解为JavascriptInterface可以从JavaScript访问。

For applications running Android 4.2 all public methods that are annotated with JavascriptInterface can be accessed from JavaScript.

所以,如果你开发的SDK版本17或更高版本的应用程序,您必须添加@JavascriptInterface标注任何您想要提供给您的JavaScript方法。

So if you develop an application for SDK version 17 or higher, you must add the @JavascriptInterface annotation to any method that you want available to your JavaScript.

如果你没有提供的注释,在Android 4.2或更高版本上运行时的方法是不是由您的网页中。

If you do not provide the annotation, the method is not accessible by your web page when running on Android 4.2 or higher.

参考