Abstract
In hybrid mobile applications (apps), the core code of an app is in JavaScript. Any JavaScript code in a hybrid app, local or remote, can access available APIs, including JavaScript bridges provided by a hybrid development framework, to access device resources. This JavaScript inclusion capability is dangerous since there is no mechanism to determine the origin (party) of the code to control access. Moreover, any JavaScript code running in a mobile app can access the device resources through the exposed APIs. Previous solutions are either limited to a particular platform (e.g., Android) or a specific hybrid framework (e.g., Cordova) or only protect the device resources and disregard the sensitive elements in the web environment. Furthermore, most solutions require modification of the base platform.
In this article, we propose a novel policy enforcement framework to enforce useful fine-grained security and privacy policies based on permission for each party in hybrid mobile apps. In contrast to the conventional permission model in mobile apps, our permission specification is platform-agnostic and context-aware. This new permission specification allows app developers to customize for different parties over single permission. We integrate our permission specification into an app at the development phase; however, by design, it allows end-users to adjust parameters at runtime to protect their privacy. Together with multi-party permission patterns, we introduce comprehensive classes of expensive fine-grained, stateful policies that developers can deploy in practice. These policy patterns can help to protect the privacy of users and can also mitigate significant types of potential attacks in hybrid apps, evidenced by our real-world evaluation. Our experimental results also demonstrate that the framework is compatible with various hybrid development frameworks over two major mobile platforms, with lightweight overhead.
Introduction
Hybrid mobile application (app) development is a technology for developing mobile apps using web technologies (i.e., HTML, CSS, and JavaScript), thanks to the portability of the web [20,65]. In hybrid mobile apps, developers write the core business code in webpages using JavaScript, HTML, and CSS, instead of a platform-specific language such as Java for Android. Typically, developers use a middle-tier development framework such as Cordova (https://cordova.apache.org/) to integrate this web code into a native mobile app for a specific platform, e.g., Android or iOS, automatically. These types of mobile apps are known as hybrid mobile apps, as they contain both web code (written by developers) and platform-specific code (typically generated by a hybrid development framework) [29,31].
Hybrid frameworks typically provide JavaScript “bridge” APIs to allow hybrid mobile apps, i.e., the business JavaScript code, to interact with the native code to access device resources such as geolocation, contact lists, SMS, and others. While this execution model provides advantages for developers, it, however, exacerbates the security issues of hybrid mobile apps compared to native apps. One security challenge is that the permission model in mobile platforms (i.e., grant all or nothing) is too coarse-grained to prevent the misuse of these JavaScript bridges. In addition, while built-in security mechanisms such as same-origin policy, content security policy, or domain whitelisting can prevent web-based vulnerabilities such as cross-siting scripting attacks, these mechanisms fail to prevent potential malicious behaviors from whitelisted third-party code (cf. Section 2.3 for detailed discussions). For example, third-party advertisement JavaScript code embedded in a hybrid mobile app can access granted resources through available JavaScript bridges without any limitations [83].
There have been several efforts in the literature to provide security solutions for hybrid mobile apps, these proposals, however, face one or several limitations. For example, some solutions, e.g., [26,83], focus on a specific platform (e.g.,
Motivated by the above limitations, our work aims to provide a robust and extensible policy enforcement framework for hybrid mobile apps that can fill the gaps in the state-of-the-art as previously discussed. In preliminary work [67], we propose HybridGuard, a framework that allows developers to define flexible permissions and fine-grained policies for different parties within a hybrid app. As a reference monitor implemented in the web environment, our framework can enforce policies at runtime to control the behavior of the code so that it can prevent potential attacks and resource abuses. The multi-party permission and fine-grained policy enforcement mechanism advance the current “all-or-nothing” permission model in mobile platforms and complement basic security features provided by the hybrid framework and the embedded web browser. We leverage JSON (JavaScript Object Notation), a textual structural specification, to design our multi-party and usage control permissions. We implement the enforcement code in JavaScript, independently and separately from the policy specification. The policy specification and enforcement code are embedded into an app at the web layer with minimal instrumentation of the original index HTML page to load and execute external JavaScript code. Our approach requires developers to mark JavaScript code from each party under a label (we define as “principal”). By doing so, the code from each party can be precisely monitored and enforced at runtime by the policies for that particular party to ensure its security. In this article, we have made significant extensions to HybridGuard [67] with the following new contributions:
We extend the specification of multi-party permissions and policies to support user-centric usage control to protect users’ privacy. We present practical permission and policy patterns that developers can deploy in hybrid mobile apps to prevent potential real-world attacks and privacy violations.
We implement a proof-of-concept prototype that stores the pre-defined policy templates permanently in local storage. This mechanism ensures that policy states can be updated persistently. It also supports the customization of policies, i.e., end-users can personalize the policy parameters at the installation or runtime.
We perform significant evaluations and report practical experimental results on various aspects. Our framework is platform-agnostic as it is compatible with various hybrid app development frameworks and two major mobile platforms (Android and iOS). We show that practical policies can soundly prevent attack scenarios while posing lightweight overhead. We demonstrate that our framework is also applicable to real-world hybrid mobile apps.
We organize the rest of this article as follows. In the next section, we describe the background of this work, including the hybrid mobile app architecture, motivating attack scenarios, existing security mechanisms in hybrid mobile apps, and the threat model. We survey the literature and discuss related work compared with ours in Section 3. In Section 4, we present our design of the framework, and we describe our specification of multi-party, fine-grained permissions, and policies in Section 4.2. We describe our prototype implementation in Section 5 and introduce a wide range of policy patterns and templates in Section 6. In Section 7, we demonstrate the evaluation and discuss the experimental results. Section 8 concludes our contributions and discusses future work.
Background
In this section, we first give an overview of the hybrid mobile application architecture. We then present four motivating attack scenarios that motivate HybridGuard’s design and implementation, and that we use as running examples throughout the rest of the paper. Next, we describe existing security mechanisms available for hybrid mobile apps, while outlining why these do not provide robust security protection against our motivating attack examples. Finally, we conclude with a description of the threat model we use for our HybridGuard framework.
Hybrid mobile application architecture
Originally, hybrid mobile applications (apps) are cross-platform mobile apps where the core business logic of apps is developed using web technologies (i.e., with HTML, CSS, and JavaScript) [29,31]. In recent years, there is another type of hybrid mobile apps that are not based on the web but developed in a programming language that differs from the mobile platform, e.g., C# in Xamarin [54]. In both types of hybrid mobile apps, after developing an app, developers use a hybrid mobile app development framework to pack the core code into a native app for a particular mobile platform. This technology and approach allow hybrid mobile apps to be write-once-run-anywhere, i.e., on different platforms such as Android and iOS. Hybrid mobile app development, therefore, saves substantial time and resources required to develop different versions of the same app on a specific platform [17].
In this work, we consider the original type of hybrid mobile apps, i.e., web-based hybrid mobile apps. In this type of hybrid mobile apps, Apache Cordova/PhoneGap [9] is the first development framework [86] and was the most prominent framework for building hybrid mobile apps in the past [29]. Many other popular frameworks based on Cordova such as PhoneGap [1], Ionic [52], Onsen UI [63], Framework7 [38], Sencha Touch [32], Intel XDK [35], and others are used in practice [9,17,78]. There have also been many new web-based hybrid app development frameworks that have emerged in the past few years, such as React Native [23], NativeScript [72], jQuery Mobile [79], Mobile Angular UI [21], Touchstone.js [81], to name just a few [17,78]. With those frameworks and the advent of near desktop-quality smartphones, web-based hybrid mobile apps are almost at par with native apps across the dimensions of performance, UI design, and development support tools [20,43]. These advantages result from significant improvements achieved in the performance of JavaScript engines in mobile platforms [49,65].
Figure 1 describes the basic architecture of a hybrid mobile app where the embedded web browser is a container to render the web content. As a webpage, the web content in a hybrid app can include local web code, remote web code located on the app’s web server, and third-party web code, such as ad syndicator scripts or other external JavaScript code. The mobile platform provides an infrastructure via the bridge code – a combination of web APIs and native APIs, for the embedded web content to communicate with device resources, such as a microphone, camera, contact list, and others. For example,

Architecture of hybrid mobile apps.
Scenario #1: Abusing device resources. Consider a hybrid mobile app that requires access to SMS and Contacts. By default, after a user grants the required permissions (could be at installation or run time), any JavaScript code running inside the application has access to these device resources [11]. If third-party JavaScript code included by the developer is infected with malicious code controlled by an attacker, the malicious code can access all the granted resources. For example, the malicious code can send bulk spam SMS messages to the user’s contacts or random numbers.
Scenario #2: Malvertisement and sensitive information leakage. Most free apps display in-app ads [19] to generate revenue through clicks and referrals. These ad services have an extensive screening process for supplied ads; however, the process is not airtight [92], as there have been many incidents of malicious ads in the past. These malicious ads reach users’ devices by either slipping through the screening process or by compromising the ad network [27,30,39]. This phenomenon is known as malvertising [75]. The malicious JavaScript in the ad can access the user’s sensitive information that may be available on the host page, such as Photo Gallery, File Storage or other personal information. Malicious JavaScript code in an ad with access to SMS and Email APIs, can use these channels to leak the stolen sensitive information.
Scenario #3: UI redress attacks. UI redress attacks are also known as clickjacking on the web or touchjacking/tapjacking on smartphones [64,73]. Malicious code can manipulate the DOM of the host page, including the creation of new elements or the modification of existing ones. Leveraging this ability, malicious JavaScript code in a hybrid app can launch such attacks by creating an invisible interface, such as an invisible
Scenario #4: Overusage of resources. A rogue third-party JavaScript with unlimited access to granted device resources, such as geolocation, can constantly monitor the current location of a user in real-time by hooking the
Existing security mechanisms in hybrid mobile apps
In this subsection, we review existing security mechanisms in hybrid mobile apps. These mechanisms are either provided by a hybrid app framework, the embedded browser, or the underlying OS. We outline the advantages of each, but also describe why they are incapable of adequately protecting against the attack scenarios outlined in the previous subsection, thus motivating the need for a tool such as HybridGuard. For a detailed discussion of related work that proposes security techniques for protecting various security issues in hybrid mobile apps, we refer readers to Section 3.
Domain whitelisting. Some frameworks, such as Cordova, Ionic, React Native and Onsen UI, provide domain whitelisting, a security mechanism where developers can configure a security policy to define which external domains the
Same-Origin Policy (SOP). An origin is defined by the scheme, host, and port number of a URL [15]; two URLs have the same origin if they have the same scheme, host, and port number (if specified). The SOP is a web security policy that restricts how a document or script loaded from one origin can interact with a resource from another origin. For example, if an app’s web content includes an
Content-Security-Policy (CSP). CSP is a native browser capability that allows developers to control, at a granular level, exactly what content an app can access [56]. CSP is applied at page level either through the Content-Security-Policy HTTP header [57] or through the HTML
OS-level permissions. Both Android and iOS implement permission-based access control, where an app is granted permission to access a resource at runtime [8,12]. The resources that can be accessed are limited to the set of resources requested by the developer for the correct functioning of the app. Each app is limited to accessing resources within the scope of this permission set. However, once the permission to access the resource has been granted, the OS has no control over how the app uses this permission. Although the OS level permission model is critical in preserving the privacy of a user by restricting malicious content in an app from accessing sensitive device resources, it is too coarse-grained. The OS-level permissions fail to protect against any attack scenario discussed in Section 2.2.
HybridGuard threat model
In this work, we consider scenarios where hybrid mobile apps are legitimate and trusted by users. We assume that hybrid app developers configure Content-Security-Policy (CSP) to prevent code injection attacks [36]. The in-scope threats originate from whitelisted third-party JavaScript code that developers allow in CSP for app functionality. However, once included in the apps, third-party JavaScript code has the same privilege as the first-party code, and developers have no mechanism to control its behavior. In this threat model, the third-party JavaScript code could be (1) benign but under the control of an attacker through web application attacks, such as SQL injection, or network attack on the third-party server; (2) malicious by intentions; it lures developers by its appealing functionalities.
Related work
In this section, we survey and discuss recent work that is most closely related to our approach. We categorize the related work into three subsections as follows.
Third-party JavaScript isolation
Numerous solutions in the literature provide protection against malicious third-party JavaScript [2,34,46–48,53,58,60,66,68,69,82,84]. However, the existing solutions do not capture the phone-related attack channels, such as SMS, Wi-Fi, Bluetooth, Contacts and other. Due to this, adapting these solutions to the hybrid mobile app environment is not a trivial task and requires significant modification to the existing proposals.
Furthermore, none of these solutions provides multi-party or principal-based permission for hybrid mobile apps, as we propose in HybridGuard. JaTE [82] supports the isolation of third-party JavaScript with labels using
Adjail [46] and Webjail [84] use
Fine-grained policy enforcement in mobile apps
There are various efforts to define and enforce fine-grained policies for mobile apps in general. For example, ConSpec [3] is an automata-based policy specification. ConSpec can specify and enforce both user policies, e.g., users may want to limit the number of SMSs sent from an app, and application contracts, i.e., policies that govern an app’s security-relevant behaviors. However, ConSpec targets type-safe byte-code languages only, which implies that unlike HybridGuard, it cannot monitor or enforce policies on JavaScript, a language that is not type-safe. LoPSiL [44] is another policy specification language that can specify and enforce location-dependent security and privacy policies for mobile apps. A sample privacy-based access-control policy in LoPSiL is constraining an app’s ability to read location data at specific times. HybridGuard is capable of enforcing a much more extensive range of policies, as presented in Section 6.
There are other mechanisms to enforce fine-grained policies for mobile apps; however, they are specific to the Android platform and require the modification of the Android OS. For example, AppGuard [13] is capable of enforcing user-customizable policies on untrusted apps by modifying the apps. AppGuard can enforce fine-grained policies such as the possibility of specifying a set of servers an app is allowed to contact over the Internet. Secure Application INTeraction (Saint) [62] is another access-control system that can enforce both installation time permission granting policies and run time inter-application communication policies. FlaskDroid [18] is another security framework that works simultaneously on both Android’s middleware and kernel layers to enforce access-control policies. Apex [61] introduces a user-centric policy specification technique by extending Android permissions with run time constraints with only two parameters: the number of times, and the time of the day.
In [33], Imamura et al. propose a web access monitoring mechanism that can monitor all web access via WebView on Android. This mechanism does not require any modification of the Android Framework or the Linux kernel and can be introduced by just replacing WebView with a modified version. However, it cannot protect against attacks that originate from third-party JavaScript like HybridGuard does.
Hybrid mobile application security
In subsection, we discuss the related work in the field of hybrid mobile app security. We classify these solutions into three subcategories as follows.
Access control systems/frameworks
Many proposals introduce access control mechanisms for hybrid mobile apps. The closest related work to HybridGuard is PhoneWrap [24], which enforces fine-grained ticket-based policies for hybrid mobile apps. These ticket-based policies ensure a limited number of resource accesses based on the user’s interaction with the app. Resource accesses through JavaScript interfaces are wrapped by a library, inspired by the “self-protecting JavaScript” approach [69]. However, PhoneWrap excludes a multi-party scenario and cannot enforce separate policies for different origins, as proposed in our work. POWERGATE [26] allows developers to define origin-based access control policies similar to our HybridGuard. However, POWERGATE only protects native objects and relies on the web-browser to protect DOM objects. Also, its implementation requires modification of the base system, such as Firefox OS. In contrast, HybridGuard can enforce policies on both bridge APIs and DOM objects to prevent unauthorized access. In [77], the authors introduce a context-aware permission control system for hybrid mobile apps. This system aims to enforce information flow policies to prevent potential data leakage. However, the work does not focus on policies and permissions for multiple parties as we concentrate on HybridGuard.
Draco [83] provides a declarative policy language for developers to define fine-grained access control policies for multiple origins, for web code running on Android in-app browsers. It also introduces the Draco Runtime System (DRS) to enforce these policies at runtime. Another fine-grained access control mechanism for Android hybrid mobile apps implements frame-level access control [37]. RestrictedPath [70] allows developers to define intended API paths of their apps and subsequently monitors all API invocations. The monitoring determines whether an app deviates from its intended path [70], thus enforcing access-control. MinPerm [50] automatically identifies over-privileged permissions by comparing permissions declared by the developer and permissions required by the app. However, all these approaches are specific to Android and, thus, require the modification of the Android base system. In contrast, we implement HybridGuard framework at the web layer, and therefore, it can apply to any mobile platform without modifying the base system.
Georgiev et al. introduce the term fracking for the generic class of vulnerabilities that allow untrusted web content to access device resources [25]. They propose NOFRAK, an access control mechanism that enforces the security policy, “NoBridge” – an app can load third-party content without accessing device resources. This approach is a highly coarse-grained mechanism compared to our multi-party and fine-grained policies. AlJarrah et al. propose an access-control mechanism that restricts access to only required device resources per page, to minimize the attack surface [76]. Unlike HybridGuard, this solution is only applicable to multi-page web-based mobile apps. The same researchers also propose a behavior-based approach to generating fine-grained security configurations to implement the least privilege principle automatically [5]. In another work, CordovaConfig [6], the authors implement a web-based tool prototype that provides automated interactive support for configuring hybrid apps. Kudo et al. [40] introduce a novel attack technique termed as app-repackaging, where an attacker repackages hybrid apps with malicious code intended to steal sensitive user data stealthily. They introduce a runtime access control mechanism to restrict access to device resources. As opposed to HybridGuard, these approaches modify the underlying Cordova library to implement the solution.
Yang et al. [90] identify a new security issue in
Detecting and preventing code-injection
Several solutions focus on detecting code-injection attacks in hybrid mobile apps. Jin et al. introduce the possibility of code-injection attacks in hybrid mobile apps through non-web channels, such as SMS, Contact List, Calendar, NFC, camera, and even Wi-FI SSID, that are specific to smartphones [36]. DroidCIA [22] extends the previously mentioned work, i.e., [36] to introduce a new code-injection channel, where a malicious script can be injected by using the HTML5
In summary, all of these methods mentioned above detect and prevent code-injection attacks that can execute malicious code at runtime. However, hybrid app developers can prevent such code-injection attacks by disallowing inline scripts in CSP. In contrast, our work focuses on attacks that cannot be mitigated by CSP.
Security analysis and surveys
There are a few studies that provide an overview of security mechanisms and analyze the vulnerabilities in hybrid and web-based mobile apps. In [59], the authors reveal that 28% of one million web-based mobile apps have at least one vulnerability. If exploited, these vulnerabilities can cause serious cyber-attacks. [87] studies over a thousand Cordova apps downloaded from Google Play and gives a statistical overview of the adoption of Cordova security best practices and mechanisms, such as usage of whitelist or the occurrence of
In [4], the authors summarize the statistics of the prevalence of hybrid apps, most widely used cross-platform tools, based on the analysis of around 15,000 hybrid apps. BridgeScope [91], investigates JavaScript bridge security issues, such as evading security checks in WebView event handlers, in Android hybrid apps. HybriDroid [42], a static analysis framework for Android hybrid apps, investigates bugs originating from the interoperability of Android Java and JavaScript in Android hybrid mobile apps. Hybrid-scanner [71] is another tool that tracks and analyzes the internal behavior of hybrid mobile apps. Using Hybrid-scanner, the authors found that almost 40% of security-sensitive APIs in hybrid mobile apps are invoked by third-party libraries, e.g., advertisement libraries. Apart from revealing numerous security issues in hybrid mobile apps, none of the works implement any defense solution.
Biørn-Hansen et al. conduct a comprehensive survey that assesses the cross-platform mobile app development academic body of knowledge [16]. The survey particularly emphasizes core concepts that include user experience, device features, performance, and security. Their findings illustrate that the state of research demands empirical verification of an array of unbacked claims and that a particular focus on qualitative user-oriented research is essential. HybridGuard provides the first steps towards this user-oriented by allowing users to customize the policies.
System design
Overview of the HybridGuard framework
The objective of our HybridGuard framework is to provide a mechanism for developers to define and enforce different policies for each included JavaScript code within a hybrid mobile app. The JavaScript code might be untrusted local script files, or remote scripts coming from various parties, e.g., advertisements. Our policy specification allows developers to express default and generic policies that can prevent frequent potential attacks such as attack scenarios discussed in Section 2.2. We separate the policy specification from the enforcement code, and we include both of them into the code base of the app. With the separated policies, our framework provides the capability to customize the policy parameters while or after installing an app. Figure 2 depicts the overview of our framework that complies with the development flow of a hybrid mobile app development process.

The overview of our framework and its development flow.
In general, when deploying our HybridGuard framework at the development phase, developers first include the core JavaScript library of the framework, i.e., the
In the next step, instead of including JavaScript code in any sources, either local or remote in the standard way, i.e., using
After including all scripts for an app using our loading mechanism, the app developer needs to customize our policy template, i.e., the
Thus in the next subsection, we introduce our design of the policy specification. We describe the implementation of the policy enforcement and monitoring component in Section 5. We note that the design and implementation of our policy and enforcement framework are independent of any particular web-based hybrid mobile app development framework.
In this subsection, we describe the policy specification design and illustrate how to apply these policies in realistic scenarios. Our goal is to specify rules on how JavaScript code from different parties interact with device resources and users’ sensitive information. To this end, our policy specification supports two types of policies, as described below.
Multi-party and context-aware permissions
We extend the permission model in mobile architecture. Our new permission scheme allows developers to define and enforce context-aware properties for each party on a single granted permission. For each resource access or action, i.e., granted permission, developers can define which party can access or perform an action on that resource under a label “principal”. We support not only
We use JavaScript Object Notation (JSON) to specify our multi-party and context-aware permissions. We express each device resource in an array element inside a JSON file, each of which has an array of permission objects, identified by a principal (the label for a party). For each resource, developers can specify which principal can be allowed with further runtime constraints. For instance, Listing 1 illustrates an example of such multi-party permissions. This multi-party permission example allows the local code (loaded with principal “

An abbreviated example of fine-grained permissions and policies for two origins
Multi-party and context-aware permission can enforce policies that control code from a source to access a granted resource. However, permission-based policies cannot capture and prevent potential malicious actions. For example, permission-based policies are not possible to detect or prevent scenarios such as sensitive information leakage or UI attacks (cf. Section 2.2). In addition to the multi-party permission check, our framework also allows developers to define custom and fine-grained policies such as whitelist specification, stateful, and history-based policies. In this framework, we use JavaScript code to define these custom policies. An example of such policies is “after a principal reads the contact list, it is not allowed to send any SMS” (assume that the principal is allowed to read the contact list in principal-based permission). Listing 7 illustrates this type of policy that can prevent potential information leakage. We note that such a policy is also based on multi-party: the principal violating the policy is denied to send SMSs, but other principals can still be allowed to send SMS.
Privacy-based and custom policies. As our fine-grained policy specification can capture potential malicious actions at runtime, our framework can be used to protect the privacy of users. Since we develop our framework in JavaScript, developers can express any custom policies that cannot be generalized in rules. In Section 6, we provide wide-range policy templates in the structure of multi-party permissions presented previously. Depending on a specific app and its third-party code, developers can use all or select parts of the templates to deploy in the hybrid app. Customized policies from the templates are included at the development stage so that the policy can be enforced and customized by users at runtime.
Implementation

Enforcement mechanism of our HybridGuard framework.
This section describes how we implement key modules in our framework to enforce defined permissions and policies. Figure 3 illustrates the overview of the enforcement mechanism in our framework. We provide a new API,
As discussed, the origin of JavaScript code in hybrid mobile apps is not propagated, therefore the app developer cannot enforce policy rules based on the real origin of the invocation [83]. To solve this issue, we introduce and implement a new JavaScript API
We use CORS (Cross-Origin Resource Sharing, see: https://www.w3.org/TR/cors/) to retrieve the content of a JavaScript file in a string. CORS allows cross-domain communication based on the
JavaScript APIs mediation
Our enforcement mechanism mediates JavaScript APIs, including the DOM/HTML5 APIs and JavaScript bridge APIs provided by hybrid frameworks or developers. This mediation method stands apart from the hybrid mobile app security literature, which only either mediates the bridge APIs, e.g., [26,83], or DOM/HTML5 APIs, e.g., [37]. The mediation mechanism monitors the invocation of the mediated APIs at runtime to control its execution based on the defined policies. We implement this monitoring mechanism by first storing the original API, and then redefining this API with a new function. This new function acts as a reference monitor for the API call and, therefore, controls the execution of this call, i.e., allow or deny based on the policies. Psuedo-code in Listing 2 illustrates the mediation mechanism for a bridge API example, the

Illustration of mediation of API sms.send within an anonymous function
Our prototype implementation generalizes the mediation mechanism by providing an interface with three parameters:
We adopt this mechanism from prior work [69]; however, we have advanced the previous work with two features that do not exist in the state-of-the-art JavaScript security solutions. First, our mediation is not only for the web APIs but also for JavaScript bridge APIs in hybrid mobile apps. Second, our implementation supports principal-based permission access control for multi-party scripts.
One challenge in this implementation is the complete mediation of the interception that to ensure loaded JavaScript code cannot access the guarded API directly except through the monitor. For DOM/HTML5 APIs, we achieve this by capturing all possible aliases of the guarded API through its prototype inheritance chain in the monitor. There have been several known vulnerabilities in JavaScript that can be exploited in JavaScript interception implementation [48,53]. We apply the secure wrapper implementations in the literature [48] to assure that our monitor implementation is tamper-proof from potentially malicious code. In particular, we have implemented the following protections for the DOM/HTML5 APIs.
We first store the local copy of common method prototypes such as
We disconnect the chain of inheritance for an intercepted method by setting the
We wrap static and dynamic aliases of a single API so that malicious cannot recover the intercepted API with these aliases. For a given method, we intercept the “root” object at the top of the prototype inheritance chain so that all the static aliases can be captured and intercepted. As being executed before other mediated scripts, our enforcement code has the advantage of intercepting all APIs that can create a window object, e.g.,
For JavaScript bridge APIs, there might be several different APIs provided by various plugins (JavaScript libraries) to access a device resource. As the app developer includes plugins to her app, she knows the specific APIs to intercept and enforce policies. Each JavaScript bridge API typically uses an internal function call to interact with the native API. For example, in Cordova,
Principal propagation in event handlers and dynamic code generation
Like native mobile apps, hybrid ones heavily rely on events such as user touch to trigger computation. In our framework, we capture and intercept these event channels, such as

Principal tracking for event handler
The same approach is applied to code generation on the fly through DOM APIs such as
As illustrated in Fig. 3, an invocation to a guarded API is dispatched together with its principal to the corresponding monitor. The monitor then consults the policy manager; based on the policy definition, the policy manager will decide whether to proceed with the invocation. As briefly outlined in the previous section, our framework supports principal-based permissions and stateful policies. We use JavaScript Object Notation (JSON) to specify principal-based permission for the device resource access (including DOM and JavaScript bridge APIs) by any party JavaScript code running inside the app as introduced in Section 4.2.
In our previous prototype implementation [67], we store the specification in a local JSON file within the app, and load it using

Pseudo-code (for brevity) to load internal policy specification
Let us consider a scenario when a user installs a hybrid app that integrates our framework. As a norm, the user needs to grant permissions requested by the app. With our framework, ideally, the user can define more fine-grained restrictions or customized policies such as “revoke a granted permission for an origin in the app”. Also, the user should be able to customize some policy parameters to protect her own privacy. Our current implementation allows users to customize policies by editing the file content directly at runtime as we store the policy specification in a data directory. However, understanding and defining policies in JSON specification is not an easy task, especially for layman users. In the future, we plan to map this policy specification into user interfaces so that end-users can easily edit the parameters at the installation phase or runtime.
Our HybridGuard monitor intercepts API calls accessing a resource, as depicted in Fig. 3. Therefore, for each API invocation, the monitor invokes the Policy Manager module to check the policies to allow or disallow that API. The monitor code maps an API call to an action defined in the policy specification so that the Policy Manager can perform the check to return the decision.
There are two layers of checking in this Policy Manager module. An API call is allowed and executed if it passes both of these two layers. The first layer is to check the multi-party and context-aware permission in the JSON object cached in memory. We synchronize this cached object with the policy specification file stored in the data directory to ensure that all policy states are updated persistently. Our framework also performs the same synchronization mechanism when the end-user customizes existing policies on the fly. For example, when the user disallows a resource for an origin by editing the policy file content, the new content is loaded into the JSON cached object. This synchronization mechanism is to guarantee that the runtime monitor enforces the newly updated policy when the app invokes a corresponding API call.
For each policy pattern (cf. Section 6) defined in the JSON specification, we implement a corresponding function to look-up the permission based on the resource and principal (the caller) and check the policy parameters based on the context. The Policy Manager module also updates runtime parameters, such as the number of times when an API call is allowed and executed. The second layer of checking is the custom policies defined purely in JavaScript. The implementation of these checks is dependent on each policy category. In the next section, we introduce the policy patterns and templates, together with its implementation details that support this Policy Manager module.
Policy patterns and templates
Implemented as a reference monitor, our framework supports fine-grained security policies satisfying safety property of execution, i.e., preventing bad things from happening. These fine-grained policies can be leveraged and deployed in hybrid mobile apps to protect the privacy of users. In this section, we present a wide range of policy templates that developers can use to deploy in hybrid apps at the development stage, depending on the functionality of the app. These policy categories cannot be expressed in current coarse-grain permission models, and are novel compared to our previous work [67]. Table 1 elaborates on how these policy templates can be deployed and enforced for common device resources. These devices resources include bridge APIs, i.e., plugins provided by a hybrid development framework, and native objects shared by developers as discussed in Section 4.1. An API comprises a resource object and a method in the corresponding columns in Table 1. For example, the API to send SMS messages comprises the object “
List of policies can be enforced on plugins/resources
List of policies can be enforced on plugins/resources
In this subsection, we introduce fine-grained and context-aware policies based on permissions that end-users can personalize at the installation stage or runtime.
Volume bound policy
Many mobile apps abuse device resources by repeatedly invoking the resources such as reading the contact list a hundred times, as demonstrated in the litureture [24]. In some scenarios, users might want to limit the volume of resource usage, such as the number of SMS messages an app can send per day.
Our specification supports such a volume bound policy within a time unit. In our current specification, we support “day” as the time unit; however, we can extend it to support other time units such as an hour, or a week. We define this policy category in the “maxUseLimit” property. To enforce this policy category for a device resource over a principal, developers need to keep and set the value for the field

An example of volume bound policy
Mobile users might want to limit the duration that a device resource can be used to save energy or to protect their privacy. Our policy specification supports this policy category with

An example of duration usage policy
Some policies might be related to location, i.e., allowing a device resource access at particular places. For example, users might want to allow sending SMS messages only while the device is in domestic location. We support this policy category with a coordinate (
Blacklist/whitelist policy
In some scenarios, a principal is allowed to invoke an API with parameters. For example, to send an SMS message, the code needs to call
Custom fine-grained policies
Implemented in JavaScript, our framework can enforce fine-grained policies expressed in JavaScript code that can be defined by developers at the development phase. We present several common history-based and generic web-based policies that can prevent potential attacks.
History-based policies
A common attack in malicious advertisements is to read sensitive user data and send it to the attacker through different channels, such as image source. Although CSP policy can prevent some of these channels, there are other channels specific to a mobile device that is not captured by CSP, such as SMS and email. Developers can prevent this potential information leakage by monitoring access to sensitive information and preventing certain APIs that are not captured by CSP and might leak data. For example, developers can define a policy such as “no SMS sending after the contact list is read” to prevent this potential phone-specific data leakage. Developers can implement this policy by intercepting the contact read action to toggle the contact read flag. If the flag is toggled when the SMS send API is invoked, the monitor will suppress the action. We illustrate this policy example in Listing 7.

Example of “no SMS send after reading contact list” policy
There are several potential malicious behaviors of third-party JavaScript code. Examples of such behaviors include manipulating the DOM and creating UI attacks such as touchjacking (e.g., by creating an invisible
Evaluation
In this section, we report the evaluation of our HybridGuard framework, including the experiments and results on the functionality, compatibility on different hybrid app frameworks, mobile platforms, and real-world hybrid apps, the performance and overhead, and its security. We release our prototype and experimental results on https://github.com/isseclab-udayton/hybridguard2.0.
Compatibility
We evaluate the compatibility of our framework in two settings: a test suite and existing hybrid apps on an app store. First, we develop a test suite of variants of a hybrid app in multiple hybrid development platforms with standard bridge APIs to access device resources. We deploy our framework on these app variants to evaluate how our framework works in these settings. In the second evaluation setting, we want to test how our framework is compatible with existing hybrid apps in the wild. To this end, we use Android real-world hybrid apps since we can reverse engineer Android apps to inject code and rebuild the apps. We describe the experiments and their results below.
Test suite
We first develop a base hybrid app using four different hybrid app development frameworks, including Cordova v6.2.3, Framework7 v1.6.4, Onsen UI v2.4.2, and Intel XDK v3987. To test the functionality, we include corresponding plugins in each framework. These plugins include SMS, email, contacts, camera, geolocation, accelerometer, and file system. We list these resources and their corresponding APIs in the first and second columns of Table 1. This inclusion is to check that the base app can use common device resources. We write JavaScript code in a
Before integrating our framework to the app variants, we build and deploy them to physical devices to ensure that the apps are functional on these devices. For Android, we deploy the app variants directly to a Google Pixel XL device with Android 7.1. For iOS, we use Xcode 9 to build and deploy the app variants to an iPhone 7 Plus device with iOS 10.0.1. We test these eight variants of the app on the two devices. As the Onsen UI variant does not work on the iOS device, we deploy and test them on an iOS 10.0.1 emulator. In all of these testing environments, the app functionally works as expected, and both local and remote scripts can access all of the device resources properly.
To evaluate the compatibility of our framework, we modify each original app variant to deploy the framework. We first customize the policy template for each app variant and store it in a JSON file within each app folder together with the framework library
For this compatibility evaluation, we define policies to monitor and log the execution. This evaluation is to test if the apps integrated with our framework work as in their original versions. We then rebuild the app variants and deploy them to the devices again to test the functionality. We turn on debug messages so that we can observe all the execution logs from our framework. The logs demonstrate that our enforcement code intercepts and monitors all the calls to the device resources. Also, the principals (based on the source) are identified correctly for both local and remote scripts, and the functionality of the app variants is preserved. Among the app variants, we note that there is a minor issue in Framework7 on both Android and iOS devices, that the principals are not tracked in the same order. However, accessing the resources is functional and monitored by the policies. Figure 4 illustrates this compatibility evaluation. As we can see from the figure, our framework is compatible with every framework on the two major mobile platforms, Android and iOS.

Compatibility crossing frameworks and platforms of the modified app with HybridGuard embedded.
By design, developers need to integrate our framework at the development stage to define and enforce policies. However, to evaluate the compatibility and usability of our framework, we integrate our framework into existing real-world hybrid apps. As Android apps allow us to reverse-engineer the code, we select the Android platform to test our framework. We first collect real-world Android-based hybrid mobile apps by downloading these apps in
Next, we integrate our framework into these apps, following a similar step as done for the test suite described above. In particular, we copy the framework library (the
Fine-grained policy enforcement
In the second round of evaluation, we revise the policies for the app variants in our test suite to evaluate whether our framework can soundly enforce these policies. Out test policies do not only log the execution but also to monitor the behaviors of the execution with fine-grained policies as provided in the templates presented in the previous section. These policy templates include multi-party and context-aware permissions in the JSON specification that can prevent the attack scenarios of abusing device resources, as identified in Section 2.2. We also define custom fine-grained policies in JavaScript. These custom policies are to prevent potential attacks such as malvertisements and sensitive information leakage as well as UI redress attacks, as also discussed in Section 2.2. To test the effectiveness of our policy enforcement framework, we modify the script code to intentionally violate the policies at some points and rebuild and deploy the apps. Experiments and logs confirm that the accesses to resources are functional until the policies are violated, demonstrating our framework enforces the defined policies correctly. For example, we enforce a volume bound policy that allows the maximum of 5 times of SMS sending, as illustrated in Listing 5. Our test code repeatedly calls the SMS sending API in every ten seconds to send an SMS message. The first five messages were successfully sent from the app and received on another phone. After that, our framework stops the execution of this SMS API and alerts a message, as shown on the left of Fig. 5. The other test cases in Fig. 5 illustrate the correct enforcement of other policy categories, including duration usage, and location-based, respectively.

Policy enforcement evaluation on different policy categories.
We evaluate our framework performance by measuring the runtime overhead posed by our policy enforcement mechanism. Typically, the runtime overhead of web-based systems like hybrid mobile apps can be measured by both in JavaScript operations, i.e., micro-benchmarks and the load or render time, macro-benchmarks [69,74]. We measure the load time of an app with and without our framework. We do not notice any slowdown as the load time of the original app and the modified app with our framework are almost identical. This result can be explained by the fact that JavaScript code in, e.g., hybrid apps, is mostly event-based, and asynchronous.1
For this reason, we are interested in evaluating the micro-benchmarks of operations that do not depend on triggered events, including getting the current position, acceleration, and direction. To this end, we modify the code in original app variants to execute these operations 1000 runs, to achieve high precision, and measure the time before and after the runs. For each case, we run the apps on the two devices with ten trials to get the averaged numbers.We then integrate our framework in these apps with three different policies, including usage limit, the number of times per day, and the duration of execution time (cf., Section 6). We set very high limits in these policies to ensure that no violation will happen. Thus the operations are just executed as usual. We do the same measurements as in the original apps to get the corresponding averaged numbers. We report the overhead by showing the slowdown ratio over 1000 runs between the average execution time of each operation test with the HybridGuard-integrated app and that of the original app for each combination of a development framework and mobile platform. Table 2 shows these slowdown ratio numbers for each operation on the combination of three development frameworks (Cordova, Framework7, OnsenUI) and two mobile platforms (Android and iOS). Although our framework is compatible with Intel XDK as demonstrated in Section 7.1.1, the time measurement over 1000 runs on the app based on this framework, both the original and modified app, was inconsistent in 10 trials. Therefore, we exclude the Intel XDK framework in performance evaluation results.
Overall, the experimental results evidenced that our HybridGuard framework only poses a small additional runtime overhead on 1000 runs. Table 2 shows these numbers as slowdown ratios. Figure 6 visualize a notable runtime overhead test. Compared to similar approaches of JavaScript runtime monitors such as [74], our micro runtime overhead is very light. These overhead numbers are also in line with our prior work, such as [68,69]. However, there are no common patterns for the overhead of each operation crossing various frameworks and devices posed by our framework. In particular, for the acceleration operation, our framework has almost no overhead, crossing the three tested hybrid development frameworks and two mobile platforms. For the get current position operation, we see that the overhead of our framework for this operation is quite small for Android. At the same time, they vary in iOS for different hybrid development frameworks. For the get direction operation, our framework poses nearly no overhead for the app variants in iOS with Cordova and OnseiUI frameworks, a small overhead for all apps in Android, but surprisingly high overhead for Framework7 app in iOS. Interestingly, we have observed that each app execution time in each Android and iOS device is a significant difference. For example, our framework overhead on the acceleration operation is almost the same for Android and iOS, crossing hybrid frameworks, as shown in Table 2. However, the execution times in each platform are vastly different. In particular, an app variant in iOS executes much faster (about 70 times) than the one in Android, as visualized in Fig. 6.
The slowdown ratio over 1000 runs of typical device resource operations. Numbers in each cell represent the slowdown ratio of an operation on a development framework (including Cordova, Framework7, OnsenUI) and mobile platform (including Android and iOS)

Overhead of the acceleration operation posed by our framework crossing development frameworks and two mobile platforms.
As discussed earlier, the standard Content-Security-Policy (CSP) in hybrid mobile apps can prevent potential code injections and information leakage attacks by web channels. However, CSP cannot detect and prevent information leakage with phone-related channels or attack scenarios we discussed in Section 2.2. Our HybridGuard framework provides an extra layer of protection on JavaScript code that is allowed by CSP. As required by default CSP, developers have to define each JavaScript code in a
Conclusions and future work
In this article, we have introduced a robust and platform-independent policy enforcement framework, namely HybridGuard, for hybrid mobile apps. HybridGuard can enforce multi-party, fine-grained permissions, and policies to guard against attacks in JavaScript code in hybrid mobile apps originating from multiple parties. We define policies in JSON and develop the enforcement engine in JavaScript. Therefore, HybridGuard is platform-agnostic and is compatible with major mobile platforms and hybrid development frameworks without modifying them, as evidenced by the evaluation. We have provided a list of practical permission and policy patterns that developers can use as templates to define real policies for mitigating potential attacks and privacy violations.
Our design allows app users to customize the policy parameters for privacy protection. However, in the current prototype implementation, it only allows users to edit the specification in a raw JSON file. In future work, we plan to extend the policy system so that app users can specify their policies on a hybrid app through a graphical interface. Together with a graphical interface for policy customization, we plan to adopt a declarative approach to specifying policies without implementing them in a specific language, e.g., JavaScript. We will extend the context-aware permission-based policy specification to support more context categories such as timeframe, interval, event sequence. We also plan to construct a testbed of hybrid apps and an ontology of possible attacks. Such a testbed allows us to conduct a large-scale evaluation of real-world hybrid apps and effective security policies. Also, we want to study the developer experiences when deploying our framework so that we can improve its features and release it as an open-source tool.
Footnotes
Acknowledgments
This work was supported by The University of Dayton Research Council Seed Grants and The Dean’s Summer Fellowship Program from The University of Dayton College of Arts and Sciences. Meera Sridhar was supported by NSF CRII award #1566321. We thank the anonymous reviewers for their insightful comments and helpful suggestions. We acknowledge Rahul Rachapalli for his contribution to the preliminary version of this work.
