BabelView: Evaluating the Impact of Code Injection Attacks in Mobile Webviews

Claudio Rizzo, Lorenzo Cavallaro, Johannes Kinder

Abstract

A Webview embeds a full-fledged browser in a mobile application and allows the application to expose a custom interface to JavaScript code. This is a popular technique to build so-called hybrid applications, but it circumvents the usual security model of the browser: any malicious JavaScript code injected into the Webview gains access to the interface and can use it to manipulate the device or exfiltrate sensitive data. In this paper, we present an approach to systematically evaluate the possible impact of code injection attacks against Webviews using static information flow analysis. Our key idea is that we can make reasoning about JavaScript semantics unnecessary by instrumenting the application with a model of possible attacker behavior -- the BabelView. We evaluate our approach on 11,648 apps from various Android marketplaces, finding 2,677 vulnerabilities in 1,663 apps. Taken together, the apps reported as vulnerable have over 835 million installations worldwide. We manually validated a random sample of 66 apps and estimate that our fully automated analysis achieves a precision of 90% at a recall of 66%.

Introduction

Modern mobile applications are increasingly "hybrid," utilizing Webviews to render content with HTML and JavaScript. To enhance functionality, developers often implement a "bridge"—a JavaScript interface that allows web-based code to invoke native Java methods. This bridge provides access to sensitive device features like the camera, contacts, or file system.

However, this architecture introduces a significant security risk by bypassing the standard browser sandbox. If an attacker successfully injects malicious JavaScript into a Webview—through insecure HTTP, malicious ads, or cross-site scripting (XSS)—they gain direct access to these native methods. While previous research could detect the existence of such interfaces, determining the actual security impact (i.e., what data could be stolen or what actions could be performed) required complex cross-language analysis that was often computationally prohibitive.

Conceptual flow of BabelView capturing data flows between the web and device domains.

Methodology: The BabelView Approach

BabelView addresses this challenge by abstracting away the complexity of JavaScript analysis. Instead of modeling specific script behaviors, it focuses entirely on the Java domain by assuming an attacker has full control over the interface.

Attacker Modeling and Instrumentation

The core of the approach is the BabelView class, a drop-in replacement for the standard Android WebView. Using the Soot framework, the tool automatically rewrites an application's bytecode to replace standard Webviews with this instrumented version.

The five-phase BabelView instrumentation and analysis pipeline.

The instrumentation follows a multi-phase process:

  1. Interface Analysis: Identifying the methods exposed to JavaScript.
  2. Generation and Instrumentation: Creating the BabelView model and injecting it into the APK.
  3. Simulated Interaction: The model non-deterministically calls every exposed method, passing "tainted" (potentially malicious) data as arguments and treating return values as potential data exfiltration points (sinks).
  4. Flow Analysis: The tool leverages FlowDroid to perform static information flow analysis. Because the attacker's behavior is now represented in Java, FlowDroid can track if tainted inputs reach sensitive APIs (e.g., sending an SMS) or if sensitive data (e.g., device IMEI) flows back to the attacker via the bridge.

Evaluation and Results

The researchers evaluated BabelView using a massive dataset from AndroZoo. Starting with over 200,000 apps, they filtered for those using Webviews with JavaScript interfaces and internet permissions. A deep-dive analysis was performed on 25,000 apps from the Google Play Store.

Key Findings

  • Widespread Vulnerability: Of the successfully analyzed apps, 4,997 (26.2%) were flagged as potentially dangerous, containing a total of 10,808 vulnerabilities.
  • Massive Impact: The vulnerable apps have a combined installation base exceeding 3 billion worldwide.
  • Common Attack Vectors: The most frequent vulnerabilities included unauthorized file system writes (1,444 apps), starting external applications (1,321 apps), and "Frame Confusion" (1,039 apps), which violates the Same-Origin Policy.
  • Performance and Accuracy: The analysis is highly efficient, averaging 180 seconds per app. Manual validation of a random sample demonstrated a precision of 81% and a recall of 89%.

Discussion and Limitations

BabelView demonstrates that the JavaScript-to-Java bridge is effectively a public API, often mistakenly treated by developers as a trusted private channel. By modeling the interface as a set of Java calls, the tool leverages mature security analysis techniques to identify "confused deputy" scenarios where an app performs unintended actions on behalf of an attacker.

Limitations

Despite its effectiveness, BabelView faces standard static analysis hurdles. It struggles with highly dynamic code involving heavy reflection, native C/C++ libraries, or dynamic class loading. Additionally, the current implementation is object-insensitive, which can lead to false positives, and it does not account for temporal dependencies in persistent storage (e.g., SharedPreferences), which may result in false negatives.

Future work suggests integrating BabelView into app store vetting processes, providing developers with immediate feedback to secure their hybrid application architectures before deployment.

Summary updated

Abstract

A Webview embeds a full-fledged browser in a mobile application and allows the application to expose a custom interface to JavaScript code. This is a popular technique to build so-called hybrid applications, but it circumvents the usual security model of the browser: any malicious JavaScript code injected into the Webview gains access to the interface and can use it to manipulate the device or exfiltrate sensitive data. In this paper, we present an approach to systematically evaluate the possible impact of code injection attacks against Webviews using static information flow analysis. Our key idea is that we can make reasoning about JavaScript semantics unnecessary by instrumenting the application with a model of possible attacker behavior -- the BabelView. We evaluate our approach on 11,648 apps from various Android marketplaces, finding 2,677 vulnerabilities in 1,663 apps. Taken together, the apps reported as vulnerable have over 835 million installations worldwide. We manually validated a random sample of 66 apps and estimate that our fully automated analysis achieves a precision of 90% at a recall of 66%.
BibTeX
@inproceedings{rizzo2018babelview,
  author = {Claudio Rizzo and Lorenzo Cavallaro and Johannes Kinder},
  title = {{BabelView: Evaluating the Impact of Code Injection Attacks in Mobile Webviews}},
  booktitle = {RAID},
  year = {2018},
  url = {https://openreview.net/forum?id=uOZSGzzTUxm},
}
Figure