Web Application Security
A Beginners Guide
Bryan Sullivan
Vincent Liu
Copyright 2012 by The McGraw-Hill Companies. All rights reserved. Except as permitted under the United States Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher.
ISBN: 978-0-07-177612-7
MHID: 0-07-177612-5
The material in this eBook also appears in the print version of this title: ISBN: 978-0-07-177616-5, MHID: 0-07-177616-8.
All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringement of the trademark. Where such designations appear in this book, they have been printed with initial caps.
McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in corporate training programs. To contact a representative please e-mail us at bulksales@mcgraw-hill.com.
Information has been obtained by McGraw-Hill from sources believed to be reliable. However, because of the possibility of human or mechanical error by our sources, McGraw-Hill, or others, McGraw-Hill does not guarantee the accuracy, adequacy, or completeness of any information and is not responsible for any errors or omissions or the results obtained from the use of such information.
TERMS OF USE
This is a copyrighted work and The McGraw-Hill Companies, Inc. (McGraw-Hill) and its licensors reserve all rights in and to the work. Use of this work is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hills prior consent. You may use the work for your own noncommercial and personal use; any other use of the work is strictly prohibited. Your right to use the work may be terminated if you fail to comply with these terms.
THE WORK IS PROVIDED AS IS. McGRAW-HILL AND ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. McGraw-Hill and its licensors do not warrant or guarantee that the functions contained in the work will meet your requirements or that its operation will be uninterrupted or error free. Neither McGraw-Hill nor its licensors shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in the work or for any damages resulting therefrom. McGraw-Hill has no responsibility for the content of any information accessed through the work. Under no circumstances shall McGraw-Hill and/or its licensors be liable for any indirect, incidental, special, punitive, consequential or similar damages that result from the use of or inability to use the work, even if any of them has been advised of the possibility of such damages. This limitation of liability shall apply to any claim or cause whatsoever whether such claim or cause arises in contract, tort or otherwise.
For Amy. Im proud to be your husband and partner but even prouder to be your best friend.
Bryan
To Yo, the best sister in the universe.
Vincent
About the Authors
Bryan Sullivan is a security researcher at Adobe Systems, where he focuses on web and cloud security issues. He was previously a program manager on the Microsoft Security Development Lifecycle team and a development manager at HP, where he helped to design HPs vulnerability scanning tools, WebInspect and DevInspect.
Bryan spends his time in Seattle, Washington, where he enjoys all of the perks of living in the Pacific Northwest: the excellent coffee, the abundant bicycle lanes, the superb Cabernet Sauvignon. Bryan lives with his wife, Amy, their cat, Tigger, and an as-yet-unnamed new bundle of joy who will be joining the family sometime around February 14, 2012.
Vincent Liu is a Managing Partner at Stach & Liu, a security consulting firm providing IT security services to the Fortune 1000 and global financial institutions as well as U.S. and foreign governments. Before founding Stach & Liu, Vincent led the Attack & Penetration and Reverse Engineering teams for the Global Security unit at Honeywell International. Prior to that, he was a consultant with the Ernst & Young Advanced Security Centers and an analyst at the National Security Agency.
Vincent is a sought-after speaker and has presented his research at conferences including BlackHat, ToorCon, InfoSec World, SANS, and Microsoft BlueHat. He has coauthored several books including Hacking Exposed Wireless first and second editions, and Hacking Exposed Web Applications, Third Edition. Vincent holds a Bachelor of Science and Engineering from the University of Pennsylvania with a major in Computer Science and Engineering and a minor in Psychology.
About the Technical Editor
Michael Howard is a principal cybersecurity architect in the Public Sector Services group. Prior to that, he was a principal security program manager on the Trustworthy Computing (TwC) Groups Security Engineering team at Microsoft, where he was responsible for managing secure design, programming, and testing techniques across the company.
Howard is an editor of IEEE Security & Privacy, a frequent speaker at security-related conferences, and he regularly publishes articles on secure coding and design. Howard is the coauthor of six security books, including the award-winning Writing Secure Code, 19 Deadly Sins of Software Security, The Security Development Lifecycle, Writing Secure Code for Windows Vista, and his most recent release, 24 Deadly Sins of Software Security.
Contents
HTML Element
JSON and JSONP
iframes and JavaScript document.domain
Adobe Flash Player Cross-Domain Policy File
Microsoft Silverlight
XMLHttpRequest (Ajax) and Cross-Origin Resource Sharing
XDomainRequest
Final Thoughts on the Same-Origin Policy
6 Browser Security Principles: Cross-Site Scripting and Cross-Site Request Forgery
Cross-Site Scripting
Cross-Site Scripting Explained
Reflected XSS
POST-Based Reflected XSS
Stored XSS
Local XSS
Another Variation: HTML Injection
XSS Defense: Encoding Output
XSS Defense: Sanitizing Input