THE BROKEN WEB A Systematic Analysis of XSS Sanitization in Web Application Frameworks.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

PHP Form and File Handling
Cross-Site Scripting Issues and Defenses Ed Skoudis Predictive Systems © 2002, Predictive Systems.
Nick Feamster CS 6262 Spring 2009
PHP I.
Hossain Shahriar Mohammad Zulkernine. One of the worst vulnerabilities in web applications It involves the generation of dynamic HTML contents with invalidated.
Context-Sensitive Auto-Sanitization In Web Templating Languages Using Type Qualifiers Prateek Saxena UC Berkeley Mike Samuel Google Dawn Song UC Berkeley.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
JSP1 Java Server Pages (JSP) Introducing JavaServer Pages TM (JSP TM ) JSP scripting elements.
Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
HTML 5 and CSS 3, Illustrated Complete Unit L: Programming Web Pages with JavaScript.
The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application.
©2009 Justin C. Klein Keane PHP Code Auditing Session 5 XSS & XSRF Justin C. Klein Keane
An Evaluation of the Google Chrome Extension Security Architecture
COMP 321 Week 12. Overview Web Application Security  Authentication  Authorization  Confidentiality Cross-Site Scripting Lab 12-1 Introduction.
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
Chapter 9 Web Applications. Web Applications are public and available to the entire world. Easy access to the application means also easy access for malicious.
DT228/3 Web Development JSP: Directives and Scripting elements.
CS 290C: Formal Models for Web Software Lecture 1: Introduction Instructor: Tevfik Bultan.
Introduction to the OWASP Top 10. Cross Site Scripting (XSS)  Comes in several flavors:  Stored  Reflective  DOM-Based.
CROSS SITE SCRIPTING..! (XSS). Overview What is XSS? Types of XSS Real world Example Impact of XSS How to protect against XSS?
Handling Security Threats in Kentico CMS Karol Jarkovsky Sr. Solution Architect Kentico Software
PHP: Introduction By Trevor Adams.
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Form Handling.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
Cosc 4765 Server side Web security. Web security issues From Cenzic Vulnerability report
Prevent Cross-Site Scripting (XSS) attack
CSCI 6962: Server-side Design and Programming Secure Web Programming.
Web Application Access to Databases. Logistics Test 2: May 1 st (24 hours) Extra office hours: Friday 2:30 – 4:00 pm Tuesday May 5 th – you can review.
BLUEPRINT: Robust Prevention of Cross-site Scripting Attacks for Existing Browsers Mike Ter Louw, V.N. Venkatakrishnan University of Illinois at Chicago.
Chapter 9 Web Applications. Web Applications are public and available to the entire world. Easy access to the application means also easy access for malicious.
November 13, 2008 Ohio Information Security Forum Attack Surface of Web Applications James Walden Northern Kentucky University
Copyright 2007 © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Krishna Mohan Koyya Glarimy Technology Services
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
Top Five Web Application Vulnerabilities Vebjørn Moen Selmersenteret/NoWires.org Norsk Kryptoseminar Trondheim
School of Computing and Information Systems CS 371 Web Application Programming Security Avoiding and Preventing Attacks.
© Copyright 2013 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice. 1 RubyJax Brent Morris/
Website Development with PHP and MySQL Saving Data.
ITCS373: Internet Technology Lecture 5: More HTML.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Introduction to JavaScript CS101 Introduction to Computing.
Web Security Lesson Summary ●Overview of Web and security vulnerabilities ●Cross Site Scripting ●Cross Site Request Forgery ●SQL Injection.
PHP Error Handling & Reporting. Error Handling Never allow a default error message or error number returned by the mysql_error() and mysql_errno() functions.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
Since you’ll need a place for the user to enter a search query. Every form must have these basic components: – The submission type defined with the method.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
CGS 3066: Web Programming and Design Spring 2016 PHP.
World Wide Web has been created to share the text document across the world. In static web pages the requesting user has no ability to interact with the.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,
Radoslav Georgiev Telerik Corporation
SlideSet #20: Input Validation and Cross-site Scripting Attacks (XSS) SY306 Web and Databases for Cyber Operations.
Group 18: Chris Hood Brett Poche
An Introduction to Web Application Security
Static Detection of Cross-Site Scripting Vulnerabilities
CS 371 Web Application Programming
PHP / MySQL Introduction
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Exploring DOM-Based Cross Site Attacks
Presentation transcript:

THE BROKEN WEB A Systematic Analysis of XSS Sanitization in Web Application Frameworks

Executive summary Web page processing analyzed in detail Sanitization is quite complex Context sensitive 14 WEB frameworks analyzed None handle sanitization properly In some cases they give a false sense of security because the algorithm is wrong

HTTP background GET le.html Client sends request to server ple.html Sample file This is a sample Server locates and sends back file Sample file This is a sample Client displays file Basic HTTP operation

HTTP background GET /sample.php Client sends request Sample.php: Sample file ’; echo ‘ This is a sample ’; ?> Server executes script Sample file This is a sample Server returns generated file Sample file This is a sample Client displays file Server side scripting

HTTP background POST /sample.php?name =Mr. Dummy&soc= &credit= Client sends data to server Sample.php: <?php # save data somewhere …. echo ‘ Now I own you. ’ ?> Server executes script Please send me your important financial information: Name: Mr. Dummy__ Soc: Credit card number: SUBMIT User fills in fields and presses ‘Submit’ Form management Now I own you. Server sends response page to client

HTTP background Client side scripting My First Web Page document.write(" " + Date() + " ");

HTTP background Client side scripting My First Web Page Tue Feb :28:07 GMT-0500 (EST)

HTTP background Client side scripting My First Web Page Tue Feb :28:07 GMT-0500 (EST)

XSS attack Server side code prints text entered by a user from an earlier session. Consider this code: <?php echo ‘ Note from ‘.$user.’ ’ echo ‘ ’.$note.’ ’ ?> Suppose $note contains document.write(" ") The sky is falling.

XSS attack The result is that the following is sent to your browser: Note from Mr. Apocalypse document.write(" ") The sky is falling.

XSS attack Your browser displays the following: Note from Mr. Apocalypse [img] The sky is falling. And the attacker has gotten your cookie.

XSS attack The attacker simply needed to enter this script on the screen used to post the note. Logged in as: Mr. Apocalypse Text of message to post: document.write(" ") The sky is falling._______ Any website that echoes back a user input can be used for an XSS attack.

XSS attack The following can be used to obtain the cookie for your bank account: document.location=' me= document.write(" ") '

Sanitization One solution is to escape out sensitive characters document.write(" ") becomes <script>document.write(“<img src= + document.cookie + “>”)</script> Problem: sanitization needs to be done in a context sensitive manner and the rules are very complex

Web page parsing

Challenge 1: context sensitivity Consider this code: echo ‘ ’.$note.’ ’ Here one can replace ‘ with > to block attacks. However consider: echo ‘ ’ Consider the following url: picture.jpg’ onLoad=‘document.location=…”

Challenge 2: Sanitizing nested contexts Consider this piece of php code: echo ‘ var x = ‘.$UNTRUSTED_DATA.’... ’ One needs to block both the possibility of a and that of a ‘ to prevent attacks

Challenge 3: Browser transductions Consider:... hidden comment... Even if all the “ characters are replaced with &quot, HTML 5 removes the encoding before passing the text to Javascript.

Challenge 4: Dynamic code Consider this program: function foo(untrusted) { document.write(" "); } Evaluation generates html code that will repeat the call to the function.

Challenge 5: Character set issues +ADw- maps to < in UTF-7 The sanitizer needs to recognize the character set conversion

Challenge 6: everything else MIME based XSS Browser bugs Capability leaks Parsing inconsistencies Browser extensions Adobe flash is fairly buggy

Evaluation of web frameworks and applications Subjects 14 popular web application frameworks 8 popular php applications Evaluation Auto-sanitization and/or sanitization libraries Dynamic sanitization handling

Auto sanitization 7 of 14 support auto sanitization 4 of 7 of these perform context insensitive sanitization which is inherently unsafe 14.8%-33.6% of output sinks fail to be protected by auto sanitization in 10 popular Django application

Context sensitive sanitization Performed by 3 of 7 frameworks GWT, Google Clearsilver, and Google Ctemplate Involved a runtime parser that checked the context and applied the appropriate sanitization function User needs to mark untrusted variables No detailed analysis of reliability I assume they worked reasonably well

Manual sanitization Prone to error Variables missed Wrong sanitization function used

Dynamic code evaluation Perform appropriate runtime checks before printing untrusted strings Generally not supported by frameworks Four frameworks provided static sanitization of untrusted strings within the context of Javascript constants

DOM based errors Javascript can actually reference the content of a web page This page changes itself Original content document.anchors[0].innerHTML=“New content”;

DOM based errors Javascript can actually reference the content of a web page This page changes itself New content document.anchors[0].innerHTML=“New content”;

DOM based errors Consider this code: text = element.getAttribute(’title’); //... elided... desc = create_element(’span’, ’bottom’); desc.innerHTML = text; tooltip.appendChild(desc); This code read an element from the HTML, destroy escaping and reinsert it elsewhere To avoid bug: use of innerText to write or innerHTML to read

DOM based errors Ignored by frameworks Cause many XSS vulnerabilities

Expressiveness of contexts in web applications 8 php applications analyzed KLOC All applications emit untrusted data into all contexts Applications sometimes employ different sanitizers for the same context General conclusion: frameworks do not provide sufficient sanitization support

Manual sanitization expressiveness 9 of 14 frameworks do not support contexts other than the generic HTML 4 provided sanitizers for Javascript string context 1 framework provided a sanitizer for Javascript number and boolean contexts None allow for sanitization of Javascript code Only one framework allowed customization of the sanitizer within a context—the others had a pre-packaged sanitizer for all contexts

Correctness of sanitizers Sanitizers prone to error In frameworks they usually work on a “whitelist” model in which only structures following specific patterns are allowed One framework uses a “blacklist” model in which specific strings are forbidden Frameworks rely on canonical form into which all output is formatted to simplify sanitizers The authors conclude that the “whitelist” approach should be researched. The “blacklist” approach is too error prone.

Related work XSS analysis and defense Server side code errors Javascript code errors Research identifies vulnerabilities Untrusted data showing up in output Improper sanitization Server side solutions BLUEPRINT, SCRIPTGARD, XSS-GUARD Formalize web model to design sanitizers Client side XSS-Auditor Analyze browser reference patterns to try and identify attacks Does not separate trusted and untrusted data Studies in sanitizer correctness Manual process of adding sanitization is error prone None provide a good underlying model for sanitizers Taint tracking and security typed languages

Paper’s conclusions Current frameworks do not properly manage sanitization The paper suggests a future direction of producing a formal model of the browser’s behavior

Some later work Saxena developed php analysis tools Model checker – symbolic execution of php to try and find dangerous code Static analysis—tries to identify and incorporate sanitizers based on the context of a print Probably the better approach Needs to be integrated with some sort of dynamic analysis

Discussion questions What is the best approach for solving XSS? In addition to technical issues, what practical issues need to be addressed to get a solution deployed? For example, asking everyone to rewrite their php code is going to be difficult. Should the government get involved in regulating web sites to make sure basic protection standards are upheld?

XSS attack game 2 teams Source code available from Look for $_GET and $_POST variables for user input Use MAMP to run