{"id":106,"date":"2009-06-19T15:41:59","date_gmt":"2009-06-19T23:41:59","guid":{"rendered":"http:\/\/blog.mozilla.org\/security\/?p=106"},"modified":"2009-06-20T14:38:16","modified_gmt":"2009-06-20T22:38:16","slug":"shutting-down-xss-with-content-security-policy","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/security\/2009\/06\/19\/shutting-down-xss-with-content-security-policy\/","title":{"rendered":"Shutting Down XSS with Content Security Policy"},"content":{"rendered":"<p>For several years, Cross-Site Scripting (XSS) attacks have plagued many of the web&#8217;s most popular sites and victimized their users.  At Mozilla, we&#8217;ve been working for the last year on a new technology called <a href=\"https:\/\/wiki.mozilla.org\/Security\/CSP\">Content Security Policy<\/a>, designed to shut these attacks down.  We wanted to give a bit of background on this project as well as provide an update on our progress so far.<\/p>\n<p>XSS is possible because all the content received as part of a web server response is treated with equal privilege by the requesting browser.  JavaScript and other content included in a web page are all combined into a single security context which has full access to the DOM.  Content Security Policy (CSP) provides a mechanism for sites to explicitly tell the browser which content is legitimate.  The browser can then disregard any content which has not been blessed by the site.<\/p>\n<p>In order to differentiate legitimate content from injected or modified content, CSP requires that all JavaScript for a page be 1) loaded from an external file, and 2) served from an explicitly approved host.  This means that all inline script, javascript: URIs, and event-handling HTML attributes will be ignored.  Only script included via a &lt;script> tag pointing to a white-listed host will be treated as valid.  Additionally, CSP allows several other <a href=\"https:\/\/wiki.mozilla.org\/Security\/CSP\/Spec#Content_Restrictions\">common-sense security restrictions<\/a> to be enforced.<\/p>\n<p>We realize that this model is dramatically different than the current unrestricted model for the Web.  We offer the following case supporting CSP&#8217;s adoption:<\/p>\n<ol>\n<li><strong>CSP can be implemented in phases.<\/strong>\n<p>While the biggest security benefit offered by Content Security Policy is the mitigation of XSS through inline script blocking, the migration of all JavaScript to external files may be challenging or time-consuming for some sites.  Therefore, sites may choose to use the <a href=\"https:\/\/wiki.mozilla.org\/Security\/CSP\/Spec#Directives\">other features<\/a> of Content Security Policy without adopting the JavaScript restrictions.  Our hope is that this flexibility will provide a wide gate for such sites to adopt CSP in a limited fashion early, and later move toward a full implementation as time and resources permit.<\/p>\n<\/li>\n<li><strong>Even complex sites can be modified to support CSP.<\/strong>\n<p>We have looked at HTML\/JavaScript samples from a wide variety of websites ranging in complexity and have yet to see an example which could not be modified to support CSP.  We&#8217;ll provide documentation regarding best practices for migrating a site to use CSP.  Content Security Policy is also consistent with the programming paradigm &#8220;don&#8217;t mix code with content&#8221; so there may be additional functional benefits to be gained by implementing such separation.<\/p>\n<\/li>\n<li><strong>Drive a stake through the heart of XSS!<\/strong>\n<p>XSS vulnerabilities have real value to attackers and are shared rapidly across the Web once discovered.  Sites can breathe a little easier knowing that their users are protected, even if a XSS bug slips through.  Because CSP can be configured to <a href=\"https:\/\/wiki.mozilla.org\/Security\/CSP\/Spec#Violation_Report_Syntax\">notify<\/a> the protected site when an attack is blocked, CSP will even benefit users of older browsers, by helping sites identify and plug vulnerabilities quickly.  The bottom line is that it will be extremely difficult to mount a successful XSS attack against a site with CSP enabled.  All common vectors for script injection will no longer work and the bar for a successful attack is placed much, much higher.<\/p>\n<\/li>\n<\/ol>\n<p>Content Security Policy has been a collaboration of many individuals and has received input from multiple web sites, browser vendors, and web app security researchers.  We are very excited to have reached a level of stability in the <a href=\"https:\/\/wiki.mozilla.org\/Security\/CSP\/Spec\">design<\/a> that has allowed us to begin <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=493857\">implementation<\/a> of the CSP specification.  Stay tuned for further updates.  We will let you know when the fixes have been checked in to trunk and the product is ready to be tested in our nightly builds.  Let us know what you think!<\/p>\n<p>Brandon Sterne<br \/>Security Program Manager<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For several years, Cross-Site Scripting (XSS) attacks have plagued many of the web&#8217;s most popular sites and victimized their users. At Mozilla, we&#8217;ve been working for the last year on &hellip; <a class=\"go\" href=\"https:\/\/blog.mozilla.org\/security\/2009\/06\/19\/shutting-down-xss-with-content-security-policy\/\">Read more<\/a><\/p>\n","protected":false},"author":54,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,69],"tags":[],"coauthors":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Shutting Down XSS with Content Security Policy - Mozilla Security Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.mozilla.org\/security\/2009\/06\/19\/shutting-down-xss-with-content-security-policy\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Al Billings\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog.mozilla.org\/security\/2009\/06\/19\/shutting-down-xss-with-content-security-policy\/\",\"url\":\"https:\/\/blog.mozilla.org\/security\/2009\/06\/19\/shutting-down-xss-with-content-security-policy\/\",\"name\":\"Shutting Down XSS with Content Security Policy - Mozilla Security Blog\",\"isPartOf\":{\"@id\":\"https:\/\/blog.mozilla.org\/security\/#website\"},\"datePublished\":\"2009-06-19T23:41:59+00:00\",\"dateModified\":\"2009-06-20T22:38:16+00:00\",\"author\":{\"@id\":\"https:\/\/blog.mozilla.org\/security\/#\/schema\/person\/d33dd2d17a8109165b6df7d1245e33fc\"},\"breadcrumb\":{\"@id\":\"https:\/\/blog.mozilla.org\/security\/2009\/06\/19\/shutting-down-xss-with-content-security-policy\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.mozilla.org\/security\/2009\/06\/19\/shutting-down-xss-with-content-security-policy\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.mozilla.org\/security\/2009\/06\/19\/shutting-down-xss-with-content-security-policy\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blog.mozilla.org\/security\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Shutting Down XSS with Content Security Policy\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog.mozilla.org\/security\/#website\",\"url\":\"https:\/\/blog.mozilla.org\/security\/\",\"name\":\"Mozilla Security Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blog.mozilla.org\/security\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/blog.mozilla.org\/security\/#\/schema\/person\/d33dd2d17a8109165b6df7d1245e33fc\",\"name\":\"Al Billings\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blog.mozilla.org\/security\/#\/schema\/person\/image\/9456a97c7c46aaacc293dfb3e668ecfd\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/59eb615338adae529ebe54960f87cd0c?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/59eb615338adae529ebe54960f87cd0c?s=96&d=identicon&r=g\",\"caption\":\"Al Billings\"},\"sameAs\":[\"https:\/\/openbuddha.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Shutting Down XSS with Content Security Policy - Mozilla Security Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.mozilla.org\/security\/2009\/06\/19\/shutting-down-xss-with-content-security-policy\/","twitter_misc":{"Written by":"Al Billings","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/blog.mozilla.org\/security\/2009\/06\/19\/shutting-down-xss-with-content-security-policy\/","url":"https:\/\/blog.mozilla.org\/security\/2009\/06\/19\/shutting-down-xss-with-content-security-policy\/","name":"Shutting Down XSS with Content Security Policy - Mozilla Security Blog","isPartOf":{"@id":"https:\/\/blog.mozilla.org\/security\/#website"},"datePublished":"2009-06-19T23:41:59+00:00","dateModified":"2009-06-20T22:38:16+00:00","author":{"@id":"https:\/\/blog.mozilla.org\/security\/#\/schema\/person\/d33dd2d17a8109165b6df7d1245e33fc"},"breadcrumb":{"@id":"https:\/\/blog.mozilla.org\/security\/2009\/06\/19\/shutting-down-xss-with-content-security-policy\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.mozilla.org\/security\/2009\/06\/19\/shutting-down-xss-with-content-security-policy\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.mozilla.org\/security\/2009\/06\/19\/shutting-down-xss-with-content-security-policy\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.mozilla.org\/security\/"},{"@type":"ListItem","position":2,"name":"Shutting Down XSS with Content Security Policy"}]},{"@type":"WebSite","@id":"https:\/\/blog.mozilla.org\/security\/#website","url":"https:\/\/blog.mozilla.org\/security\/","name":"Mozilla Security Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.mozilla.org\/security\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.mozilla.org\/security\/#\/schema\/person\/d33dd2d17a8109165b6df7d1245e33fc","name":"Al Billings","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blog.mozilla.org\/security\/#\/schema\/person\/image\/9456a97c7c46aaacc293dfb3e668ecfd","url":"https:\/\/secure.gravatar.com\/avatar\/59eb615338adae529ebe54960f87cd0c?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/59eb615338adae529ebe54960f87cd0c?s=96&d=identicon&r=g","caption":"Al Billings"},"sameAs":["https:\/\/openbuddha.com"]}]}},"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/security\/wp-json\/wp\/v2\/posts\/106"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/security\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/security\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/security\/wp-json\/wp\/v2\/users\/54"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/security\/wp-json\/wp\/v2\/comments?post=106"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/security\/wp-json\/wp\/v2\/posts\/106\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/security\/wp-json\/wp\/v2\/media?parent=106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/security\/wp-json\/wp\/v2\/categories?post=106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/security\/wp-json\/wp\/v2\/tags?post=106"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blog.mozilla.org\/security\/wp-json\/wp\/v2\/coauthors?post=106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}