// Optional AJAX dependency, but won't run scripts if not present
if ( jQuery._evalUrl && !node.noModule ) {
- jQuery._evalUrl( node.src );
+ jQuery._evalUrl( node.src, {
+ nonce: node.nonce || node.getAttribute( "nonce" )
+ } );
}
} else {
DOMEval( node.textContent.replace( rcleanScript, "" ), node, doc );
"use strict";
-jQuery._evalUrl = function( url ) {
+jQuery._evalUrl = function( url, options ) {
return jQuery.ajax( {
url: url,
"text script": function() {}
},
dataFilter: function( response ) {
- jQuery.globalEval( response );
+ jQuery.globalEval( response, options );
}
} );
};
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>CSP nonce via jQuery.globalEval Test Page</title>
+ <script nonce="jquery+hardcoded+nonce" src="../jquery.js"></script>
+ <script nonce="jquery+hardcoded+nonce" src="iframeTest.js"></script>
+ <script nonce="jquery+hardcoded+nonce" src="csp-nonce-external.js"></script>
+</head>
+<body>
+ <p>CSP nonce for external script Test Page</p>
+</body>
+</html>
QUnit[ /\bedge\/|iphone os [789]|android 4\./i.test( navigator.userAgent ) ? "skip" : "test" ]
);
+testIframe(
+ "Check if CSP nonce is preserved for external scripts with src attribute",
+ "mock.php?action=cspNonce&test=external",
+ function( assert, jQuery, window, document ) {
+ var done = assert.async();
+
+ assert.expect( 1 );
+
+ supportjQuery.get( baseURL + "support/csp.log" ).done( function( data ) {
+ assert.equal( data, "", "No log request should be sent" );
+ supportjQuery.get( baseURL + "mock.php?action=cspClean" ).done( done );
+ } );
+ },
+
+ // Support: Edge 18+, iOS 7-9 only, Android 4.0-4.4 only
+ // Edge doesn't support nonce in non-inline scripts.
+ // See https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/13246371/
+ // Old iOS & Android Browser versions support script-src but not nonce, making this test
+ // impossible to run. Browsers not supporting CSP at all are not a problem as they'll skip
+ // script-src restrictions completely.
+ QUnit[ /\bedge\/|iphone os [789]|android 4\./i.test( navigator.userAgent ) ? "skip" : "test" ]
+);
+
testIframe(
"jQuery.globalEval supports nonce",
"mock.php?action=cspNonce&test=globaleval",