summaryrefslogtreecommitdiff
path: root/cli/module_graph.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-05-21 13:06:12 +0200
committerGitHub <noreply@github.com>2020-05-21 13:06:12 +0200
commit5f9c1c7da6047ee8612e71f8ef4ca9c950b3a699 (patch)
tree7a2175a4c8c9a694924dad5183790d3c75a8bf5e /cli/module_graph.rs
parentbebb8c029fff56f3a6e653b757583ab5c1d4b11f (diff)
fix: disallow http imports for modules loaded over https (#5680)
Diffstat (limited to 'cli/module_graph.rs')
-rw-r--r--cli/module_graph.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/cli/module_graph.rs b/cli/module_graph.rs
index 21e575cfd..e03468679 100644
--- a/cli/module_graph.rs
+++ b/cli/module_graph.rs
@@ -274,6 +274,8 @@ impl ModuleGraphLoader {
Ok(())
}
+ // TODO(bartlomieju): decorate errors with import location in the source code
+ // https://github.com/denoland/deno/issues/5080
fn download_module(
&mut self,
module_specifier: ModuleSpecifier,
@@ -283,6 +285,18 @@ impl ModuleGraphLoader {
return Ok(());
}
+ // Disallow http:// imports from modules loaded over https://
+ if let Some(referrer) = maybe_referrer.as_ref() {
+ if let "https" = referrer.as_url().scheme() {
+ if let "http" = module_specifier.as_url().scheme() {
+ let e = OpError::permission_denied(
+ "Modules loaded over https:// are not allowed to import modules over http://".to_string()
+ );
+ return Err(e.into());
+ };
+ };
+ };
+
if !self.is_dyn_import {
// Verify that remote file doesn't try to statically import local file.
if let Some(referrer) = maybe_referrer.as_ref() {
@@ -293,7 +307,9 @@ impl ModuleGraphLoader {
match specifier_url.scheme() {
"http" | "https" => {}
_ => {
- let e = OpError::permission_denied("Remote module are not allowed to statically import local modules. Use dynamic import instead.".to_string());
+ let e = OpError::permission_denied(
+ "Remote modules are not allowed to statically import local modules. Use dynamic import instead.".to_string()
+ );
return Err(e.into());
}
}