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

Claudio Rizzo, Lorenzo Cavallaro, Johannes Kinder

TL;DR

BabelView is a novel static analysis tool that evaluates the security impact of code injection attacks on Android Webviews. By instrumenting applications with a "BabelView" model that simulates malicious JavaScript behavior directly in the Java domain, the researchers identified over 10,000 potential vulnerabilities across apps with a combined 3 billion installations.

What Problem Does This Paper Address?

Modern mobile applications are often "hybrid," meaning they embed a web browser component called a Webview to display content using HTML and JavaScript. To provide a seamless experience, developers often create a "bridge"—a JavaScript interface—that allows web code to call native Java methods (e.g., to access the camera, contacts, or file system).

The problem is that this bridge bypasses the standard browser security model. If an attacker can inject malicious JavaScript into that Webview (via an insecure HTTP connection, a malicious advertisement, or a cross-site scripting flaw), they gain direct access to those native Java methods. Previous research could identify that an interface existed, but it couldn't easily determine the impact—exactly what sensitive data an attacker could steal or what damage they could do—without performing prohibitively expensive cross-language analysis.

Methods

The authors introduce BabelView, which sidesteps the complexity of analyzing JavaScript by focusing entirely on the Java side.

  1. Attacker Modeling: Instead of trying to reason about what a specific piece of JavaScript does, they assume the attacker has full control. They create a "BabelView" class—a drop-in replacement for the standard Android WebView.
  2. Instrumentation: Using the Soot framework, they automatically rewrite the target app's bytecode, replacing standard Webviews with their BabelView.
  3. Simulated Interaction: The BabelView contains a model (Algorithm 1) that non-deterministically calls every method exposed to the JavaScript interface. It passes "tainted" (potentially malicious) data into these methods and treats their return values as "sinks" (places where data could be exfiltrated).
  4. Taint Analysis: They then run FlowDroid, a state-of-the-art static information flow analysis tool, on the instrumented app. Because the attacker's behavior is now modeled in Java, FlowDroid can track if "tainted" input from the bridge reaches a sensitive API (like sending an SMS) or if sensitive data (like an IMEI) flows back through the bridge to the attacker.

Datasets

The researchers pulled a massive sample from AndroZoo, a well-known repository of Android APKs.

  • Initial Filter: They started with a random subset of 209,069 apps.
  • Target Set: They filtered for apps that used Webviews, had a JavaScript interface, and requested Internet permissions, resulting in 62,674 apps.
  • Final Evaluation: They randomly selected 25,000 apps from the Google Play Store for their deep dive.
  • Validation: They manually reversed and decompiled a random sample of 50 apps to verify the tool's accuracy.

Key Insights and Ideas

  • Language Abstraction: The "aha moment" is realizing that you don't need to analyze JavaScript to find JavaScript-based vulnerabilities. By modeling the interface as a non-deterministic set of Java calls, you can leverage mature Java-based security tools.
  • The "Bridge" is a Public API: Developers often treat the JS-to-Java bridge as a private, trusted channel. The paper demonstrates it is effectively a public API that any man-in-the-middle or malicious script can call.
  • Prevalence of Risk: The study highlights that even if an app isn't "malicious," a poorly designed interface makes it a "confused deputy" that an attacker can use to perform actions the user never intended.

Key Results

  • Scale of Vulnerability: Out of the ~20,000 successfully analyzed apps, 4,997 (26.2%) were flagged as dangerous.
  • Total Flaws: The tool found 10,808 potential vulnerabilities. These apps have been installed more than 3 billion times worldwide.
  • Common Alarms: The most frequent issues involved writing to the file system (1,444 apps), starting other applications (1,321 apps), and "Frame Confusion" (1,039 apps) which violates the Same-Origin Policy.
  • Performance: The analysis is efficient, taking an average of 180 seconds per app.
  • Accuracy: Manual validation showed a precision of 81% and a recall of 89%.

Limitations and Future Work

  • Static Analysis Hurdles: Like all static analysis, BabelView struggles with highly dynamic code, such as apps that use heavy reflection, native code (C/C++), or dynamic class loading to hide their logic.
  • Object Insensitivity: The current implementation doesn't distinguish between different instances of the same Webview type, which can lead to some false positives.
  • Temporal Dependencies: The tool doesn't account for the order in which data is stored and retrieved in persistent storage (like SharedPreferences) across different app sessions, which could lead to false negatives.
  • Future Direction: The authors suggest that BabelView could be integrated into app store vetting processes to provide developers with immediate feedback on insecure interface designs before their apps reach millions of users.

Summary updated

Abstract

A Webview embeds a fully-fledged browser in a mobile application and allows that 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 custom 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 25,000 apps from various Android marketplaces, finding 10,808 potential vulnerabilities in 4,997 apps. Taken together, the apps reported as problematic have over 3 billion installations worldwide. We manually validate a random sample of 50 apps and estimate that our fully automated analysis achieves a precision of 81% at a recall of 89%.
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},
}

Loading related content...

Figure