Secure Coding Practices in Java: Challenges and Vulnerabilities
Total Page:16
File Type:pdf, Size:1020Kb
Secure Coding Practices in Java: Challenges and Vulnerabilities Na Meng Stefan Nagy Daphne Yao Wenjie Zhuang Gustavo Arango Argoty Virginia Tech Blacksburg, Virginia 24060 {nm8247,snagy2,danfeng,kaito,gustavo1}@vt.edu ABSTRACT 1 INTRODUCTION Java platform and third-party libraries provide functionalities to fa- Java platform and third-party libraries or frameworks (e.g., Boun- cilitate secure coding. However, misusing these functionalities can cyCastle [6]) provide various features to enable secure coding. Mis- cost developers tremendous time and effort, or introduce security using these libraries and frameworks not only slows development vulnerabilities in software. Prior research focused on the misuse of time, but also leads to security vulnerabilities in the resulting soft- cryptography and SSL APIs, but did not explore the fundamental re- ware [14, 98, 99, 103]. search question: what are the biggest challenges and vulnerabilities Prior research mainly focused on cryptography and SSL API in secure coding practices? In this paper, we conducted a broader misuse causing security vulnerabilities [80, 82, 85, 88]. Specifically, empirical study on StackOverflow posts to understand developers’ Lazar et al. manually examined 269 published cryptographic vul- concerns on Java secure coding, their programming obstacles, and nerabilities in the CVE database, and observed 83% of them resulted the potential vulnerabilities in their code. from cryptography API misuse [88]. Nadi et al. further investigated We observed that developers have shifted their effort to the usage the obstacles introduced by Java cryptography APIs, developers’ of authentication and authorization features provided by Spring usage of the APIs, and desired tool support [94]. Fahl et al. [82] and Security—a third-party framework designed to secure enterprise Georgiev et al. [85] separately implemented a man-in-the-middle applications. The programming challenges are all related to APIs or attack, and detected vulnerable Android applications and software libraries, including the complicated cross-language data handling libraries misusing SSL APIs. Despite these studies, it is still un- of cryptography APIs, and the complex Java-based or XML-based known what the major concerns are in secure coding practices, approaches to configure Spring Security. More interestingly, we and whether these practices benefitted from security research over identified security vulnerabilities in the suggested code of accepted time. answers. The vulnerabilities included using insecure hash functions In this paper, we conducted a broader in-depth investigation on (e.g., MD5), breaking SSL/TLS security through bypassing certificate the common concerns, programming challenges, and security vul- validation, and insecurely disabling the default protection against nerabilities in developers’ secure coding practices by inspecting 503 Cross Site Request Forgery attacks. Our findings reveal the insuffi- StackOverflow (SO) posts related to Java security. We chose SO[63] ciency of secure coding assistance and documentation, as well as because (1) it is a popular online platform for developers to share the gap between security theory and coding practices. and discuss programming issues and solutions, and (2) SO plays an important role in educating developers and shaping their daily CCS CONCEPTS coding practices. The main challenge of conducting this empirical study is interpreting security-relevant programming issues or solu- • General and reference → Empirical studies; tions within both program and security contexts. To comprehend each post within the program context, we manually checked all KEYWORDS included information related to the source code, configuration files, CSRF, SSL/TLS certificate validation, cryptographic hash functions, and/or execution environments. Then, we identified the root causes authentication, authorization, StackOverflow posts and solutions of each problem. To comprehend each post within the security context, we collected information about the developers’ ACM Reference format: implementation intents and the involved security libraries, and Na Meng Stefan Nagy Daphne Yao Wenjie Zhuang Gustavo determined whether the final implementation fulfilled the intents. Arango Argoty. 2018. Secure Coding Practices in Java: Challenges and Such manual analysis requires so much expertise in both software Vulnerabilities. In Proceedings of ACM conference, Gothenburg, Sweden, May engineering and security that it is difficult to automate. 2018 (ICSE’18), 13 pages. In our thorough manual analysis of the 503 posts, we investigated https://doi.org/10.475/123_4 the following three research questions (RQs): RQ1 What are the common concerns in Java secure coding? Al- Permission to make digital or hard copies of part or all of this work for personal or though there are various security libraries and frameworks [2, classroom use is granted without fee provided that copies are not made or distributed 32, 34, 57, 86, 95], we do not know which libraries and func- for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for third-party components of this work must be honored. tionalities are most frequently asked about by developers. For all other uses, contact the owner/author(s). RQ2 What are the common programming challenges? We aim to ICSE’18, May 2018, Gothenburg, Sweden identify the common obstacles preventing developers from © 2018 Copyright held by the owner/author(s). easily and correctly implementing secure code. Such infor- ACM ISBN 123-4567-24-567/08/06. https://doi.org/10.475/123_4 mation will provide SE researchers actionable knowledge to ICSE’18, May 2018, Gothenburg, Sweden Na Meng Stefan Nagy Daphne Yao Wenjie Zhuang Gustavo Arango Argoty better develop tools, and help close the gap between intended cryptographic operations (encryption, digital signatures, hashes), versus actual library usage. generators or converters of cryptographic material (keys and algo- RQ3 What are the common security vulnerabilities? We aim to rithm parameters), or objects (keystores or certificates) that encap- identify security the vulnerabilities spread on SO, since their sulate the cryptographic data. gaining popularity may cause insecure code to see wide- The access control architecture protects the access to sensitive re- spread implementation. This effort will help raise security sources (e.g., local files) or sensitive application code (e.g., methods consciousness among software developers. in a class). All access control decisions are mediated by a security In our study, we made three major observations. manager. By default, the security manager uses the AccessController • There were security vulnerabilities in the recommended code class for access control operations and decisions. of some accepted answers. For example, usage of MD5 or Secure communication ensures that the data which travels across SHA-1 algorithms was repeatedly suggested, although these a network is sent to the appropriate party, without being modified algorithms are notoriously insecure and should not be used. during the transmission. Cryptography forms the basis for secure Additionally, many developers were advised to trust all in- communication. The Java platform provides API support for stan- SSL/TLS HTTPS coming SSL/TLS certificates as a temporary fix to certificate dard secure communication protocols like . , or verification errors. Such action completely disrupts the secu- “HTTP secure”, is an application-specific implementation that isa rity of SSL. Although this bad practice was initially reported combination of HTTP and SSL/TLS. by researchers in 2012 [82, 85], developers have still asked for and accepted it until now. Furthermore, when encounter- 2.2 Java EE Security ing errors in implementing Spring Security authentication, Java EE is an standard specification for enterprise Java extensions [44]. developers were often suggested a workaround to blindly Various application servers are built to implement this specification, disable the default security protection against Cross Site such as JBoss or WildFly [71], Glassfish [18], WebSphere [69], Request Forgery (CSRF) attacks. and WebLogic [3]. A Java EE application consists of components • Various programming challenges were related to security li- deployed into various containers. The Java EE security specification brary usage. For instance, developers became stuck using defines that containers secure components by supporting features cryptography APIs due to clueless error messages, complex like authentication and authorization. cross-language data handling, and delicate implicit API usage In particular, authentication defines how communicating en- constraints. However, when using Spring Security, develop- tities, such as a client and a server, prove to each other that they ers struggled with the two alternative ways of configuring are who they say they are. An authenticated user is issued a creden- security: Java-based or XML-based. tial, which includes user information like usernames/passwords or • Since 2012, developers have increasingly relied on Spring Se- tokens. Authorization ensures that users have permissions to per- curity for secure coding. 267 of the 503 examined posts (53%) form operations or access data. When accessing a certain resource, were about Spring Security. However, to the best of our a user is authorized if the server can map this user to a security knowledge, research has not yet investigated