Frederic Hemberger
2014: On Alexaʼs Top 100,000 websites,
75% use a jQuery version older than 2½ years.
On 35% itʼs even older than 5 years.
2016: Scanning the domains of the Fortune 500 companies,
83% contained vulnerable libraries.
<script>
- manipulate the siteʼs appearance
- manipulate cookies, localStorage, etc.
- steal session credentials, tokens, etc.
- load malicious code via XMLHttpRequest
- do whatever the heck you want
</script>
Cache-Control: public Content-Encoding: gzip Content-Length: 2373 Content-Security-Policy: … Content-Type:text/html; charset=utf-8 Date: Wed, 19 Oct 2016 11:22:05 GMT …
# .htaccess
Header set Content-Security-Policy: ↩
"script-src 'self' https://code.jquery.com"
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery.js"></script>
</head>
<body>
<!-- this got injected somehow -->
<script src="https://evil.com/evil.js"></script>
</body>
</html>
Loading/executing the script from evil.com is suppressed:
jQuery CDN, Google web fonts, embedded YouTube videos
Header set Content-Security-Policy: " \
default-src 'none'; \
script-src 'self' https://code.jquery.com; \
style-src 'self' https://fonts.googleapis.com; \
font-src https://themes.googleusercontent.com; \
img-src 'self' data:; \
frame-src https://www.youtube.com;"
You can specify sources by scheme (data:, https:), hostname (example.com), fully qualified URI (https://example.com:443) or wildcard (*://*.example.com:*)
Warning: 'unsafe-inline' / 'unsafe-eval'
will execute all
inline scripts, including possible XSS vectors.
<script nonce="EDNnf03nceIOfn39fn3e9h3sdfa">
…
</script>
Header set Content-Security-Policy: ↩
"script-src 'nonce-EDNnf03nceIOfn39fn3e9h3sdfa'"
Content-Security-Policy-Report-Only: [policy]
Header set Content-Security-Policy: …↩
report-uri /my/reporting/endpoint
You can also use report-uri.io for CSP data collection
{
"csp-report": {
"document-uri": "http://example.com/signup.html",
"referrer": "",
"blocked-uri": "http://example.com/css/style.css",
"violated-directive": "style-src cdn.example.com",
"original-policy": "…"
}
}
HTML5 Rocks: An Introduction to Content Security Policy
content-security-policy.com![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
25 | 4 | 10 | 15 | 6.1 | 4.4 |
IE < Edge, some Android and/or older browsers may use
»X-Content-Security-Policy« or »X-Webkit-CSP«
<script src="https://cdn.example.com/jquery.min.js"></script>
$ cat jquery.min.js | openssl dgst -sha256 | openssl base64
hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=
<script
src="https://cdn.example.com/jquery.min.js"
crossorigin="anonymous"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
></script>
![]() |
![]() |
![]() |
![]() |
![]() macOS |
![]() iOS |
![]() |
45 | 43 | * | 32 | 11 | ** | 5 |
* MS Edge status: Windows Insider Preview Build
** WebKit status: Supported In Preview
(as of September 2017)