New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
src
attribute, I get a CSPscript-src
violation error. Tested with current master branch.Since
domManip
usesjQuery_evalUrl
for script tags withsrc
attribute it violates CSP's with a nonce script rule. I'am aware of #3969 (comment) but I can't usecrossDomain
since I require sync script loading. The following fix seems only to work for scripts withoutsrc
attribute 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
_evalUrl
which will be passed tojQuery.globalEval
./manipulation.js:159
In my tests I noticed that the
nonce
attribute 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: