-
Notifications
You must be signed in to change notification settings - Fork 20.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attributes: Don't stringify attributes in the setter
Stringifying attributes in the setter was needed for IE <=9 but it breaks trusted types enforcement when setting a script `src` attribute. Note that this doesn't mean script execution works. Since jQuery disables all scripts by changing their type and then executes them by creating fresh script tags with proper `src` & possibly other attributes, this unwraps any trusted `src` wrappers, making the script not execute under strict CSP settings. We might try to fix it in the future in a separate change. Fixes gh-4948 Closes gh-4949
- Loading branch information
Showing
6 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset=utf-8 /> | ||
<title>Trusted HTML attribute tests</title> | ||
</head> | ||
<body> | ||
<div id="qunit-fixture"></div> | ||
<script src="../../dist/jquery.js"></script> | ||
<script src="iframeTest.js"></script> | ||
<script> | ||
var i, input, elem, policy, | ||
results = []; | ||
|
||
function runTests( messagePrefix, getTrustedScriptUrlWrapper ) { | ||
try { | ||
elem = jQuery( "<script><\/script>" ) | ||
.attr( "src", getTrustedScriptUrlWrapper( "trusted-types-attributes.js" ) ); | ||
elem.appendTo( document.body ); | ||
|
||
results.push( { | ||
actual: elem.attr( "src" ), | ||
expected: "trusted-types-attributes.js", | ||
message: messagePrefix + ": script URL properly set" | ||
} ); | ||
} catch ( e ) { | ||
results.push( { | ||
actual: "error thrown", | ||
expected: "", | ||
message: messagePrefix + ": error has been thrown" | ||
} ); | ||
} | ||
} | ||
|
||
if ( typeof trustedTypes !== "undefined" ) { | ||
policy = trustedTypes.createPolicy( "jquery-test-policy", { | ||
createScriptURL: function( html ) { | ||
return html; | ||
} | ||
} ); | ||
|
||
runTests( "TrustedScriptURL", function wrapInTrustedScriptUrl( input ) { | ||
return policy.createScriptURL( input ); | ||
} ); | ||
} else { | ||
|
||
// No TrustedScriptURL support so let's at least run tests with object wrappers | ||
// with a proper `toString` function. See trusted-html.html for more context. | ||
runTests( "Object wrapper", function( input ) { | ||
return { | ||
toString: function toString() { | ||
return input; | ||
} | ||
}; | ||
} ); | ||
} | ||
|
||
startIframeTest( results ); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
window.testMessage = "script run"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters