1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-21 23:04:45 -05:00

fix(flags): properly error out for urls (#25770)

Closes https://github.com/denoland/deno/issues/25760
This commit is contained in:
Leo Kettmeir 2024-09-20 11:10:46 -07:00 committed by GitHub
parent 92fc702cec
commit 3e053f8f06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View file

@ -5084,12 +5084,12 @@ fn permission_args_parse(
}
if let Some(net_wl) = matches.remove_many::<String>("allow-net") {
let net_allowlist = flags_net::parse(net_wl.collect()).unwrap();
let net_allowlist = flags_net::parse(net_wl.collect())?;
flags.permissions.allow_net = Some(net_allowlist);
}
if let Some(net_wl) = matches.remove_many::<String>("deny-net") {
let net_denylist = flags_net::parse(net_wl.collect()).unwrap();
let net_denylist = flags_net::parse(net_wl.collect())?;
flags.permissions.deny_net = Some(net_denylist);
}
@ -10801,4 +10801,18 @@ mod tests {
["foo,", "bar"]
);
}
#[test]
fn net_flag_with_url() {
let r = flags_from_vec(svec![
"deno",
"run",
"--allow-net=https://example.com",
"script.ts"
]);
assert_eq!(
r.unwrap_err().to_string(),
"error: invalid value 'https://example.com': URLs are not supported, only domains and ips"
);
}
}

View file

@ -894,6 +894,10 @@ impl QueryDescriptor for NetDescriptor {
// TODO(bartlomieju): rewrite to not use `AnyError` but a specific error implementations
impl NetDescriptor {
pub fn parse(hostname: &str) -> Result<Self, AnyError> {
if hostname.starts_with("http://") || hostname.starts_with("https://") {
return Err(uri_error(format!("invalid value '{hostname}': URLs are not supported, only domains and ips")));
}
// If this is a IPv6 address enclosed in square brackets, parse it as such.
if hostname.starts_with('[') {
if let Some((ip, after)) = hostname.split_once(']') {