Analyzing Information Flow in Javascript-Based Browser Extensions Mohan Dhawan and Vinod Ganapathy Department of Computer Science, Rutgers University
Total Page:16
File Type:pdf, Size:1020Kb
Published in ACSAC’09: Proceedings of the 25th Annual Computer Security Applications Conference, Honolulu, Hawaii, December 2009 Analyzing Information Flow in JavaScript-based Browser Extensions Mohan Dhawan and Vinod Ganapathy Department of Computer Science, Rutgers University Abstract net Explorer and Google Chrome also support extensions (e.g., scriptable plugins and ActiveX controls) that contain JavaScript-based browser extensions (JSEs) enhance the or interact with JavaScript code. core functionality of web browsers by improving their look However, recent attacks show that JSEs pose a threat to and feel, and are widely available for commodity browsers. browser security. Two factors contribute to this threat: To enable a rich set of functionalities, browsers typically (1) Inadequate sandboxing of JavaScript in a JSE. Un- execute JSEs with elevated privileges. For example, un- like JavaScript code in a web application, which executes like JavaScript code in a web application, code in a JSE is with restricted privileges [9], JavaScript code in a JSE exe- not constrained by the same-origin policy. Malicious JSEs cutes with the privileges of the browser. JSEs are not con- can misuse these privileges to compromise confidentiality strained by the same-origin policy [38], and can freely ac- and integrity, e.g., by stealing sensitive information, such as cess sensitive entities, such as the cookie store and brows- cookies and saved passwords, or executing arbitrary code ing history. For instance, JavaScript in a JSE is allowed on the host system. Even if a JSE is not overtly malicious, to send an XMLHttpRequest to any web domain. Even vulnerabilities in the JSE and the browser may allow a re- though JavaScript only provides restricted language-level mote attacker to compromise browser security. constructs for I/O, browsers typically provide cross-domain We present Sabre (Security Architecture for Browser interfaces that enable a JSE to perform I/O. For example, Extensions), a system that uses in-browser information-flow although JavaScript does not have language-level primi- tracking to analyze JSEs. Sabre associates a label with tives to interact with the file system, JSEs in Firefox can each in-memory JavaScript object in the browser, which access the file system via constructs provided by the XP- determines whether the object contains sensitive informa- COM (cross-domain component object model) interface [7]. tion. Sabre propagates labels as objects are modified by the Importantly, these features are necessary to create expres- JSE and passed between browser subsystems. Sabre raises sive JSEs that support a rich set of functionalities. For an alert if an object containing sensitive information is ac- example, JSEs that provide cookie/password management cessed in an unsafe way, e.g., if a JSE attempts to send the functionality rely critically on the ability to access the object over the network or write it to a file. We implemented cookie/password stores. Sabre by modifying the Firefox browser and evaluated it us- However, JSEs from untrusted third parties may contain ing both malicious JSEs as well as benign ones that con- malicious functionality that exploits the privileges that the tained exploitable vulnerabilities. Our experiments show browser affords to JavaScript code in an extension. Exam- that Sabre can precisely identify potential information flow ples of such JSEs exist in the wild. They are extremely violations by JSEs. easy to create and can avoid detection using stealth tech- niques [11, 13, 14, 15, 18, 41]. Indeed, we wrote several such JSEs during the course of this project. 1. Introduction (2) Browser and JSE vulnerabilities. Even if a JSE is not malicious, vulnerabilities in the browser and in JSEs may al- Modern web browsers support an architecture that lets low a malicious website to access and misuse the privileges third-party extensions enhance the core functionality of the of a JSE [12, 35, 39, 40, 45]. Vulnerabilities in older ver- browser. Such extensions enhance the look and feel of the sions of Firefox/Greasemonkey allowed a remote attacker to browser and help render rich web content, such as mul- access the file system on the host machine [35, 45]. Simi- timedia. Extensions are widely available for commodity larly, vulnerabilities in Firebug [12, 39] allowed remote at- browsers as plugins (e.g., PDF readers, Flash players, Ac- tackers to execute arbitrary commands on the host machine tiveX), browser helper objects (BHOs) and add-ons. using exploits akin to cross-site scripting. These attacks ex- This paper concerns JavaScript-based browser exten- ploit subtle interactions between the browser and JSEs. sions (JSEs). Such extensions are written primarily in While there is much prior work on the security of JavaScript, and are widely available and immensely pop- untrusted browser extensions such as plugins and BHOs ular (as “add-ons”) for Firefox [4] and related tools, such (which are distributed as binary executables) particularly in as Thunderbird. Notable examples of JSEs for Firefox in- the context of spyware [22, 30, 31], there is relatively lit- clude Greasemonkey [5], which allows user-defined scripts tle work on analyzing the security of JSEs. Existing tech- to customize how web pages are rendered, Firebug [3], a niques to protect against an untrusted JSE rely on load- JavaScript development environment, and NoScript [8], a time verification of the integrity of the JSE, e.g., by ensur- JSE that aims to improve security by blocking script ex- ing that scripts are digitally signed by a trustworthy source. ecution from certain websites. Other browsers like Inter- However, such verification is agnostic to the code in a JSE our knowledge, prior work on JavaScript-level information and cannot prevent attacks enabled by vulnerabilities in the flow has not needed such support. browser or the JSE. Ter-Louw et al. [41] developed a run- To summarize, the main contributions of this paper are: time agent to detect malicious JSEs by monitoring XP- • Sabre, an information flow tracker for JSEs. We dis- COM calls and ensuring that these calls conform to a user- cuss the techniques used to implement information flow defined security policy. Such a security policy may, for in- tracking in a web browser and the heuristics used to stance, prevent a JSE from accessing the network after it achieve precision (Section 3). Sabre handles explicit in- has accessed browsing history. Unfortunately, XPCOM- formation flows, some forms of implicit flows, as well as level monitoring of JSEs is too coarse-grained and can be cross-domain flows. We have implemented a prototype overly restrictive. For example, one of their policies disal- of Sabre in Firefox. lows XPCOM calls when SSL is in use, which may prevent • Evaluation on 24 JSEs. We evaluated Sabre using ma- some JSEs from functioning in a https browsing session. licious JSEs as well as benign ones that contained ex- XPCOM-level monitoring can also miss attacks, e.g., a JSE ploitable vulnerabilities. In these cases, Sabre precisely may disguise its malicious actions so that they appear benign identified information flow violations. We also tested to the monitor (in a manner akin to mimicry attacks [43]). Sabre using benign JSEs. In these experiments, Sabre This paper presents Sabre, a system that uses in-browser precisely identified potentially suspicious flows that we information-flow tracking to analyze JSEs. Sabre associates manually analyzed and whitelisted (Section 4). each in-memory JavaScript object with a label that deter- mines whether the object contains sensitive information. We chose Firefox as our implementation and evalua- Sabre modifies this label when the corresponding object is tion platform because of the popularity and wide avail- modified by JavaScript code (contained both in JSEs and ability of JSEs for Firefox. However, JSEs pose a secu- web applications). Sabre raises an alert if a JavaScript ob- rity threat even in privilege-separated browser architectures ject containing sensitive data is accessed in an unsafe way, (e.g., [6, 27, 44]) for the same reasons as outlined earlier. e.g., if a JSE attempts to send a JavaScript object contain- The techniques described in this paper are therefore relevant ing sensitive data over the network or write it to a file. In and applicable to such browsers as well. addition to detecting such confidentiality violations, Sabre 2. Background and Motivating Examples also uses the same mechanism to detect integrity violations, e.g., if a JSE attempts to execute a script received from an Writing browser extensions in JavaScript offers a num- untrusted domain with elevated privileges. ber of advantages that will ensure that JSEs remain rele- Sabre differs from prior work [22] that uses information- vant in future browsers as well. JavaScript has emerged as flow tracking to analyze plugins and BHOs because it tracks the lingua franca of the Web and is supported by all major information flow at the level of JavaScript instructions and browsers. It offers several primitives that are ideally suited does so within the browser. In contrast, prior work on plugin for web browsing (e.g., handlers for user-generated events, security tracks information flow at the system level by track- such as mouse clicks and keystrokes) and allow easy inter- ing information flow at the granularity of machine instruc- action with web applications (e.g., primitives to access the tions. These differences allow Sabre to report better forensic DOM). JSEs can be written by developers with only a rudi- information with JSEs because an analyst can explain flow mentary knowledge of JavaScript and can readily be mod- of information at the granularity of JavaScript objects and ified by others, which in turn allows for rapid prototyping. instructions rather than at the granularity of memory words This is in contrast to plugins and BHOs, which are devel- and machine instructions.