Android WebView评估Javascript,如何安全?

发布于 2025-01-18 05:11:52 字数 781 浏览 3 评论 0原文

我必须通过我的 WebView 向 Web 发送一些消息。 我找到了这样的方法:

将数据从native层发送到Webview。在中创建一个函数 JavaScript 用于接收 Html 中的数据。这将更新 inputField 收到的值。

function updateFromNative(message){
       document.getElementById("inputField").value = message;
  }
<input id="inputField" style="height:50px;width:300px;font-size:20pt;" type="text" value="">

现在,从本机层,我们可以通过以下方式访问此函数。

private fun sendDataToWebView(){
    mWebViewComponent.evaluateJavascript(
        "javascript: " + "updateFromNative(\"" + mEditText.text +  
                                                       "\")",null)
    }

这对我来说工作得很好。但我担心这种方法的安全性。 有人可以通过这种方式使用这种方式来阻止应用程序数据或任何其他漏洞。

如果有人给我一些有关它的信息,我会很高兴。

I have to send some messages to Web through my WebView.
I've found approach like this:

To send data from native layer to Webview. Create a function in
JavaScript to receive data in Html. Which will update inputField with
the value received.

function updateFromNative(message){
       document.getElementById("inputField").value = message;
  }
<input id="inputField" style="height:50px;width:300px;font-size:20pt;" type="text" value="">

Now from native layer, we can access this function by the following.

private fun sendDataToWebView(){
    mWebViewComponent.evaluateJavascript(
        "javascript: " + "updateFromNative(\"" + mEditText.text +  
                                                       "\")",null)
    }

It's work for me quite well. But I'm worried about security of this method.
Can somebody this way to use this way to still app data or any other vulnerabilities.

I would be happy if somebody take me some information about it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清晰传感 2025-01-25 05:11:52

根据您的方案,如果您使用它来发送/接收重要数据,则这种方式是不安全的,因为黑客可以清楚地看到您的数据,并且可以编辑它。另外,您可以进行通信的RSA加密层

Depending on your scenario, if you use it to send/receive important data, this way is unsafe because hackers can see your data clearly and it can edit it. also, you can RSA encryption layer for communication

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文