WebViews are used in android applications to load content and HTML pages within the application. Due to this functionality the implementation of WebView it must be secure in order not to introduce the application to great risk. The purpose of this article is to examine the things that will make WebView less secure and therefore the application itself. Both developers and penetration testers can use this article as a reference when conducting a mobile penetration test.

Loading Clear-Text Content

If WebView is allowing to load clear-text content from the Internet then it would be open to various forms of attack such as MiTM.


SSL Error Handling

The code below instructs the WebView client to proceed when an SSL error occur. This means that the application is vulnerable to MiTM attacks as it could allow an attacker to read or modify content that is displayed to the user since any certificate would be accepted by the application.

public void onReceivedSslError(WebView view, SslErrorHandler handler,
SslError error)

JavaScript Enabled

Allowing JavaScript content to be executed within the application via WebView might give the opportunity to an attacker to execute arbitrary JavaScript code in order to perform malicious actions. This setting allow WebView to execute JavaScript code.

WebSettings webSettings = myWebView.getSettings();

The JavascriptInterface function allows bridging between JavaScript code and native Java code. This means that JavaScript code can access and inject Java objects and Java code to be called by JavaScript. Depending on the permissions of the application this could allow an attacker to interact with the functionality of the device (read SMS, microphone recording etc.) exposing the security of the application and the device itself into great risk.

WebView webView = new WebView(this);
class JsObject {
private String sensitiveInformation;

public String toString() { return sensitiveInformation; }

webView.addJavascriptInterface(new JsObject(), "injectedObject");
webView.loadData("", "text/html", null);

Accessing Local Resources

If the WebView is allowing to access content from other applications that exist on the same device then it could be possible for an attacker to create a malicious html file that could be injected inside the target application through the use file:scheme. In order for this malicious file to be loaded needs to have world readable permissions.

public class MyBrowser extends Activity {
public void onCreate(Bundle savedInstanceState) {

WebView webView = (WebView) findViewById(R.id.webview);

// turn on javascript
WebSettings settings = webView.getSettings();

String turl = getIntent().getStringExtra("URL");


WebView due to it its functionality can expose the application and the device it great security risk. Mobile penetration testers should examine the following methods and  their status when conducting and an android assessment to identify associated risks.

  • setAllowContent Access
  • setAllowFileAccess
  • setAllowFileAccessFromFileURLs
  • setAllowUniversalAccessFromFileURLs
  • setJavaScriptEnabled


Code samples have been taken from the following websites:


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s