Preserve CSP nonce on scripts with src attribute in DOM manipulation. #4323
Comments
|
Thanks for the report! The Since you found the issue and the possible solution, would you want to take a stab at solving this issue (I can help)? We plan to release jQuery 3.4.0 soon so if this doesn't land soon it'll have to wait until the next release. |
|
Thanks for the clarification, I'll have a look as soon as I can. |
|
PR: #4328 |
When appending html content containing script tags with
srcattribute, I get a CSPscript-srcviolation error. Tested with current master branch.Since
domManipusesjQuery_evalUrlfor script tags withsrcattribute it violates CSP's with a nonce script rule. I'am aware of #3969 (comment) but I can't usecrossDomainsince I require sync script loading. The following fix seems only to work for scripts withoutsrcattribute https://github.com/jquery/jquery/pull/4269/files.The problematic line:
jquery/src/manipulation.js
Line 202 in 5bdc85b
Hacky fix:
manipulation/_evalUrl.js:
Adding a node parameter to
_evalUrlwhich will be passed tojQuery.globalEval./manipulation.js:159
In my tests I noticed that the
nonceattribute is not accessible anymore after the script nodes were added byappendChild()(if CSP is active). A dirty workaround was to backup the nonce attributes before inserting the dom like this:The text was updated successfully, but these errors were encountered: