230 likes | 362 Views
Automated Identification of Parameter Mismatches in Web Applications. William G.J. Halfond and Alessandro Orso Georgia Institute of Technology. End Users. Web Server. Example Web Application. Web Application. Initial Visit. searchpage.jsp. dosearch.jsp.
E N D
Automated Identification of Parameter Mismatches in Web Applications William G.J. Halfond and Alessandro Orso Georgia Institute of Technology
End Users Web Server Example Web Application Web Application Initial Visit searchpage.jsp dosearch.jsp http://host/dosearch.jsp?search=bagels&business=bakery Search Results
Generating Invocations: searchpage.jsp void service(Request req) { 1. print( "<html><body><h1>Business Search</h1>" ); 2. print( "<form method=GET action=dosearch.jsp>" ); 3. print( "<input type=text name=search><br>" ); 4. if (conf.searchPref.equals( "zip" )) { 5. print( "<font color=black>Zip:</font>" ); 6. print( "<input type=text name=zip><br>" ); 7. } else if(conf.searchPref.equals( "type" )) { 8. printTypes( “business” ); 9. } else { 10. print( "<font color=black>City:</font>" ); 11. print( "<input type=text name=city><br>" ); 12. print( "<font color=black>State:</font>" ); 13. print( "<input type=text name=state><br>" ); 14. } 15. print( "<input type=hidden name=searchPref value=" + conf.searchPref + ">"); 16. print( "<input name=Submit type=submit>" ); 17. print( "</form></body></html>" ); 18. }
search • searchpref • zip • search • searchpref • busines • search • searchpref • state Receiving Invocations: dosearch.jsp void service(Request req) { 1. String dbQuery = "select businesses from db where " ; 2. String search = req.getParameter( "search" ); 3. String dbQuery += "name like '" + search + "' " ; 4. String searchType = req.getParameter( "searchPref" ); 5. if (searchType.equals( "zip" )) { 6. String zip = req.getParameter( "zip" ); 7. dbQuery+= "zip=" +zip; 8. } else if(searchType.equals( "type" )) { 9. String type = req.getParameter( "busines" ); 10. dbQuery+= "type=" +type; 11. } else { 12. String state = req.getParameter( "state" ); 13. dbQuery+= "state=" +state; 14. } 15. ResultSet results = execute(dbQuery); 16. print(results);
Web Application Errors in Example Servlets searchpage.jsp dosearch.jsp Interfaces search, searchpref, zip search, searchpref, busines search, searchpref, state Invocations search, searchpref, zip search, searchpref, business search, searchpref, city, state Error #1: Mispelling Error #2: Ignored Parameter
Current Approaches • Compilers • HTML validators • Developer specification • Manual inspection • Traditional testing
Our Approach • Identify accepted interfaces • Identify interface invocations • Verify invocations against accepted interfaces
Web Application HTML Servlets Step 1: Identify Accepted Interfaces WAM (Interface Discovery) [FSE 2007] Accepted Interfaces
Step 2: Identify Interface Invocations 1. Direct – via API calls String urlString = “dosearch.jsp?search=bagels” URLConnectionurl = new URLConnection(); InputStream response = url.open(urlString); 2. Indirect – via user client
Direct Invocations String urlString = “dosearch.jsp?search=bagels” URLConnectionurl = new URLConnection(); InputStream response = url.open(urlString); • Scan code to find direct invocation API calls • Identify parameter containing invocation • Perform string analysis on parameter • Parse the URL strings
Web Application HTML Servlets Indirect Invocations: Overview Analysis to Identify Indirect Invocations Indirect Interface Invocations Servlet • For each method m: • Identify HTML content of each output statement • Group content along a path into HTML fragments • Intermediate parsing of HTML fragments • Add HTML fragment to m’s summary • Combine summaries up to root method
Indirect Invocations: Example 19. voidprintTypes(String name) { 20. print( "<select name=“ + name + “>" ); 21. optValues[] = [ "Jewelry", "Bakery", "Restaurant" ]; 22. for (String opt :optValues) { 23. print( "<option value=" + opt + ">" + opt + "</option>" ); 24. } 25. print( "</select><br>" ); 26. } HTML Fragment for Method printTypes <select name=1> <option value=Jewelry>Jewelry</option> <option value=Bakery>Bakery</option> <option value=Restaurant>Restaurant</option> </select> <br>
Indirect Invocations: Example <html><body> <h1>Business Search</h1> <form method=GET action=dosearch.jsp> <font color=black>Search terms:</font> <input type=text name=search> <font color=black>City:</font> <input type=text name=city> <font color=black>State:</font> <input type=text name=state> <br> <input type=hidden name=searchPref value=zip> <input name=Submit type=submit> </form> </body></html> voidservice(Request req) { 1. print( "<html><body><h1>Business Search</h1>" ); 2. print( "<form method=GET action=dosearch.jsp>" ); 3. print( "<input type=text name=search><br>" ); 4. if (conf.searchPref.equals( "zip" )) { 5. print( "<font color=black>Zip:</font>" ); 6. print( "<input type=text name=zip><br>" ); 7. } else if(conf.searchPref.equals( "type" )) { 8. printTypes( “business” ); 9. } else { 10. print( "<font color=black>City:</font>" ); 11. print( "<input type=text name=city><br>" ); 12. print( "<font color=black>State:</font>" ); 13. print( "<input type=text name=state><br>" ); 14. } 15. print( "<input type=hidden name=searchPref value=" + conf.searchPref + ">"); 16. print( "<input name=Submit type=submit>" ); 17. print( "</form></body></html>" ); 18. } <html><body> <h1>Business Search</h1> <form method=GET action=dosearch.jsp> <font color=black>Search terms:</font> <input type=text name=search> <font color=black>Type:</font> <select name=business> <option value=Bakery>Bakery</option> <option value=Jewelry>Jewelry</option> <option value=Restaurant>Restaurant</option> </select> <br> <input type=hidden name=searchPref value=zip> <input name=Submit type=submit> </form> </body></html> <html><body> <h1>Business Search</h1> <form method=GET action=dosearch.jsp> <font color=black>Search terms:</font> <input type=text name=search> <font color=black>Zip:</font> <input type=text name=zip> <input type=hidden name=searchPref value=zip> <input name=Submit type=submit> </form> </body></html>
Step 3: Verification dosearch.jsp For each invocation: verify that its target has a matching interface. search, searchpref, state search, searchpref, zip search, searchpref, busines • Interface Invocations • search, searchpref, zip • search, searchpref, city, state • search, searchpref, business
Empirical Evaluation Research Questions: • How efficient is our analysis when run on real web applications? • What percentage of the reported parameter mismatches represent actual errors in the web applications?
Tool Implementation • Written in Java • Accepted Interfaces => WAM • Interface Invocations => leveraged Soot, JSA, HTML Parser • Targets Java Enterprise Edition (JEE) • Analyzes bytecode and outputs mismatches
Subject Applications • Applications available via SourceForge and GotoCode • Mix of commercial and open-source development
RQ1: Efficiency • Overall time ranges from 10 minutes to 5 hours • 50-80% of time spent in call graph building • Manual inspection of four servletstook 12 hours
RQ2: Precision • Ran WAIVE on four subject applications • Manually inspected each reported parameter mismatch • Classified each mismatch • Actual error or false positive • According to root cause
Errors Identified • Effect of errors varied widely, but all caused significant problems • Underlying human error ranged from mistyping to complex logic errors
False Positives • Dominant root causes addressable by engineering • WAM precision can be significantly improved
Summary and Future Work • Technique to identify parameter mismatches • Implemented in prototype tool, WAIVE • Evaluation • Identified 151 mismatches • Only 18 false positives • Future work: Expand verification to include type checking
Thank You. William G.J. Halfond Georgia Tech whalfond@cc.gatech.edu