Recently, I need to detect the source code of a web page. There is no direct interface to obtain the source code of the web page in Android Webview. The traditional addJavascriptInterface method has security risks, so I studied the security interaction between Java and Javascript. Android Webview Vulnerability Android Webview has two very well-known vulnerabilities:
Safe interaction between Java and Javascript First of all, a few points: 1. It is easy to call Js methods from Java in Android Webview. loadUrl("javascript:isOk()") can call the isOk Js method, but the return result of the Js method cannot be directly obtained.
2. In the traditional method, Js can obtain Java information in the following ways:
3. When there is a hyperlink jump in the web page, the shouldOverrideUrlLoading method of WebClient will be called. If WebViewClient is set and the method returns true, it means that the URL is processed by the application code and WebView does not, which can achieve the effect of intercepting the jump. Understanding the above points, we can summarize a relatively safe way for Java and Js to interact : We can learn from the idea of Android Intent. Java and Js define a URL format such as js://_. Java calls the Js method. In the Js method, window.location.href='js://_?key=value#key1=value1' is used to simulate the jump. It is captured by Java's shouldOverrideUrlLoading. The return value of the function can be placed in the URL parameter. (The principle of Js calling Java methods is the same) This interaction method is asynchronous. What if you want to know whether calling a Js method returns a value? Generally, Java calls the Js method in the onPageFinished method, and obtains the Js return value in the shouldOverrideUrlLoading method. The two methods have a common parameter webview, so you can first call webview.setTag(false). If the return result is captured, then call webview.setTag(true). After a short time, such as 300 milliseconds, call webview.getTag() to check whether there is any change. |
<<: Changsi Advertising won the "Golden Coordinate" 2014 Best Mobile Advertising Platform Award
>>: Which three “mobile industry chains” has WeChat created?
How much is the quotation for Zhengzhou aquatic p...
In conclusion: In the current popular "crazy...
This article mainly introduces how to check orders...
A product is like a traffic pool, with fresh bloo...
The main tasks of user operations include: user a...
On March 20, the Cannes Film Festival officially ...
Question 1: How do you evaluate the effectiveness...
In the past two years, mobile advertising has bro...
Soft content marketing is the most common and eff...
During this year's National Day, NetEase main...
Fission, a popular Internet marketing term in 201...
Food lovers must have a love-hate relationship wi...
The moment the hot topic came, it seemed that eve...
In the channel promotion of App, there are many f...
From reading articles, to looking at pictures, to...