1 / 47

Eliminating Bugs In MVC-Style Web Applications

Eliminating Bugs In MVC-Style Web Applications. Tevfik Bultan Verification Lab (Vlab), CS@UCSB bultan@cs.ucsb.edu http://www.cs.ucsb.edu/~vlab. Joint work with my students & postdocs. Fang Yu Muath Alkhalaf Jaideep Nijjar Sylvain Halle. Web software everywhere.

korbin
Télécharger la présentation

Eliminating Bugs In MVC-Style Web Applications

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Eliminating Bugs In MVC-Style Web Applications Tevfik Bultan Verification Lab (Vlab), CS@UCSB bultan@cs.ucsb.edu http://www.cs.ucsb.edu/~vlab

  2. Joint work with my students & postdocs • Fang Yu • Muath Alkhalaf • Jaideep Nijjar • Sylvain Halle

  3. Web software everywhere • Commerce, entertainment, social interaction • We will rely on web apps more in the future • Web apps + cloud will make desktop apps obsolete

  4. One major road block • Web applications are not trustworthy • They are notorious for security vulnerabilities and unreliable behavior • Web applications are hard to program • Distributed behavior, interaction among many components and many languages • We applications are hard to test • Highly dynamic behavior and concurrency • Testing accounts for 50% of the development costs and software failures cost USA 60 billion annually

  5. Why are web applications error prone? • Script-oriented programming • A collection of scripts with no explicit control flow • Extensive string manipulation • User input comes in string form, output (html, SQL) is generated via string manipulation • Complex interactions • User interaction via browsers, client-side server-side interaction, interaction with the backend database • Distributed system • Many components have to coordinate

  6. VLab Research Agenda • Improve dependability of web applications • How? • By eliminating bugs • How? • Use automated verification • By eliminating bugs I do not mean debugging • Debugging is done after the bug is found • Finding the bug is the hard part • Our goal is to find the bugs automatically • and eliminate them before the software is deployed • we do this using automated verification

  7. We have a hammer Automated Verification

  8. Actually, we have several hammers Bounded verification via SAT solvers Symbolic execution via SMT solvers String analysis Model checking Automated Verification Techniques

  9. Unfortunately, life is complicated Web application problems Automated verification techniques

  10. Automated verification is hard • If it wasn’t, everybody would be using it • It is hard because software systems are too complex • In order to make automated verification feasible • we need to focus our attention

  11. Making automated verification feasible • We focus our attention by • Abstraction • Hide details that do not involve the things we are checking • Modularity • We focus on one part of the system at a time • Separation of concerns • We focus on one property at a time • It turns out these are also the main principles of software design • We should be able to exploit the design structure in automated verification!

  12. Separation of concerns • First, we need to identify our concerns • What should we be concerned with if we want to eliminate the bugs in web applications • Here are some concerns: • Input validation • Errors in input validation are a major cause of security vulnerabilities in web applications • Navigation • Many web applications do not handle unexpected user requests appropriately • Data model • Integrity of the data model is essential for correctness of web applications

  13. Why care about input validation? String related web application vulnerabilities as a percentage of all vulnerabilities (reported by CVE) • OWASP Top 10 in 2007: • Cross Site Scripting • Injection Flaws • OWASP Top 10 in 2010: • Injection Flaws • Cross Site Scripting

  14. Why care about navigation?

  15. Why care about navigation?

  16. Why care about navigation?

  17. Why care about data model? • The data in the back-end database is the most important resource for most web applications • Integrity and consistency of this data is crucial for dependability of the web application

  18. Separation of concerns • By focusing on one problem at a time: • Input validation errors • Navigation errors • Data modeling errors We are more likely to develop feasible verification techniques Still, we need more help!

  19. Modularity: Model-View-Controller • Model-view-controller (MVC) architecture has become the standard way to structure web applications • Ruby on Rails, Zend Framework for PHP, CakePHP, Spring Framework for Java, Struts Framework for Java, Django for Python, … • MVC architecture separates • where and how the data is stored (the model) • from how it is presented (the views)

  20. Model-View-Controller (MVC) architecture • MVC consists of three modules • Model represents the data • View is its presentation to the user • Controller defines the way the application reacts to user input a=50% b=30% c=20% views model

  21. MVC framework for web applications • Model: • An abstract representation of the data stored in the backend database • Uses an object-relational mapping to map the application class structure to the back-end database tables • Views: • Responsible for rendering of the web pages, i.e., how is the data presented in user’s browser • Controllers: • Event handlers that process incoming user requests • They can update the data model, and create a new view to be presented to the user

  22. Exploiting MVC for verification • Modularity provided by MVC can be exploited in verification • For checking navigation properties • Focus on controllers • For checking input validation • Focus on controllers • For checking data model properties • Focus on the model

  23. Still, need more help • Even with • the separation of concerns • check one type of property at a time (navigation, input validation, data model) • and modularity • focus on only one component at a time (controller or the model) we still need more help! To completely automate the verification process • We need to find a way to map the code written in a programming language to something that an automated verification tool can check We have a verification model problem!

  24. How to get verification models? • The verification model is an abstraction of the behavior of the application • We obtain this abstraction using two basic approaches: • When possible we automatically extract a verification model from the code using automated abstraction + static analysis • Automated model extraction • If we cannot automatically extract the model, we ask the developer to write a model. In this case we have to enforce the specified model at runtime • Automated model enforcement

  25. Three verification techniques • Concern: Input validation checking • Module: Controller • Verification model extraction via abstraction: Dependency analysis to extract dependency graph • Verification technique: String analysis • Concern: Navigation correctness • Module: Controller • Verification model specification by developer: Automated enforcement of navigation model at runtime • Verification technique: Model checking • Concern: Data model integrity • Module: Data model • Verification model extraction via abstraction: • Verification technique: Bounded SAT based verification

  26. Making it work Separation of concerns + modularity + abstraction String analysis Input validation Model checking Navigation correctness Bounded SAT based verification Data integrity

  27. Input validation verification Application/ Scripts (Tainted) Dependency Graphs Parser/ Taint Analysis Reachable Attack Strings Attack Patterns Vulnerability Analysis Vulnerability Signature Signature Generation Sanitization Statements Patch Synthesis

  28. An example XSS vulnerability A PHP Example: 1:<?php 2: $www = $_GET[”www”]; 3: $l_otherinfo = ”URL”; 4: $www = preg_replace(”[^A-Za-z0-9 .-@://]”,””,$www); 5: echo ”<td>” . $l_otherinfo . ”: ” . $www . ”</td>”; 6:?> • Line 4 removes all characters that are not in {A-Za-z0-9 .-@:/} • However, “.-@”denotes all characters between “.” and “@” (including “<” and “>”) • Our string analysis automatically detects that there is a XSS vulnerability in line 5 <!sc+ri++pt! ... > <script ... >

  29. Automatically generated patch • Our string analysis generates a vulnerability signature that characterizes all possible input strings that can exploit the vulnerability • Our patch generation algorithm automatically generates a patch that removes the vulnerability 1: <?php P: if(preg match(’/[^ <]*<.*/’,$_GET[”www”])) $_GET[”www”] = preg replace(<,””,$_GET[”www”]); 2: $www = $_GET[”www”]; 3: $l_otherinfo = ”URL”; 4: $www = preg_replace(”[^A-Za-z0-9 .-@://]”,””,$www); 5: echo ”<td>” . $l_otherinfo . ”: ” .$www. ”</td>”; 6: ?>

  30. Experiments We applied our analysis to three open source PHP applications • Webches 0.9.0 (a server for playing chess over the internet) • EVE 1.0 (a tracker for player activity for an online game) • Faqforge 1.3.2 (a document management tool) • Attack patterns: • Σ∗<scriptΣ∗ (for XSS) • Σ∗ or 1=1 Σ∗ (for SQLI)

  31. Verification Results • We use (single, 2, 3, 4) indicates the number of detected vulnerabilities that have single input, two inputs, three inputs and four inputs

  32. Making it work Separation of concerns + modularity + abstraction String analysis Input validation Model checking Navigation correctness Bounded SAT based verification Data integrity

  33. Navigation verification • We ask developer to specify the high level navigation behavior as a navigation state machine • MVC frameworks typically use a hierarchical structure where actions are combined in the controllers and controllers are grouped into modules • We exploit this hierarchy to specify the navigation state machines as hierarchical state machines

  34. Navigation verification Navigation Properties Counter-example behavior Translator Navigation State Machine SMV Static Verification Verified Runtime Enforcement NSM Plugin (NSM Interpreter)

  35. Navigation verification experiments • We studied three real-world, freely available web applications: • BambooInvoice: invoice management application159,000 lines of code, 60 actions • Capstone: student project management system41,000 lines of code, 33 actions • Digitalus: content management system401,000 lines of code, 26 actions

  36. Specifying the NSM • We specified the NSMs manually, by exploring potential error sequences in applications • Amount of effort: Half a day per application (including taking screenshots, drawing the graph, etc.)

  37. Model checking NSMs • We used an existing model checker (SMV) to statically check navigation properties of NSMs • Some example navigation properties: • Once you login, the only way to go back to the login page is by traversing the logout page • Each controller has the 'index' action as its only entry point from other controllers • We can statically verify the NSMs with SMV model checker • Verification uses less than 4.4 MB of memory and takes less than 1 second

  38. Runtime enforcement of NSMs • PHP plugin for enforcement of NSMs at runtime • Intercepts page requests in an MVC application and validates them against the NSM • One line of code to insert in the application • Simple: 1,100 lines of PHP code (3% of the smallest application) • Average processing time when an action conforms to the NSM:

  39. Runtime enforcement of NSMs • Processing time when an action provokes a PHP warning (which the NSM-enabled application blocks): • ...and when an action provokes a PHP error:

  40. Making it work Separation of concerns + modularity + abstraction String analysis Input validation Model checking Navigation correctness Bounded SAT based verification Data integrity

  41. Data model verification • We worked on verification of static data model properties in Ruby-on-Rails applications • Rails uses active records for object-relational mapping • There are many options in active records declarations that can be used to specify constraints about the data model • Our goal: • Automatically analyze the active records files in Rails applications to check if the data model satisfies some properties that we expect it to satisfy • Approach: • Bounded SAT based verification • We automatically search for data model errors within a given scope

  42. Data Model Verification Active Records Translator Alloy Specification Counter-example data model instance Data Model Properties Alloy Analyzer Verified

  43. Data Model Verification Experiments • We used two open source Rails applications in our experiments: • TRACKS: An application to manage things-to-do lists • 6062 lines of code, 44 classes, 13 data model classes • Alloy translation: 301 lines • Fat Free CRM: Customer Relations Management software • 12069 lines of code, 54 classes, 20 data model classes • Alloy translation: 1082 lines

  44. Types of properties we checked • Relationship cardinality • Is it possible to have two accounts for one user? • Transitive relations • A book’s author is the same as the book’s edition’s author • Deletion properties • Deleting a user does not create orphan orders • We wrote 10 properties for TRACKS and 20 properties for Fat Free CRM

  45. Data Model Verification Experiments • Of the 30 properties we checked 7 of them failed • For example, in TRACKS Note’s User can be different than Note’s Project’s User

  46. Conclusions • Web application dependability is a very important problem • Using automated verification we can find and remove errors in web application before they are deployed • In order to develop feasible automated verification techniques we exploit the MVC architecture and the principles of modularity, abstraction and separation of concerns • At minimum, the developer has to specify the correctness properties (e.g. attack patterns) • In some cases, the developer may also need to specify desired behavior (e.g. navigation)

  47. Future work • Handle more concerns • Maximize automation • Mobile applications

More Related