summaryrefslogtreecommitdiff
path: root/runtime/permissions/mod.rs
diff options
context:
space:
mode:
authorIan Bull <irbull@gmail.com>2023-12-01 19:03:53 +0100
committerGitHub <noreply@github.com>2023-12-01 19:03:53 +0100
commite087851e5422010e2fde5ae291632668d8514c1a (patch)
treefd727c5bbfdfcaa180ca4f18ef12adf6d2d098a9 /runtime/permissions/mod.rs
parentfc8f060ee3e87c81a2073279a2720b423965d68f (diff)
fix(perm): allow-net with port 80 (#21221)
Diffstat (limited to 'runtime/permissions/mod.rs')
-rw-r--r--runtime/permissions/mod.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/runtime/permissions/mod.rs b/runtime/permissions/mod.rs
index cb1af7619..75d4af1c7 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<Self, Self::Err> {
- 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),