Commit ee0d0e6e authored by Oleg's avatar Oleg

Add more thorough check for CSP violations

parent c66a5e70
<?php
file_put_contents("csp.log", "", LOCK_EX);
?>
<?php
file_put_contents("csp.log", "error", LOCK_EX);
?>
<?php <?php
# Support: Firefox # This test page checkes CSP only for browsers with "Content-Security-Policy" header support
header("X-Content-Security-Policy: default-src 'self';"); # i.e. no old WebKit or old Firefox
header("Content-Security-Policy: default-src 'self'; report-uri csp-log.php");
# 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'");
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
......
...@@ -30,6 +30,24 @@ if ( jQuery.css ) { ...@@ -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() { (function() {
var expected, version, var expected, version,
userAgent = window.navigator.userAgent; userAgent = window.navigator.userAgent;
...@@ -175,17 +193,3 @@ if ( jQuery.css ) { ...@@ -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" );
}
);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment