Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

Nick Feamster CS 6262 Spring 2009
Cross Site Scripting (XSS)
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
1/7 ITApplications XML Module Session 8: Introduction to Programming with XML.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the Creative Commons Attribution-ShareAlike.
0 The Past, Present and Future of XSS Defense Jim Manico 2011 OWASP Brussels.
An Introduction to XML Based on the W3C XML Recommendations.
Tutorial 6 Creating a Web Form
The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application.
A NTI S AMY J AVA I NTRODUCTION Wang Wenjun June 2011.
©2009 Justin C. Klein Keane PHP Code Auditing Session 5 XSS & XSRF Justin C. Klein Keane
Seattle Drupal Clinic Introduction to Drupal and Web Content Management.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the Creative Commons Attribution-ShareAlike.
WebGoat & WebScarab “What is computer security for $1000 Alex?”
Cross Site Scripting a.k.a. XSS Szymon Siewior. Disclaimer Everything that will be shown, was created for strictly educational purposes. You may reuse.
HTML5 and CSS3 Illustrated Unit B: Getting Started with HTML
Blackbox Reversing of XSS Filters Alexander Sotirov ekoparty 2008.
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.
Introduction to the OWASP Top 10. Cross Site Scripting (XSS)  Comes in several flavors:  Stored  Reflective  DOM-Based.
Tutorial 3: Adding and Formatting Text. 2 Objectives Session 3.1 Type text into a page Copy text from a document and paste it into a page Check for spelling.
Drupal Workshop Introduction to Drupal Part 1: Web Content Management, Advantages/Disadvantages of Drupal, Drupal terminology, Drupal technology, directories.
Creating a Simple Page: HTML Overview
4.1 JavaScript Introduction
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
XML introduction to Ahmed I. Deeb Dr. Anwar Mousa  presenter  instructor University Of Palestine-2009.
Prevent Cross-Site Scripting (XSS) attack
Chapter 16 The World Wide Web Chapter Goals ( ) Compare and contrast the Internet and the World Wide Web Describe general Web processing.
Chapter 16 The World Wide Web Chapter Goals Compare and contrast the Internet and the World Wide Web Describe general Web processing Describe several.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
CSCI 6962: Server-side Design and Programming Secure Web Programming.
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.
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
JavaScript, Fourth Edition
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.
 2002 Prentice Hall, Inc. All rights reserved.2 Chapter 2 — Introduction to HyperText Markup Language 4: Part I Outline 2.1Introduction 2.2Markup Languages.
Learning Web Design: Chapter 4. HTML  Hypertext Markup Language (HTML)  Uses tags to tell the browser the start and end of a certain kind of formatting.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
XML About XML Things to be known Related Technologies XML DOC Structure Exploring XML.
Online Translation Service Capstone Design Eunyoung Ku Jason Roberts Jennifer Pitts Gregory Woodburn Kim Tran.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
ECA 228 Internet/Intranet Design I XSLT Example. ECA 228 Internet/Intranet Design I 2 CSS Limitations cannot modify content cannot insert additional text.
Copyright 2007, Information Builders. Slide 1 Understanding Basic HTML Amanda Regan Technical Director June, 2008.
© Copyright 2013 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice. 1 RubyJax Brent Morris/
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
Seattle Drupal Clinic Introduction to Drupal Part 1: Web Content Management, Advantages/Disadvantages of Drupal, Drupal terminology.
Introduction to XML This presentation covers introductory features of XML. What XML is and what it is not? What does it do? Put different related technologies.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
Cross Site Scripting and its Issues By Odion Oisamoje.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
ICM – API Server & Forms Gary Ratcliffe.
Introduction to HTML. _______________________________________________________________________________________________________________ 2 Outline Key issues.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
XML Notes taken from w3schools. What is XML? XML stands for EXtensible Markup Language. XML was designed to store and transport data. XML was designed.
By Collin Donaldson. Hacking is only legal under the following circumstances: 1.You hack (penetration test) a device/network you own. 2.You gain explicit,
The OWASP Foundation OWASP XSS Remediation Cassia Martin Romain Gaucher April 7 th, 2011.
Enhance Your Page Load Speed And Improve Traffic.
SlideSet #20: Input Validation and Cross-site Scripting Attacks (XSS) SY306 Web and Databases for Cyber Operations.
Building Secure ColdFusion Applications
CSCE 548 Student Presentation Ryan Labrador
Getting Started with CSS
Unit 4 Representing Web Data: XML
Chapter 7 Representing Web Data: XML
Web Programming A different world! Three main languages/tools No Java
Chapter 16 The World Wide Web.
Cross-Site Scripting Attack (XSS)
Presentation transcript:

Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP Foundation OWASP Validating Rich User Content: Using OWASP AntiSamy Jason Li AppSec India Conference August 20 th, 2008

OWASP Talk Overview  Why do we need rich content?  What strategies exist for validating rich content?  What is OWASP AntiSamy?  How does it work?  Demo  Project Status

OWASP Why Do We Need Rich Content?  Websites need user created content:  User generated content can contain XSS attacks User Customized Profiles (ex. MySpace, FaceBook) Public Listings (ex. eBay, Craigslist) Content Management Systems (ex. Drupal, Magnolia) Rich Comments (ex. Blogs, News Sites)

OWASP What is XSS?  General Problem:  Site takes input that is included in HTML sent to user  Attacker crafts malicious script as the input  Victim has malicious script run in browser  Game Over.  Two main types of XSS:  Reflected XSS – attacker tricks victims into clicking a link containing a malicious attack  Stored XSS – attacker stores an attack that victims later stumble upon

OWASP Reflected XSS - Illustrated Check out this cool link!!! alert(‘bang!’) / Instant Message

OWASP … You searched for: alert(‘bang!’) … HTTP / HTTPS Reflected XSS - Illustrated GET /search? alert(‘bang!’) 2.0P/1.1 User-Agent: InterOperFireFari/4.04 Cookie: SESSION_COOKIE: QXJzaGFuIGlzIG15IGhlcm8=; HTTP / HTTPS

OWASP POST /comment? alert(‘bang!’) 2.0P/1.1 User-Agent: InterOperFireFari/4.04 Cookie: SESSION_COOKIE: QXJzaGFuIGlzIG15IGhlcm8=; HTTP / HTTPS Stored XSS - Illustrated … Headline News (Waffles, BE): … Says: alert(‘bang!’) … HTTP / HTTPS HTTP / HTTPS

OWASP But That’ll Never Happen to Me!  GMail has cookies stolen via XSS in Google Spreadsheets (April 2008)  U.S. Presidential Candidate Barrack Obama has supporters redirected to Hillary Clinton’s site via XSS (April 2008)  MySpace profiles hijacked via Samy Worm (October 2005)

OWASP The Samy Worm  MySpace is a popular social networking website  Link with “friends” (mutually authorized)  Users create custom profiles  Includes use of HTML  JavaScript, quotes, and other potentially dangerous characters stripped out by MySpace filters

OWASP The Samy Worm (continued)  Samy wanted to make friends  Used his profile to store an XSS attack  Circumvents JavaScript stripping with: “ java\nscript ”  Generates quotes using: String.fromCharCode(34)

OWASP The Samy Worm (continued)  Anyone viewing Samy’s profile:  Made Samy their “friend” (actually, their “hero”)  Had their profile changed to store and perpetuate the attack  10 hours – 560 friends, 13 hours – 6400, 18 hours – 1,000,000, 19 hours – site is down

OWASP Strategies That Don’t Work  Use HTML Encoding!  Convert to < and >  Encoding removes tags and formatting  Just strip out tags (i.e. blacklist)!  Requires constant update  Provides low assurance (ex. Samy Worm)  Use a JavaScript editor (ex. TinyMCE or FCKEditor)!  Client side validation easily circumvented  Requires matching server side validation

OWASP Strategies That Do Work  Use Another Markup Language  Encode Text and Decode Selected Tags  Use XSD For Validation  Use OWASP AntiSamy 13

OWASP Use Another Markup Language  Examples include BBCode and WikiText  Create an alternate set of markup tags:  [b]bold text[/b]  [i]italic text[/i]  [url=  Markup parser converts this to:  bold text  italic text  Links 14

OWASP Use Another Markup Language (cont)  Advantages:  Effectively a whitelist of “allowed” formatting tags  Several existing markup languages already available  Disadvantages:  Not as rich as HTML  Forces users to learn yet another markup language 15

OWASP Encode Text and Decode Selected Tags  Suggested by Chris Shiflett (  HTML Encode all input  For a pre-defined set of tags, run decoding  Ex: allow and tags by decoding <em> and <strong> This text has alert() tags ! This <strong>text</strong> has <script>alert()</script> <em>tags</em>! This text has <script>alert() </script> tags !

OWASP Encode Text and Decode Selected Tags (cont)  Advantages:  Ensures all output is encoded  Whitelist specification of allowed tags  Disadvantages:  Difficult to properly decode attributes  Must enumerate all desired tags 17

OWASP Use XSD For Validation  Suggested by Petko Petkov (a.k.a. pdp) ( )  Convert to HTML to XML  Create an XSD defining allowed HTML elements  Verify XML against XSD 18

OWASP Use XSD For Validation (cont)  Advantages:  Flexible implementation (wide variety of parsers)  Whitelist specification of allowed tags  Allows conditionally nested tags  Disadvantages:  No feedback provided to user  Must create XSD for all HTML elements 19

OWASP Use OWASP AntiSamy  What is OWASP AntiSamy?  An HTML/CSS validation tool and API  Provides safe default whitelist of HTML/CSS  Provides user-friendly error messages  Started as an OWASP Spring of Code 2007  Currently a Beta Status Project  Project lead by Arshan Dabirsiaghi  Core Developers:  Jason Li (CSS)  Jerry Hoff (.NET)

OWASP How Does It Work? (cont) ConvertScanRespondSerialize NekoHTML converts to XML Allows creation of DOM Prevents fragmentation attacks Provides sanitized HTML Scan each node against policy file Policy file defines corresponding response for each tag Validate (special CSS behavior) Truncate Filter Remove Serialize output as HTML or XHTML

OWASP How Does It Work? (cont) ParseValidateSerializeRecurse Parse CSS using SAC (Simple API for CSS) SAC is event-driven (a la SAX) Validate selector and id names against policy Validate property values against policy Remove failed properties and selectors Canonicalize style output Import and optionally embed referenced style sheets Repeat validation process for imported stylesheets

OWASP How Does It Work? (cont) body p img src=“…” script src=“…” (text) b onclick=“…” (text) This is so cool!! Clean via Neko

OWASP How Does It Work? (cont) body p img src=“…” script src=“…” (text) b antisamy-policy.xml onclick=“…”

OWASP How Does It Work? (cont)  Clean Result:  Error Messages: The onclick attribute of the b tag has been removed for security reasons. This removal should not affect the display of the HTML submitted. The script tag has been removed for security reasons. This is so cool!!

OWASP How Do I Use It?  AntiSamy class:  scan(taintedHtml[, policy]) – CleanResults  CleanResults class:  getCleanHTML() – String  getCleanXMLDocumentFragment() – DocumentFragment  getScanTime() – double  getErrorMessages() – ArrayList

OWASP How Do I Use It? (cont)

OWASP That’s Nice, But...  Policy allows customization based on site policy  Policy file consists of:  Directives  Common Regular Expressions  Common Attributes  Global Tag Attributes  Tag Rules  CSS Rules

OWASP That’s Nice, But...  I don’t want users to:  Have offsite images  Use HTML tags  I don’t want to do any work  Standard policy file is safe by default  Multiple policy files for typical use cases available (eBay, MySpace, Slashdot, anything goes)

OWASP Where Do I Get It?  Project Homepage:  Source Code:  Thousands of downloads of AntiSamy libraries  Used at several Fortune 500 companies

OWASP OWASP AntiSamy Demo

OWASP JavaScript Demos  Standard XSS Attacks  RSnake’s cheat sheet  Solution: Already defended against in default policy files

OWASP Absolute Div Overlay Demo  Create a div in our profile that overlays the entire page (or a subsection)  Extremely effective phishing vector  SSL certificate is valid  Look and feel matches expectations  Solution: Add a stylesheet rule in the policy file to whitelist allowed position values

OWASP Div Clobbering Demo  Redefine an existing div “above” our profile  Most stylesheets defined at the beginning of the page in or “at the top”  Solution: Blacklist the IDs and selector names used by site to prevent the user from modifying them

OWASP Base Hijacking Demo  Insert a tag to hijack internal resources  Used to define a base for all relative URLs on the page  Solution: remove tag from policy file

OWASP Current Project Status  Version 1.2 released April 17, 2008  Java 1.4 compatible  HTML entities recognized using (X)HTMLSerializer  Added XHTML support  Input/Output encoding can now be specified  Policy files internationalized  Internationalized error messages for English, Italian, Portuguese, Russian and Chinese  Incorporated into OWASP ESAPI project

OWASP Future Roadmap  Support For Other languages: .NET version in development as part of OWASP Summer of Code 2008  ColdFusion support through native Java interface  Features Under Development:  More internationalization of error messages  Full CSS2 support

OWASP Thanks  Dhruv Soi and Puneet Mehta for inviting me to speak  Arshan Dabirsiaghi for starting the project  Jeff Williams, Gareth Heyes, Michael Coates, Joel Worral, Raziel Alvarez for helping improve AntiSamy  OWASP for its continued support of the project

OWASP Questions?