-
Notifications
You must be signed in to change notification settings - Fork 72
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
Import maps should be controlled by CSP #105
Comments
I think Import Maps should be subject to For example: say I have a CSP defined that blocks scripts not in a given list of sources:
As long as the resulting mapped import is subject to CSP constraints, it's still possible to prevent loading of any unknown code via Import Maps: <script type="importmap">
{ "imports": {
"@std/kv-storage": [
"@std/kv-storage",
"/kvs-polyfill.mjs"
]
} }
</script> import 'main.js' // ok
import 'libs.js' // ok
import '@std/kv-storage' // violation What's unclear to me, however, is whether the violation is triggered for |
CSS also isn't executable, but IIUC Would it be so bad to just expect authors to use a hash or nonce in such cases (or to put import maps in a different CSP bucket, if that would be too cumbersome)? |
I feel we should apply at least all CSP restrictions that are currently applied to inline scripts also to import maps, because even though import maps are not "executable" in a strict meaning, they still can affect fetching and execution of other scripts. |
For script, CSP generally acts in two places:
Import maps adds a third, which are the "resources" quasi-fetched as part of the standard library. I think I accept the notion that built-ins aren't actually fetched, and are part of the platform, and I'm not sure there's value in trying to govern their accessibility via CSP. @developit's example above matches my understanding of how we'd want to handle the second case. If Governing the |
I've commented about this here. If platform will fix all vulnerabilities or gadgets in the standard library, then I'm fine with not adding standard library under CSP governance. Though,if DOM manipulation in standard library increases (e.g. things like |
If we have a standard library, it seems to me that we need to treat it as we would any other API provided by the browser. I'm 100% sure that we'll introduce bugs along the way; I'm looking forward to folks like you holding our feet to the fire to fix them. :) |
Import maps, if they are in the DOM like proposed, should be covered by the standard CSP I don't think we should treat import maps as anything less than regular scripts. |
To synthesize what has been said above, and articulate a success condition: Problem Statement
Success condition: Compatibility in the face of injection for non-adoptersIt'd be nice to see an argument in the explainer about how a document that
loads equivalent JavaScript regardless of whether the browser supports import mapping. |
I think Domenic's proposed fix addresses the compatibility argument, as long as it follows the same (script-src falling back to default-src) path used for The Security Considerations verbiage might look like:
Some white-listed origins host user-contributed content. Often they check extensions or content-types, and are careful not to serve user-contributed content with The proposal could mitigated this by requiring a Content-type that is not unadorned application/json.
We should probably not accept any JSON MIME type. |
This incorporates the conclusion at the end of WICG#105 (comment) > We should probably not accept any JSON MIME type. based on the assumptions made by existing hosting providers and JSON-producing web services as to what can be safely hosted on origins that appear on CSP source white lists.
By the way, I'm interested in @koto's following comment:
Do you have alternative designs for this? Do you have a github issue to discuss this point? |
The spec now covers this, I believe, as do the web platform tests. Happy to reopen if we missed something, but if not, closing for now! |
I believe that, since the threat model of CSP is "someone is able to inject script into my page but I still want to prevent bad things from happening", we need import maps to be controlled by CSP as well. If a malicious actor can inject an import map, then they can change the behavior of scripts on the page (similar to overwriting
self.fetch()
, or inserting a<base>
tag, or similar). So CSP should stop that as well.This issue can be closed when there is an actual spec which includes these protections.
The text was updated successfully, but these errors were encountered: