Pushing CSP to PROD Case Study of a Real-World Content- Security Policy Implementation.

Slides:



Advertisements
Similar presentations
CS193H: High Performance Web Sites Lecture 10: Rule 6 – Put Scripts at the Bottom Steve Souders Google
Advertisements

Protecting Browser State from Web Privacy Attacks Collin Jackson, Andrew Bortz, Dan Boneh, John Mitchell Stanford University.
The OWASP Foundation Web Application Security Host Apps Firewall Host Apps Database Host Web serverApp serverDB server Securing the.
0 The Past, Present and Future of XSS Defense Jim Manico 2011 OWASP Brussels.
Protecting Browsers from Cross-Origin CSS Attacks Lin-Shung Huang, Zack Weinberg Carnegie Mellon University Chris Evans Google Collin Jackson Carnegie.
I'll see your cross site scripting and raise you a Content Security Policy Lou Leone :: Rochester OWASP.
17 th ACM CCS (October, 2010).  Introduction  Threat Model  Cross-Origin CSS Attacks  Example Attacks  Defenses  Experiment  Related Work 2 A Presentation.
An Evaluation of the Google Chrome Extension Security Architecture
Site and user security concerns for real time content serving Chris Mejia, IAB Sean Snider, Yahoo! Prabhakar Goyal, Microsoft.
The Most Dangerous Code in the Browser Stefan Heule, Devon Rifkin, Alejandro Russo, Deian Stefan Stanford University, Chalmers University of Technology.
Build /16/2017 © 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION.
Active X Microsoft’s Answer to Dynamic Content Reference: Using Active X by Brian Farrar QUE
CM143 - Web Week 2 Basic HTML. Links and Image Tags.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Introduction to InfoSec – Recitation 10 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
Presented by…. Group 2 1. Programming language 2Introduction.
HTML 5 New Standardization of HTML. I NTRODUCTION HTML5 is The New HTML Standard, New Elements New Attributes Full CSS3 Support Video and Audio 2D/3D.
Computer Concepts 2014 Chapter 7 The Web and .
Pittsburgh Java User Group– Dec Java PureFaces: A JSF Framework Extension.
JavaScript & jQuery the missing manual Chapter 11
BLUEPRINT: Robust Prevention of Cross-site Scripting Attacks for Existing Browsers Mike Ter Louw, V.N. Venkatakrishnan University of Illinois at Chicago.
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
Design Patterns Phil Smith 28 th November Design Patterns There are many ways to produce content via Servlets and JSPs Understanding the good, the.
I Do Not Know What You Visited Last Summer: Protecting users from stateful third-party web tracking with TrackingFree browser Xiang Pan §, Yinzhi Cao †,
Krishna Mohan Koyya Glarimy Technology Services
3-Protecting Systems Dr. John P. Abraham Professor UTPA.
Embedding CenterView and Hosting External Content.
1 Internet Browsing Vulnerabilities and Security ECE4112 Final Lab Ye Yan Frank Park Scott Kim Neil Joshi.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Cross Site Integration “mashups” cross site scripting.
© Copyright 2013 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice. 1 RubyJax Brent Morris/
Interception and Analysis Framework for Win32 Scripts (not for public release) Tim Hollebeek, Ph.D.
Introduction to HTML. What is HTML?  Hyper Text Markup Language  Not a programming language but a markup language  Used for presentation and layout.
Week 1 – Beginners Content McAfee & Big Fish Games CoderDojo.
Don't Let Third Parties Slow You Down Arvind Jain, Michael Kleber Google.
audio video object Options: controls autoplay Need to define height and width Options: controls autoplay.
UPLOAD / DOWNLOAD april  HTML5 is just the next iteration of HTML  Previous version was technically HTML 4.01, which incorporated XHTML 1.0.
Introduction to JavaScript CS101 Introduction to Computing.
1 3 Computing System Fundamentals 3.4 Networked Computer Systems.
University of Central Florida The Postman Always Rings Twice: Attacking & Defending postMessage in HTML5 Websites Ankur Verma University of Central Florida,
ICM – API Server & Forms Gary Ratcliffe.
XSS Horror Show scary XSS vectors About me Researcher for Portswigger (makers of Burp suite) JavaScript XSS hacker I love JavaScript sandboxes Built.
Puppetnets: Misusing Web Browsers as a Distributed Attack Infrastructure Paper By : V.T.Lam, S.Antonatos, P.Akritidis, K.G.Anagnostakis Conference : ACM.
Learning Aim C.  In this section we will look at some simple client-side scripts, browser compatibility, exporting and compressing and suitable file.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
Browser code isolation John Mitchell CS 155 Spring 2016.
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,
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
The Postman Always Rings Twice: Attacking and Defending postMessage in HTML5 Websites Paper by Sooel Son and Vitaly Shmatikov, The University of Texas.
ColdFusion: Code Security Best Practices Presented at CCFUG Mar 2016 By Denard Springle.
Computer Basics Introduction CIS 109 Columbia College.
SlideSet #20: Input Validation and Cross-site Scripting Attacks (XSS) SY306 Web and Databases for Cyber Operations.
Web Security (cont.) 1. Referral issues r HTTP referer (originally referrer) – HTTP header that designates calling resource  Page on which a link is.
HTML CS 4640 Programming Languages for Web Applications
An Introduction to Web Application Security
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
Web Concepts Lesson 2 ITBS2203 E-Commerce for IT.
CISC103 Web Development Basics: Web site:
Data Virtualization Tutorial… CORS and CIS
BTEC NCF Dip in Comp - Unit 15 Website Development Lesson 05 – Website Performance Mr C Johnston.
Whether you decide to use hidden frames or XMLHttp, there are several things you'll need to consider when building an Ajax application. Expanding the role.
CISC103 Web Development Basics: Web site:
Browser code isolation
Browser Support for HTML5
Riding Someone Else’s Wave with CSRF
Web Development 101 Workshop
HTTP Security Headers Explained
An Introduction to JavaScript
HTTP Security Headers You Need To Know
HTML CS 4640 Programming Languages for Web Applications
Presentation transcript:

Pushing CSP to PROD Case Study of a Real-World Content- Security Policy Implementation

What is Content-Security Policy?  Controls where content is loaded from  Controls what content can do Extremely useful for thwarting content injection attacks! XSS

What Content-Security Policy IS NOT  A silver bullet for addressing Cross-Site Scripting - Think of it as a safety belt in case you mess up

History of Content Security Policy  Started at Mozilla, and has since grown into its own W3C specification  v1.0 – Release Candidate Support is pretty good across most major browsers  v1.1 – Draft Browser support is lacking / spotty What we will be talking about today.

Browser Support for CSP v14+v6+v4+N/Av15+ DESKTOP

Who’s using CSP?  Only 191 out of Alexa top 1,000,000 sites Source: Veracode - headers-on-the-top websites-march-2013-report/  List includes some high-profile websites - Facebook, Twitter, GitHub

What types of content can be restricted? Content TypeCSP Attribute JavaScriptscript-src CSSstyle-src Connections (XHR, WebSockets, etc)connect-src iFrameframe-src Imagesimg-src Web Fontsfont-src Video and Audio Sourcesmedia-src Embedded elements, applets and plug-insobject-src

How is content restricted?  By Source (per directive) - 'none', 'self', specific hostnames, *  By Category - unsafe-inline (script-src & style-src only) - unsafe-eval (script-src only)  Missing directives inherit from default-src - Assumed to be * if missing (open by default)

About the Application

Objectives of our CSP Implementation Be as Strict as Possible Deny everything by default, only allow what is needed Maximize Coverage Across Browsers Handle browser-specific nuances Monitor Attempts to Bypass Leverage built in CSP error reporting

Objectives of our CSP Implementation Be as Strict as Possible Deny everything by default, only allow what is needed Maximize Coverage Across Browsers Handle browser-specific nuances Monitor Attempts to Bypass Leverage built in CSP error reporting

Dedicated Site for Authorized Scripts BEFORE +

We want to be as strict as possible  Our policy uses a “Deny by Default” model - default-src= "none"  Allow JavaScript only from our static server - static.sendsafely.com  No string-to-code functions or in-line scripts - No use of unsafe-eval or unsafe-inline

Dedicated Site for Authorized Scripts AFTER

And now for the harder part…  Removal of patterns banned by unsafe-eval - Covers text-to-Javascript functions like eval() - Luckily we had already banned these  Removal of all in-line JavaScript - This was pervasive within our code - Most of your code will likely look like our examples

Eliminating In-line Scripting (Example #1) Do something Before (HTML w/ In-line JavaScript) Do something After (HTML without JavaScript) var link = document.getElementById("my-link"); link.addEventListener("click", doSomething, false); After (JavaScript loaded from static.sendsafely.com) Find the link based on it’s ID

Eliminating In-line Scripting (Example #1) Do something Before (HTML w/ In-line JavaScript) Do something After (HTML without JavaScript) var link = document.getElementById("my-link"); link.addEventListener("click", doSomething, false); After (JavaScript loaded from static.sendsafely.com) Wire up the “click” event to “doSomething()”

Eliminating In-line Scripting (Example #2) Before (HTML w/ In-line JavaScript) <type="text" id="my- -field" name=" " data-arg-one="arg1" data-arg-two="arg2"> After (HTML without JavaScript) Embed argument values within the HTML as data-vars $(“#my- -field”).keyup(function() { doSomethingElse(this.getAttribute(“data-arg-one”), this.getAttribute(“data-arg-two”)); }); After (JavaScript loaded from static.sendsafely.com)

Eliminating In-line Scripting (Example #2) Before (HTML w/ In-line JavaScript) <type="text" id="my- -field" name=" " data-arg-one="arg1" data-arg-two="arg2"> After (HTML without JavaScript) $(“#my- -field”).keyup(function() { doSomethingElse(this.getAttribute(“data-arg-one”), this.getAttribute(“data-arg-two”)); }); After (JavaScript loaded from static.sendsafely.com) Use JQuery to wireup event and pass data-args to function

Working with Third Party Scripts  We try to minimize reliance on third party scripts - Occasionally the cost/benefit is worth using them - Examples: JQuery, reCAPTCHA  Our policy is to host all JavaScript on our servers - Re-factoring to make CSP compliant is not desirable

Working with Third Party Scripts (reCAPTCHA)  Required unsafe-inline - Inline Event Handler Definitions - Inline Script within HREF Attributes  Required unsafe-eval - Use of String-to-Code in Function Calls Fixed by Google this Summer

Refactoring reCAPTCHA (Example #1) Recaptcha.timer_id = setInterval('Recaptcha.reload("t");', a); Before (Inline Event Handler Definitions) Recaptcha.timer_id = setInterval(function(){Recaptcha.reload("t")}, a); After (Eliminate Inline Event Handler)

What about Web Workers?  HTML5 Web Workers enforce Same-Origin Policy - You cannot create a Web Worker using a JavaScript file that's on a different domain.  Our workaround: - Relaxed CSP on the two pages that use Web Workers - script-src='self'

Content TypeDirective Defaultdefault-src JavaScriptscript-src Stylesheetsstyle-src Connectionsconnect-src iFrameframe-src Imagesimg-src Web Fontsfont-src Video and Audiomedia-src Embedded Objectsobject-src

Content TypeDirective Defaultdefault-src JavaScriptscript-src Stylesheetsstyle-src Connectionsconnect-src iFrameframe-src Imagesimg-src Web Fontsfont-src Video and Audiomedia-src Embedded Objectsobject-src default-src 'none'; CSP

Content TypeDirective Defaultdefault-src JavaScriptscript-src Stylesheetsstyle-src Connectionsconnect-src iFrameframe-src Imagesimg-src Web Fontsfont-src Video and Audiomedia-src Embedded Objectsobject-src default-src 'none'; script-src CSP

Embedded Stylesheet Resources  We have in-line CSS across most of our pages - Significantly more effort that removing our in-line script

Embedded Stylesheet Resources  We have in-line CSS across most of our pages - Significantly more effort that removing our in-line script  What our code needs to run: - style-src='self' 'unsafe-inline'

Allowing un-safe inline for StyleSheets  Threat of CSS injection is lower than that of direct script injection (but still a valid threat)  We do not rely on CSP as a primary defense - Robust encoding APIs used throughout the site Decision: Cost/Benefit of refactoring effort was not worth it Long term goal (in next UI overhaul) will attempt to fix

Content TypeDirective Defaultdefault-src JavaScriptscript-src Stylesheetsstyle-src Connectionsconnect-src iFrameframe-src Imagesimg-src Web Fontsfont-src Video and Audiomedia-src Embedded Objectsobject-src default-src 'none'; script-src style-src 'self' 'unsafe-inline'; CSP

Content TypeDirective Defaultdefault-src JavaScriptscript-src Stylesheetsstyle-src Connectionsconnect-src iFrameframe-src Imagesimg-src Web Fontsfont-src Video and Audiomedia-src Embedded Objectsobject-src default-src 'none'; script-src style-src 'self' 'unsafe-inline'; connect-src 'self'; CSP

Content TypeDirective Defaultdefault-src JavaScriptscript-src Stylesheetsstyle-src Connectionsconnect-src iFrameframe-src Imagesimg-src Web Fontsfont-src Video and Audiomedia-src Embedded Objectsobject-src default-src 'none'; script-src style-src 'self' 'unsafe-inline'; connect-src 'self'; frame-src 'self'; CSP

Content TypeDirective Defaultdefault-src JavaScriptscript-src Stylesheetsstyle-src Connectionsconnect-src iFrameframe-src Imagesimg-src Web Fontsfont-src Video and Audiomedia-src Embedded Objectsobject-src default-src 'none'; script-src style-src 'self' 'unsafe-inline'; connect-src 'self'; frame-src 'self'; img-src 'self' CSP

Content TypeDirective Defaultdefault-src JavaScriptscript-src Stylesheetsstyle-src Connectionsconnect-src iFrameframe-src Imagesimg-src Web Fontsfont-src N/A Video and Audiomedia-src Embedded Objectsobject-src default-src 'none'; script-src style-src 'self' 'unsafe-inline'; connect-src 'self'; frame-src 'self'; img-src 'self' CSP

Content TypeDirective Defaultdefault-src JavaScriptscript-src Stylesheetsstyle-src Connectionsconnect-src iFrameframe-src Imagesimg-src Web Fontsfont-src N/A Video and Audiomedia-src N/A Embedded Objectsobject-src default-src 'none'; script-src style-src 'self' 'unsafe-inline'; connect-src 'self'; frame-src 'self'; img-src 'self' CSP

Allowing Java Applets  The same pages that use Web Workers use a Java Applet when using a browser without HTML5 - Initially we planned for an object-src directive to allow

As it turns out…  None of the browsers we tested block the tag (even with object-src: 'none') - Chrome, FireFox, Safari  Were we missing something? - Thread started on ???

Content TypeDirective Defaultdefault-src JavaScriptscript-src Stylesheetsstyle-src Connectionsconnect-src iFrameframe-src Imagesimg-src Web Fontsfont-src N/A Video and Audiomedia-src N/A Embedded Objectsobject-src N/A default-src 'none'; script-src style-src 'self' 'unsafe-inline'; connect-src 'self'; frame-src 'self'; img-src 'self' CSP

Objectives of our CSP Implementation Be as Strict as Possible Deny everything by default, only allow what is needed Maximize Coverage Across Browsers Handle browser-specific nuances Monitor Attempts to Bypass Leverage built in CSP error reporting

Objectives of our CSP Implementation Be as Strict as Possible Deny everything by default, only allow what is needed Maximize Coverage Across Browsers Handle browser-specific nuances Monitor Attempts to Bypass Leverage built in CSP error reporting

CSP Error Reporting  Built-in feature of CSP, used to report violations - Browser sends error reports when a directive is violated - Source URL, offending directive and code fragment  If CSP kicks in for a user, you will know - Great for development and testing - CSP also works in report-only mode

Example CSP Error Report document-uri: referrer: blocked-uri: self violated-directive: inline script base restriction source-file: script-sample: alert(document.cookie) The URI of the page where the error occurred Report

Example CSP Error Report document-uri: referrer: blocked-uri: self violated-directive: inline script base restriction source-file: script-sample: alert(document.cookie) The page that the user came from to get there Report

Example CSP Error Report document-uri: referrer: blocked-uri: self violated-directive: inline script base restriction source-file: script-sample: alert(document.cookie) Blocked URI shows that the content resides on the same page Report

Example CSP Error Report document-uri: referrer: blocked-uri: self violated-directive: inline script base restriction source-file: script-sample: alert(document.cookie) Violated Directive tells us what happened. Report

Example CSP Error Report document-uri: referrer: blocked-uri: self violated-directive: inline script base restriction source-file: script-sample: alert(document.cookie) Source File tells us the page where the breach happened. Report

Example CSP Error Report document-uri: referrer: blocked-uri: self violated-directive: inline script base restriction source-file: script-sample: alert(document.cookie) Script Sample shows us an example of the injected code. Report

Real CSP Error Report from Production document-uri: referrer: blocked-uri: self violated-directive: inline script base restriction source-file: chrome-extension://hdokiejnpimakedhajhdlcegeplioahd script-sample: var a=function(){},_gaq={pus... Report Does this look like a valid exploit attempt?

The (big) problem with False Positives  Several popular browser plug-ins /extensions inject JavaScript code into pages  The most common sources we’ve seen: - LastPass - Norton Identity Protection - Urchin Tracker - JSShell

Seeing Through the Noise  Need to filter out the noise while being careful not to cover real exploit attempts  We started analyzing reports to identify signatures could be safely ignored Signature = Keyword or Pattern + Violated CSP Directive

Violations from Common Chrome Extensions ExtensionViolated Directive (per Report) Source File (per Report) LastPassSource-filechrome-extension://hdokiejnpimakedhajhdlcegeplioahd BufferSource-filechrome-extension://noojglkidnpfjbincgijbaiedldjfbhh FirebugSource-filechrome://firebug/content/console/commandLineExposed.js AutoFillSource-filechrome-extension://nlmmgnhgdeffjkdckmikfpnddkbbfkkk DoNotTrackMeSource-filechrome-extension://epanfjkfahimkgomnigadpkobaefekcd

Filtering out extensions will go a long way  Extensions wont hide real attacks, unless its coming from the extension itself - If a user installs an evil extension, we can’t help them

Signature for Ignoring Chrome Extensions  Chrome loads extensions via URL calls - Shows up as source-file document-uri: * referrer: * blocked-uri: * violated-directive: * source-file: ^(chrome-extension://|chrome://) script-sample: * Report Signature (Chrome Extensions)

Signature for Ignoring Safari Extensions  Similar to chrome, loads extensions via URL calls - Shows up as source-file document-uri: * referrer: * blocked-uri: * violated-directive: * source-file: ^(safari-extension://) script-sample: * Report Signature (Safari Extensions)

What about Firefox?  Firefox doesn’t load extensions the same way  Filtering based on code snippets is dangerous document-uri: referrer: blocked-uri: self violated-directive: inline script base restriction source-file: script-sample: try { for(var lastpass_iter=0; lastpass... LastPass on Firefox

Objectives of our CSP Implementation Be as Strict as Possible Deny everything by default, only allow what is needed Maximize Coverage Across Browsers Handle browser-specific nuances Monitor Attempts to Bypass Leverage built in CSP error reporting

Objectives of our CSP Implementation Be as Strict as Possible Deny everything by default, only allow what is needed Maximize Coverage Across Browsers Handle browser-specific nuances Monitor Attempts to Bypass Leverage built in CSP error reporting

Maximizing Browser Coverage v14+v6+v4+N/Av15+

Maximizing Browser Coverage Content-Security-Policy: default-src 'none';scri... ???

Maximizing Browser Coverage Content-Security-Policy: default-src 'none';scri... X-WebKit-CSP: default-src 'none';scri...

Handling different CSP Header Names  Detect browser and send the correct header? - Alternatively we could just set both headers every time  Older versions of Safari 5.1x - Botched CSP support (breaks pages)

Setting the CSP Header Apache mod_header mod_header covers ALL HTTP requests, not just those that make it to the application Needed to chain mod_rewrite rules for browser detection Tomcat Servlet Filter Context-aware - Authenticated vs Anonymous Allows much more complex logic for a more granular CSP policy vs.

Other Notable Differences  Safari posts CSP Error Reports - Sends HTTP name/value pairs instead of JSON  Chrome and Firefox Headers - Was X-Content-Security-Policy until recently  Firefox Connection Source Directive - Was previously xhr-src (fixed)

Apple Ad Campaign Circa 1990

Objectives of our CSP Implementation Be as Strict as Possible Deny everything by default, only allow what is needed Maximize Coverage Across Browsers Handle browser-specific nuances Monitor Attempts to Bypass Leverage built in CSP error reporting

Concluding Thoughts  CSP works, especially with regards to XSS - But you will likely not end up with a bullet proof CSP  Error Reporting causes A LOT of noise - Mainly due to browser add-ons  Browser support currently useable for 1.0 only features are fairly stable, not much coverage for 1.1