]> source.dussan.org Git - jquery.git/commitdiff
Add more thorough check for CSP violations
authorOleg <markelog@gmail.com>
Wed, 30 Oct 2013 12:20:38 +0000 (16:20 +0400)
committerOleg <markelog@gmail.com>
Thu, 7 Nov 2013 19:16:19 +0000 (20:16 +0100)
test/data/support/csp-clean.php [new file with mode: 0644]
test/data/support/csp-log.php [new file with mode: 0644]
test/data/support/csp.log [new file with mode: 0755]
test/data/support/csp.php
test/unit/support.js

diff --git a/test/data/support/csp-clean.php b/test/data/support/csp-clean.php
new file mode 100644 (file)
index 0000000..e16d047
--- /dev/null
@@ -0,0 +1,3 @@
+<?php
+       file_put_contents("csp.log", "", LOCK_EX);
+?>
diff --git a/test/data/support/csp-log.php b/test/data/support/csp-log.php
new file mode 100644 (file)
index 0000000..efbb9d7
--- /dev/null
@@ -0,0 +1,3 @@
+<?php
+       file_put_contents("csp.log", "error", LOCK_EX);
+?>
diff --git a/test/data/support/csp.log b/test/data/support/csp.log
new file mode 100755 (executable)
index 0000000..e69de29
index b21ce0f745039c48e4f078b6d7d07bc726b1aca0..d01def783f081194b902eaeb0ec3eb86a242bdbb 100644 (file)
@@ -1,12 +1,7 @@
 <?php
-       # Support: Firefox
-       header("X-Content-Security-Policy: default-src 'self';");
-
-       # Support: Webkit, Safari 5
-       # http://stackoverflow.com/questions/13663302/why-does-my-content-security-policy-work-everywhere-but-safari
-       header("X-WebKit-CSP: script-src " . $_SERVER["HTTP_HOST"] . " 'self'");
-
-       header("Content-Security-Policy: default-src 'self'");
+       # This test page checkes CSP only for browsers with "Content-Security-Policy" header support
+       # i.e. no old WebKit or old Firefox
+       header("Content-Security-Policy: default-src 'self'; report-uri csp-log.php");
 ?>
 <!DOCTYPE html>
 <html>
index 08685def17ec8b4416b62f914ec2461794e8eafa..965ea4cdd16a25ce50c3cf3ca49a358c19880a25 100644 (file)
@@ -30,6 +30,24 @@ if ( jQuery.css ) {
        });
 }
 
+
+// This test checkes CSP only for browsers with "Content-Security-Policy" header support
+// i.e. no old WebKit or old Firefox
+testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Security/CSP) restrictions",
+       "support/csp.php",
+       function( support ) {
+               expect( 2 );
+               deepEqual( jQuery.extend( {}, support ), computedSupport, "No violations of CSP polices" );
+
+               stop();
+
+               supportjQuery.get( "data/support/csp.log" ).done(function( data ) {
+                       equal( data, "", "No log request should be sent" );
+                       supportjQuery.get( "data/support/csp-clean.php" ).done( start );
+               });
+       }
+);
+
 (function() {
        var expected, version,
                userAgent = window.navigator.userAgent;
@@ -175,17 +193,3 @@ if ( jQuery.css ) {
        }
 
 })();
-
-// Support: Safari 5.1
-// Shameless browser-sniff, but Safari 5.1 mishandles CSP
-if ( !( typeof navigator !== "undefined" &&
-       (/ AppleWebKit\/\d.*? Version\/(\d+)/.exec(navigator.userAgent) || [])[1] < 6 ) ) {
-
-       testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Security/CSP) restrictions",
-               "support/csp.php",
-               function( support ) {
-                       expect( 1 );
-                       deepEqual( jQuery.extend( {}, support ), computedSupport, "No violations of CSP polices" );
-               }
-       );
-}