diff options
author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2020-02-23 06:45:02 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-23 09:45:02 -0500 |
commit | e9fff02e9681f3eb2edee9f94db66b140e179899 (patch) | |
tree | debb7868de81f91e0f4e67a0bcf8cc592e9c8e2b /cli/ops | |
parent | bf48f5fa5a15e01d6f8b7eb7c3e70f6ecc91fa23 (diff) |
fetch: proper error for unsupported protocol (#4085)
Diffstat (limited to 'cli/ops')
-rw-r--r-- | cli/ops/fetch.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/cli/ops/fetch.rs b/cli/ops/fetch.rs index 580fd993a..9758732c7 100644 --- a/cli/ops/fetch.rs +++ b/cli/ops/fetch.rs @@ -1,6 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use super::dispatch_json::{Deserialize, JsonOp, Value}; use super::io::StreamResource; +use crate::deno_error::DenoError; +use crate::deno_error::ErrorKind; use crate::http_util::{create_http_client, HttpBody}; use crate::ops::json_op; use crate::state::State; @@ -40,6 +42,19 @@ pub fn op_fetch( }; let url_ = url::Url::parse(&url).map_err(ErrBox::from)?; + + // Check scheme before asking for net permission + let scheme = url_.scheme(); + if scheme != "http" && scheme != "https" { + return Err( + DenoError::new( + ErrorKind::TypeError, + format!("scheme '{}' not supported", scheme), + ) + .into(), + ); + } + state.check_net_url(&url_)?; let mut request = client.request(method, url_); |