Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Csp july2015

1,076 views

Published on

content security policy talk during null/g4h/owasp meet on 26th July 2015

Published in: Technology
  • Login to see the comments

Csp july2015

  1. 1. Content Security Policy OR HOW TO MAKE DEVELOPERS EVEN MORE LAZIER RIYAZ WALIKAR
  2. 2. whoami  Security evangelist  Do not work at a Big 4  One of the 3 OWASP Bangalore chapter leaders  Extremely talkative
  3. 3. Same Origin Policy  So you own http://banana.com  Code from http://potato.com should not be able to access data from http://banana.com  Browser’s sandbox and Origin protection  XSS to bypass SOP
  4. 4. For the love of XSS  Reflected, Stored, DOM based
  5. 5. Content Security Policy
  6. 6. The core issue exploited by XSS attacks is the browser’s inability to distinguish between script that’s intended to be part of your application, and script that’s been maliciously injected by a third-party. http://www.html5rocks.com/en/tutorials/security/content-security-policy/
  7. 7. I had you at Header  Content Security Policy (CSP) defines the Content-Security-Policy HTTP header  Whitelist script sources of trusted content  Even if vulnerable to XSS, injected script will not trigger due to header definition
  8. 8. Building the policy  So you trust scripts only from http://banana.com and your own domain (non inline) Content-Security-Policy: script-src 'self' http://banana.com  So you want to load images only from http://potato.com and flash content from your own domain. Also, absolutely no scripts. Content-Security-Policy: script-src 'none'; img-src http://potato.com; object-src 'self'
  9. 9. CSP Directives  default-src  script-src  style-src  img-src  connect-src  font-src  object-src  media-src  child-src  sandbox  report-uri The default-src is the default policy for loading content such as JavaScript, Images, CSS, fonts, AJAX requests, Frames and HTML5 Media Defines valid sources of JavaScript Defines valid sources of css (stylesheets) Defines valid sources of images Defines sources to which XMLHTTPRequest (AJAX), WebSocket or EventSource can fetch data from Defines valid sources of fontsDefines valid sources of plugins (for example: flash, embed tag, applet etc.) Defines valid source of audio and video Defines valid source for workers and embedded frame contents. frame-src is deprecated. child-src should be used. More about this laterInstructs the browser to POST a reports of policy failures to a specified URI.
  10. 10. CSP Source Declarations Source Value Meaning * Wildcard, allows all origins. 'self' Allow same origin (current origin). 'none' Don't allow any resources of this directive to load. domain.example.com Allow a domain (explicit declaration) *.example.com Allow all subdomains on a domain. Exclude TLD. https://example.com Exact match including protocol https: Load from any domain but https data: Allow data uri (eg: Base64 encoded image)
  11. 11. unsafe-inline  When script-src or style-src are declared, inline script tags and css are disabled  You can specify 'unsafe-inline' to execute inline script but that is precisely what CSP was designed to prevent!
  12. 12. unsafe-eval  CSP disables the JavaScript function eval() by design  To enable this explicitly, add 'unsafe-eval' to a script-src directive  Not advised!
  13. 13. sandbox  If present, browser treats the page as if it loaded inside an iframe with a sandbox attribute  The browser severely restricts the page’s functionality, disabling JS, form submissions, plugins and objects  You can keep the sandbox value empty to keep all restrictions in place, or add values: allow-forms allow-same-origin allow-scripts, and allow-top-navigation
  14. 14. DEMO TIME
  15. 15. Sources: caniuse.com/contentsecuritypolicy & Mozilla
  16. 16. CSP 2.0!  Several new enhancements including support for inline scripts in combination with a cryptographic nonce or hash sharing of the script itself Content-Security-Policy: script-src 'nonce-AY778asa229b2DEADBEEF' http://www.w3.org/TR/CSP2/
  17. 17. I read the following to make this presentation  http://www.w3.org/TR/2012/CR-CSP-20121115/  http://www.html5rocks.com/en/tutorials/security/content-security- policy/  http://content-security-policy.com/  http://caniuse.com/#feat=contentsecuritypolicy  https://html.spec.whatwg.org/multipage/browsers.html#sandboxin g-flag-set  http://www.w3.org/TR/CSP2/
  18. 18. Riyaz Walikar http://www.riyazwalikar.com @riyazwalikar @wincmdfu

×