-
Notifications
You must be signed in to change notification settings - Fork 78
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
Consider adding import-src #506
Comments
Can you sketch out /cc @lweichselbaum @koto |
There are mainly 2 reasons why we'd probably want to implement
I feel like we should probably separate mitigation for import mechanism out of The suggestion I made about |
Thanks! I still don't think I understand the distinction you're drawing between imports and plain ol' scripts. What's a policy you'd recommend that folks construct that would apply specific mitigations for |
I don't have answers, only more questions :) It kinda depends on two things:
A similar syntax is used for importing JS and non-JS modules, and it's probable these would behave and evolve in a similar way in EcmaScript. They already do - e.g. both can already be loaded dynamically, or statically. If we want to put guards on these specific behaviours, it might make sense to start afresh and put them together under a separate directive and a set of keywords instead of complicating the If we don't plan to guard non-JS modules, and only focus on JS ones, If import maps ship, the advantage of a separate directive is that we could separately guard on module specifiers and resulting URLs:
If we think there's value in guarding module specifiers and not URLs, and expect import maps to ship, that directive is also a better fit for new keywords e.g. |
Alternatively, we could:
Essentially, I think the problem boils down to dynamic import. The only way to guard it now is by CSP |
Plain scripts can be mitigated with nonce, but While a keyword like With that probably recommended (for now) CSP that demonstrates good use of
Import maps requires script tags, therefore it can be mitigated by nonce. So, I'm not terribly concerned about that.
Agreed that the main problem we have right now is dynamic import. |
JavaScript is capable of loading other scripts (e.g. static and dynamic import).
But it can also load modules like JSON, CSS, and (in the future) HTML.
Issues 243 acknowledges that there is an issue with dynamic import, but we aren't making progress there.
We should probably start a discussion about
import-src
that fallback toscript-src
, where we can control those import behavior from JS (which I believe bypasses nonce-based CSP).In addition to allow-list based based blocking mechanism, it'll be interesting to consider keywords that only denies dynamic import (e.g.
import-src 'allow-static-import'
), or something that allows import with TrustedScriptURL (not sure if this is doable though).P.S.
I intentionally haven't mentioned
importScripts
, because that's probably controlled byworker-src
.The text was updated successfully, but these errors were encountered: