Android WebView评估Javascript,如何安全?
我必须通过我的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的方案,如果您使用它来发送/接收重要数据,则这种方式是不安全的,因为黑客可以清楚地看到您的数据,并且可以编辑它。另外,您可以进行通信的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