From e087851e5422010e2fde5ae291632668d8514c1a Mon Sep 17 00:00:00 2001 From: Ian Bull Date: Fri, 1 Dec 2023 19:03:53 +0100 Subject: [PATCH] fix(perm): allow-net with port 80 (#21221) --- runtime/permissions/mod.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/runtime/permissions/mod.rs b/runtime/permissions/mod.rs index cb1af76196..75d4af1c74 100644 --- a/runtime/permissions/mod.rs +++ b/runtime/permissions/mod.rs @@ -559,8 +559,14 @@ impl FromStr for NetDescriptor { type Err = AnyError; fn from_str(s: &str) -> Result { - let url = url::Url::parse(&format!("http://{s}"))?; - let hostname = url.host_str().unwrap().to_string(); + // Set the scheme to `unknown` to parse the URL, as we really don't know + // what the scheme is. We only using Url::parse to parse the host and port + // and don't care about the scheme. + let url = url::Url::parse(&format!("unknown://{s}"))?; + let hostname = url + .host_str() + .ok_or(url::ParseError::EmptyHost)? + .to_string(); Ok(NetDescriptor(hostname, url.port())) } @@ -2273,7 +2279,9 @@ mod tests { "github.com:3000", "127.0.0.1", "172.16.0.2:8000", - "www.github.com:443" + "www.github.com:443", + "80.example.com:80", + "443.example.com:443" ]), ..Default::default() }) @@ -2297,6 +2305,9 @@ mod tests { ("172.16.0.2", 0, false), ("172.16.0.2", 6000, false), ("172.16.0.1", 8000, false), + ("443.example.com", 444, false), + ("80.example.com", 81, false), + ("80.example.com", 80, true), // Just some random hosts that should err ("somedomain", 0, false), ("192.168.0.1", 0, false),