-
Notifications
You must be signed in to change notification settings - Fork 20.6k
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
getScript requires 'unsafe-inline' CSP rule #3969
Comments
|
Thanks for the report. This looks like a duplicate of #3541 so I'm closing it. |
|
I am not sure that the linked PR in #3541 resolves this problem. It is similar problem, but I am not sure it's the same that's why I opened this issue. |
|
Yeah i don't think it's the same. You can avoid the problem by adding a nonce or hash but we should discuss whether to always inject a script tag for external files. |
|
It would be great workaround for me if you could add a global flag for jQuery or an AFAIS this could be a workaround for those who disabled the |
|
Ideally, as I suggested in #3541 (comment), we'd feature detect Feature detection ideas welcome! |
|
I'll add this to the |
|
Hmm, instead of detecting var cspMode = ( function() {
try {
new Function( "" );
return false;
} catch ( e ) {
return true;
}
} )();This is similar to what e.g. AngularJS does. What do you think? |
|
Agreed on 3.4.0 and landing this with gh-3782 would be nice in order to deal with all CSP issues in one release. I think it would be better and more consistent to always use a script tag regardless of CSP, if we have to make an exception for Android 4.0 to work then we'd only get/eval there. @koczkatamas In general we've sworn off global flags because they make it very difficult for a large page full of plugins written at different times by different people to depend on consistent behavior. The Keep in mind that this won't help the original case you linked to since they were using jQuery 1.12 which has not been maintained for a while. They would need to update to 3.4.0 to get this fix. |
|
@dmethvin If you can auto-detect The issue I linked was opened by somebody else, we are using jQuery 3 and we are prepared to switch to latest jQuery at any time. (Especially if the CSP fix lands.) @mgol please note that I am not sure how, but I think Angular (at least the latest versions) solves this otherwise. We use Angular and we don't get any |
@dmethvin It's not just Android 4.0 but all <=4.3. How would you make an exception for those Android Browsers without UA-sniffing? |
|
@mgol yeah it looks like although Android sets the property to a function if you create an attribute, it doesn't run the function on a 404. Maybe it does on a script error but I didn't try. |
|
To document what was discussed in the meeting today, we SHOULD support restrictive CSP configuration but MUST NOT break currently-working strict ordering of script evaluation in |
|
Per last meeting, the workaround here is to set |
|
@timmywil is it possible to set |
|
@graingert instead of |
|
Just noting here that when gh-3782 lands it will be possible to use the Note that because things like |
|
just a question @dmethvin how do I now use a Thanks |
|
When gh-3782 lands you would use |
|
@dmethvin perfect, I see that such commit was already merged into the main branch, and I wait then to the next version. Thank you |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
So, trying to follow progress. what was done to resolve jquery from returning an inline script? Or whatever fix was done to permit a secure CSP? |
|
@pir8radio it seems from jquery 3.2.0, you can use something like this: $.ajax({
dataType : "script",
url : "https://some/path",
attrs : { nonce: "EDNnf03nceIOfn39fn3e9h3sdfa" },
success : callback
}); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I've just looked at this issue and I'm a bit puzzled by @gibson042's comment:
Maybe I'm missing something but this seems to concern synchronous script execution that we do during DOM manipulation but this issue is about |
Until now, the AJAX script transport only used a script tag to load scripts for cross-domain requests or ones with `scriptAttrs` set. This commit makes it also used for all async requests to avoid CSP errors arising from usage of inline scripts. This also makes `jQuery.getScript` not trigger CSP errors as it uses the AJAX script transport under the hood. For sync requests such a change is impossible and that's what `jQuery._evalUrl` uses. Fixing that is tracked in jquerygh-1895. The commit also makes other type of requests using the script tag version of the script transport set its type to "GET", namely async scripts & ones with `scriptAttrs` set in addition to the existing cross-domain ones. Fixes jquerygh-3969
|
PR: #4763. |
|
Adding the |
Until now, the AJAX script transport only used a script tag to load scripts for cross-domain requests or ones with `scriptAttrs` set. This commit makes it also used for all async requests to avoid CSP errors arising from usage of inline scripts. This also makes `jQuery.getScript` not trigger CSP errors as it uses the AJAX script transport under the hood. For sync requests such a change is impossible and that's what `jQuery._evalUrl` uses. Fixing that is tracked in jquerygh-1895. The commit also makes other type of requests using the script tag version of the script transport set its type to "GET", namely async scripts & ones with `scriptAttrs` set in addition to the existing cross-domain ones. Fixes jquerygh-3969
Until now, the AJAX script transport only used a script tag to load scripts for cross-domain requests or ones with `scriptAttrs` set. This commit makes it also used for all async requests to avoid CSP errors arising from usage of inline scripts. This also makes `jQuery.getScript` not trigger CSP errors as it uses the AJAX script transport under the hood. For sync requests such a change is impossible and that's what `jQuery._evalUrl` uses. Fixing that is tracked in gh-1895. The commit also makes other type of requests using the script tag version of the script transport set its type to "GET", namely async scripts & ones with `scriptAttrs` set in addition to the existing cross-domain ones. Fixes gh-3969 Closes gh-4763
jQuery should be able to load scripts via
$.getScriptwithout causingunsafe-inlineCSP violations.Look at the following test case:
index.html
payload.js
If you click on the
Load script via jQuerybutton the following error is shown in the browser's console (Chrome in this case):On the other hand if you click on the
Load script via script tagbutton then the script is loaded without issues and the textOKis shown in the console.Note: I am reporting this issue, because third-party libraries use
$.getScript()and they consider this a jQuery issue (rightly) and won't fix this by their own because they expect the fix from jQuery.For example see this issue: jackocnr/intl-tel-input#541
Security considerations
Using constructs which require
unsafe-inlineorunsafe-evalare generally not recommended and the security community considers them as bad practice.Mozilla MDN states the following about
unsafe-inline:Google recommends the same in their Web Fundamentals guide
So I hope you will consider changing the current behavior for the sake of a safer web (taking into account how widespread your library is).
The text was updated successfully, but these errors were encountered: