-
Notifications
You must be signed in to change notification settings - Fork 74
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
Allow guarding (dynamic) module imports - a type for module specifiers #117
Comments
There actually are some prior ideas about point 1 (adding metadata): https://discourse.wicg.io/t/specifying-nonce-or-integrity-when-importing-modules/1861 If these were implemented, at least the nonce or hash value could be generated and inserted server-side. That still doesn't solve point 2. (Trusted Types are at runtime), unless there's some code that can run in a non-module script first that populates the whitelist, e.g. <script>
TrustedTypes.allowedScriptModules.push(modulePolicy.createTrustedScriptURL(foo))
TrustedTypes.allowedScriptModules.push(modulePolicy.createTrustedScriptURL('bar'))
</script>
<script type=module>
import {baz} from 'bazinga' // only works if allowedScriptModules contains 'bazinga'
</script> |
https://github.com/WICG/import-maps just surfaced and looks like an interesting mechanism to control / guard modules used by the application. There's two important issues though:
|
@koto, I'll play around to see whether there's a way to whitelist by having a single unscoped mapping like |
UpdateSince #117 (comment) dynamic import has been accepted as stage 4 and will be part of EcmaScript 2020. Stage 0 Dynamic Import Host Adjustment builds on that to allow vetting, and applying default policies to the argument to |
Open question: What is a conforming argument to
|
The neccessary primitive in the language to be able to guard module imports is tracked in the dynamic import host adjustment TC39 proposal. |
Closing until after we have the necessary ECMAScript bits. |
Script modules are here i.e. there is a way of loading additional code from a URL to your application (previously you'd just append a new script, or
eval
). These come in a few flavors:import {foo} from 'url'
import(foo).then()
import {foo} from 'a.html'
These new code loading methods introduce a few interesting challenges:
For CSP side of things, this realistically means that only the
script-src
whitelist can somehow guard which modules are allowed to be run (example problem). I'm not sure if and how Trusted Types can offer something here as well, given that they are a runtime feature.Mentioning a related issue as well, as it seems these concerns (code isolation, module limitations) are raised by other folks as well.
cc @arturjanc who raised the issue.
The text was updated successfully, but these errors were encountered: