├── .gitignore ├── 3rdPartyOSS.txt ├── LICENSE.md ├── README.md ├── bin └── www ├── browser_versions.txt ├── config.js ├── csp-validator ├── README.md └── csp-validator.js ├── index.js ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── images │ └── spinner.gif ├── javascripts │ ├── jquery │ │ ├── jquery-1.11.2.min.js │ │ └── jquery-ui-1.11.2.min.js │ ├── test-share-script.js │ ├── test-window.js │ └── testscript.js └── stylesheets │ ├── jquery │ └── 1.11.2 │ │ └── themes │ │ └── smoothness │ │ └── jquery-ui.css │ ├── pure │ └── 0.5.0 │ │ └── pure-min.css │ └── style.css ├── routes └── index.js ├── run ├── views ├── cspreport.ejs ├── error.ejs ├── index.ejs ├── partials │ └── template │ │ ├── footer.ejs │ │ ├── head.ejs │ │ └── header.ejs ├── test-report.ejs ├── test-window.ejs ├── test.ejs └── webkit-tests.ejs └── webkit-tests ├── 1.1 ├── base-uri-allow.html ├── base-uri-deny.html ├── form-action-src-allowed.html ├── form-action-src-blocked.html ├── form-action-src-default-ignored.html ├── form-action-src-get-allowed.html ├── form-action-src-get-blocked.html ├── form-action-src-javascript-blocked.html ├── form-action-src-redirect-blocked.html ├── frame-allowed.html ├── frame-blocked.html ├── frame-redirect-blocked.html ├── meta-outside-head.html ├── plugintypes-notype-url.html ├── plugintypes-nourl-allowed.html ├── scripthash-allowed.html ├── scripthash-basic-blocked.html ├── scripthash-ignore-unsafeinline.html ├── scripthash-unicode-normalization.html ├── scriptnonce-allowed.html ├── scriptnonce-and-scripthash.html ├── scriptnonce-basic-blocked.html ├── scriptnonce-ignore-unsafeinline.html ├── stylehash-allowed.html ├── stylehash-basic-blocked.html ├── stylenonce-allowed.html └── stylenonce-blocked.html ├── blob-urls-match-self.html ├── combine-multiple-policies.html ├── csptest.html ├── default-src-inline-allowed.html ├── duplicate-directive.html ├── eval-allowed-in-report-only-mode.html ├── eval-allowed.html ├── eval-blocked.html ├── eval-scripts-setInterval-allowed.html ├── eval-scripts-setInterval-blocked.html ├── eval-scripts-setTimeout-allowed.html ├── eval-scripts-setTimeout-blocked.html ├── function-constructor-allowed.html ├── function-constructor-blocked.html ├── image-allowed.html ├── image-full-host-wildcard-allowed.html ├── image-host-wildcard-allowed.html ├── img-blocked-no-gc-crash.html ├── injected-inline-script-allowed.html ├── injected-inline-script-blocked.html ├── injected-inline-style-allowed.html ├── injected-inline-style-blocked.html ├── inline-script-allowed.html ├── inline-script-blocked-goofy.html ├── inline-style-allowed.html ├── inline-style-attribute-allowed.html ├── inline-style-attribute-blocked.html ├── inline-style-attribute-on-html.html ├── inline-style-blocked.html ├── media-src-track-block.html ├── no-policy.html ├── policy-does-not-affect-child.html ├── report-and-enforce.html ├── report-blocked-data-uri.html ├── report-only-report-uri-missing.html ├── report-only.html ├── report-uri.html ├── resources ├── abe.png ├── alert-fail.js ├── alert-pass.html ├── blue.css ├── document-write-alert-fail.js ├── dump-as-text.js ├── get.txt ├── go-to-echo-report.js ├── inject-script.js ├── inject-style.js ├── multiple-iframe-test.js ├── script.js ├── track.vtt ├── worker-eval.js ├── worker-function-function.js ├── worker-make-xhr.js └── worker-set-timeout.js ├── sandbox-allow-scripts-subframe.html ├── sandbox-allow-scripts.html ├── sandbox-empty-subframe.html ├── sandbox-empty.html ├── script-src-overrides-default-src.html ├── source-list-parsing-02.html ├── source-list-parsing-03.html ├── source-list-parsing-04.html ├── source-list-parsing-deprecated.html ├── source-list-parsing-no-semicolon.html ├── srcdoc-doesnt-bypass-script-src.html ├── style-allowed.html ├── style-blocked.html ├── worker-connect-src-allowed.html ├── worker-connect-src-blocked.html ├── worker-eval-blocked.html ├── worker-function-function-blocked.html ├── worker-script-src.html └── worker-set-timeout-blocked.html /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /3rdPartyOSS.txt: -------------------------------------------------------------------------------- 1 | Open source softwares: 2 | ---------------------- 3 | purecss.io (http://purecss.io/) 4 | license: https://github.com/yahoo/pure-site/blob/master/LICENSE.md 5 | 6 | jquery (http://jquery.com/) 7 | license: https://github.com/jquery/jquery/blob/master/LICENSE.txt 8 | 9 | nodejs ( http://nodejs.org/) 10 | license: https://github.com/joyent/node/blob/master/LICENSE 11 | 12 | redis (http://redis.io) 13 | license: https://github.com/antirez/redis/blob/unstable/COPYING 14 | 15 | NodeJs npm open source packages: 16 | -------------------------------- 17 | body-parser 18 | license: https://github.com/expressjs/body-parser/blob/master/LICENSE 19 | 20 | cookie-parser 21 | license: https://github.com/expressjs/cookie-parser/blob/master/LICENSE 22 | 23 | debug 24 | license: https://github.com/visionmedia/debug (MIT) 25 | 26 | ejs 27 | license: https://github.com/tj/ejs (MIT) 28 | 29 | express 30 | license: https://github.com/strongloop/express/blob/master/LICENSE 31 | 32 | express-busboy 33 | license: https://github.com/yahoo/express-busboy/blob/master/LICENSE 34 | 35 | morgan 36 | license: https://github.com/expressjs/morgan/blob/master/LICENSE 37 | 38 | randomstring 39 | license: https://github.com/klughammer/node-randomstring/blob/master/LICENSE 40 | 41 | redis 42 | license: https://github.com/mranney/node_redis (MIT) 43 | 44 | serve-favicon 45 | licenses: https://github.com/expressjs/serve-favicon/blob/master/LICENSE 46 | 47 | ua-parser 48 | license: https://github.com/tobie/ua-parser/blob/master/LICENSE.txt 49 | 50 | 51 | The application also contains modified version of CSP test scripts from: 52 | https://trac.webkit.org/browser#trunk/LayoutTests/http/tests/security/contentSecurityPolicy/ 53 | webkit 54 | licenses: https://www.webkit.org/coding/bsd-license.html & https://www.webkit.org/coding/lgpl-license.html 55 | and 56 | https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/&sq=package:chromium 57 | license: https://code.google.com/p/chromium/codesearch#chromium/src/LICENSE&sq=package:chromium&q=license 58 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD License) 2 | ======================================== 3 | 4 | Copyright (c) 2015, Yahoo Inc. All rights reserved. 5 | ---------------------------------------------------- 6 | 7 | Redistribution and use of this software in source and binary forms, 8 | with or without modification, are permitted provided that the following 9 | conditions are met: 10 | 11 | * Redistributions of source code must retain the above 12 | copyright notice, this list of conditions and the 13 | following disclaimer. 14 | * Redistributions in binary form must reproduce the above 15 | copyright notice, this list of conditions and the 16 | following disclaimer in the documentation and/or other 17 | materials provided with the distribution. 18 | * Neither the name of Yahoo Inc. nor the names of its 19 | contributors may be used to endorse or promote products 20 | derived from this software without specific prior 21 | written permission of Yahoo Inc. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 25 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 26 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **Note:** This library has known security vulnerabilities, use at your own risk! 2 | 3 | ## CSPTESTER 4 | 5 | A quick and easy way to test CSP behavior on modern browsers 6 | 7 | `csptester` is a Node.js-based web app that can frame a user's HTML content and allow them to test CSP policies in a browser of their choice to see what fails/works. You may optionally even try XSS attacks against your code. There are tools like http://caniuse.com/#search=csp that shows which browser versions support CSP, but it doesn't convey disparity in support between versions or browsers. And that's one reason `csptester` is helpful. 8 | 9 | **Features** 10 | * Test CSP on all modern browsers 11 | * CSP HTML meta tag support 12 | * Ability to render your HTML code on iframe and top-level window 13 | * Report-only and enforce mode options. Try an `alert()` in your code to see report-only and enforce in action! 14 | * Shareable links - To share with other users or to repeat the test on a different browser 15 | * Preloaded with curated subset of WebKit/Chrome tests (CSP level 1 & 2) to test various CSP features 16 | * Check 3rd party resources (eg. JavaScript) to find 4th party/recursive dependencies 17 | 18 | ## Using csptester 19 | 20 | CSP implementation differs between browsers. Even CSP 1.0 implementation is not consistent across all modern browsers. Therefore understanding browser's CSP support is important to implement CSP on your property. This is a tool to test policy behavior (with your sample script) across multiple browsers. However this is NOT intended to use to test a random site's CSP behavior. 21 | 22 | ### CSP Header 23 | The Content-Security-Policy (CSP) header value is made up of one or more directives. Multiple directives are separated with a semicolon (`;`) 24 | 25 | **NOTE:** Do not add CSP header name and report-uri field. The header and report-uri will be set by the application. 26 | 27 | **CSP header examples** 28 | 29 | [1] A server wishes to load resources only form its own origin 30 | ``` 31 | default-src 'self'; 32 | ``` 33 | 34 | [2] This policy allows images, scripts, AJAX, and CSS from the same origin, and does not allow any other resources to load (eg object, frame, media, etc). 35 | ``` 36 | default-src 'none'; script-src 'self'; connect-src 'self'; img-src 'self'; style-src 'self'; 37 | ``` 38 | 39 | [3] Allow all by default and restricts each resource type separately. 40 | ``` 41 | default-src *; 42 | script-src https://*.yahoo.com https://*.yimg.com 'unsafe-inline' 'unsafe-eval'; 43 | object-src https://*.yahoo.com https://*.yimg.com; 44 | style-src https://*.yahoo.com https://*.yimg.com 'unsafe-inline'; 45 | media-src https://*.yahoo.com https://*.yimg.com; 46 | frame-src https://*.yahoo.com https://*.yimg.com https://*.ymail.com; 47 | font-src https://*; 48 | connect-src https://*.yahoo.com https://*.flickr.com 49 | ``` 50 | 51 | ### HTML Code 52 | Provide your HTML code here. 53 | 54 | **Example** 55 | 56 | ```html 57 | 58 | 59 |
60 |<%= error.stack %>7 | <% } %> 8 | -------------------------------------------------------------------------------- /views/index.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | <% include partials/template/head.ejs %> 4 | 5 | 6 | <% include partials/template/header.ejs %> 7 |
19 | | document-uri | 20 |referrer | 21 |violated-directive | 22 |blocked-uri | 23 |
---|
24 | | document-uri | 25 |referrer | 26 |violated-directive | 27 |blocked-uri | 28 |
---|
<%= i+1 %> | 22 |<%= tests[i] %> | 23 |View | 24 | <% if (csp11 === true) { %> 25 |Run | 26 | <% } else { %> 27 |Run | 28 | <% } %> 29 | 30 |
Tests that allowed form actions work correctly. If this test passes, you will see a page indicating a form was POSTed.
20 | 21 | 22 | -------------------------------------------------------------------------------- /webkit-tests/1.1/form-action-src-blocked.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 13 | 14 | 18 | 19 |Tests that allowed form actions work correctly. If this test passes, you will see a page indicating a form was POSTed.
20 | 21 | 22 | -------------------------------------------------------------------------------- /webkit-tests/1.1/form-action-src-default-ignored.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 13 | 14 | 18 | 19 |Tests that allowed form actions work correctly. If this test passes, you will see a page indicating a form was POSTed.
20 | 21 | 22 | -------------------------------------------------------------------------------- /webkit-tests/1.1/form-action-src-get-allowed.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 13 | 14 | 18 | 19 |Tests that allowed form actions work correctly. If this test passes, you will see a page indicating a form was POSTed.
20 | 21 | 22 | -------------------------------------------------------------------------------- /webkit-tests/1.1/form-action-src-get-blocked.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 13 | 14 | 18 | 19 |Tests that allowed form actions work correctly. If this test passes, you will see a page indicating a form was POSTed.
20 | 21 | 22 | -------------------------------------------------------------------------------- /webkit-tests/1.1/form-action-src-javascript-blocked.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 13 | 14 | 15 | 19 | 20 |Tests that blocking form actions works correctly. If this test passes, you will see a console error, and will not see a JavaScript alert.
21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /webkit-tests/1.1/form-action-src-redirect-blocked.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 13 | 14 | 15 | 19 | 20 |Tests that blocking form redirect works correctly. If this test passes, you will see a console error, and will not see a page indicating a form was POSTed.
21 | 22 | 23 | -------------------------------------------------------------------------------- /webkit-tests/1.1/frame-allowed.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /webkit-tests/1.1/frame-blocked.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /webkit-tests/1.1/frame-redirect-blocked.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /webkit-tests/1.1/meta-outside-head.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 |This test checks that Content Security Policy delivered via a meta element is not enforced if the element is outside the document's head.
11 | 12 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /webkit-tests/1.1/plugintypes-notype-url.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Given a `plugin-types` directive, plugins have to declare a type explicitly. 8 | No declared type, no load. This test passes if there's a console message 9 | above. 10 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /webkit-tests/1.1/plugintypes-nourl-allowed.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | This test passes if there isn't a console message saying the plugin was blocked. 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /webkit-tests/1.1/scripthash-allowed.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 13 | 16 | 19 | 20 | 21 |22 | This tests the effect of a valid script-hash value. It passes if no 23 | console warning is visible, and the alert() is executed. 24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /webkit-tests/1.1/scripthash-basic-blocked.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 13 | 15 | 16 | 17 | 18 | 19 |20 | This tests the effect of a valid script-hash value, with one valid 21 | script and several invalid ones. It passes if one alert is executed 22 | and four console warings are visible. 23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /webkit-tests/1.1/scripthash-ignore-unsafeinline.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 13 | 14 | 15 |16 | This tests that a valid hash value disables inline JavaScript, even if 'unsafe-inline' is present. 17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /webkit-tests/1.1/scripthash-unicode-normalization.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 15 | 19 | 23 | 24 | 25 |26 | This tests Unicode normalization. While appearing the same, the 27 | strings in the scripts are different Unicode points, but through 28 | normalization, should be the same when the hash is taken. 29 |
30 | 31 | 32 | -------------------------------------------------------------------------------- /webkit-tests/1.1/scriptnonce-allowed.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 12 | 15 | 16 | 17 |18 | This tests the effect of a valid script-nonce value. It passes if 19 | no console warning is visible and the alerts are executed. 20 |
21 | 22 | 23 | -------------------------------------------------------------------------------- /webkit-tests/1.1/scriptnonce-and-scripthash.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 13 | 16 | 19 | 22 | 23 | 24 |25 | This tests the combined use of script hash and script nonce. It 26 | passes if two console warnings are visible and the three alerts show 27 | PASS. 28 |
29 | 30 | 31 | -------------------------------------------------------------------------------- /webkit-tests/1.1/scriptnonce-basic-blocked.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 13 | 16 | 19 | 22 | 23 | 24 |25 | This tests the effect of a valid script-nonce value. It passes if 26 | three console warnings are visible, and the two PASS alerts are 27 | executed. 28 |
29 | 30 | 31 | -------------------------------------------------------------------------------- /webkit-tests/1.1/scriptnonce-ignore-unsafeinline.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 12 | 15 | 18 | 19 | 20 |21 | This tests that a valid nonce disables inline JavaScript, even if 'unsafe-inline' is present. 22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /webkit-tests/1.1/stylehash-allowed.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |This tests the result of a valid style hash. It passes if this text is green, and a "PASS" alert for p1 is fired.
8 |This tests the result of a valid style hash. It passes if this text is green, and a "PASS" alert for p2 is fired.
9 |This tests the result of a valid style hash. It passes if this text is green, and a "PASS" alert for p3 is fired.
10 |This tests the result of a valid style hash. It passes if this text is green, and a "PASS" alert for p4 is fired.
11 | 12 | 13 | 14 | 15 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /webkit-tests/1.1/stylehash-basic-blocked.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |12 | This tests the effect of a valid style-hash value, with one valid 13 | style and several invalid ones. It passes if the valid style is applied 14 | and three console warnings are visible. 15 |
16 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /webkit-tests/1.1/stylenonce-allowed.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 11 | 16 | 21 | 22 | 23 |This text should be green.
24 |This text should also be green.
25 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /webkit-tests/1.1/stylenonce-blocked.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 |This text should be black.
13 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /webkit-tests/blob-urls-match-self.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |8 | blob: URLs are same-origin with the page in which they were created, 9 | and should therefore match the 'self' source in CSP directives. 10 |
11 | 12 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /webkit-tests/combine-multiple-policies.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | This test checks that we enforce all the supplied policies. This test passes 10 | if it doesn't alert fail and if the style doesn't apply. 11 | 14 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /webkit-tests/csptest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |11 | This tests the effect of duplicated directives. It passes if a 12 | console warning is visible, and the alert() is executed. 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /webkit-tests/eval-allowed-in-report-only-mode.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /webkit-tests/eval-allowed.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /webkit-tests/eval-blocked.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /webkit-tests/eval-scripts-setInterval-allowed.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |8 | 21 |22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /webkit-tests/eval-scripts-setInterval-blocked.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 21 |22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /webkit-tests/eval-scripts-setTimeout-allowed.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 20 |21 | 22 | 23 |