1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 21:50:00 -05:00

fix: net permissions didn't account for default ports (#6606)

This commit is contained in:
Jacob Gee-Clarke 2020-07-02 15:16:41 +01:00 committed by GitHub
parent 8a14eafaff
commit 74c260517a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -291,9 +291,10 @@ impl Permissions {
.to_owned(),
));
}
Ok(
self.get_state_net(&format!("{}", parsed.host().unwrap()), parsed.port()),
)
Ok(self.get_state_net(
&format!("{}", parsed.host().unwrap()),
parsed.port_or_known_default(),
))
}
pub fn check_net(&self, hostname: &str, port: u16) -> Result<(), OpError> {
@ -308,7 +309,7 @@ impl Permissions {
.host_str()
.ok_or_else(|| OpError::uri_error("missing host".to_owned()))?;
self
.get_state_net(host, url.port())
.get_state_net(host, url.port_or_known_default())
.check(&format!("network access to \"{}\"", url), "--allow-net")
}
@ -629,7 +630,8 @@ mod tests {
"deno.land",
"github.com:3000",
"127.0.0.1",
"172.16.0.2:8000"
"172.16.0.2:8000",
"www.github.com:443"
],
..Default::default()
});
@ -692,6 +694,8 @@ mod tests {
("https://172.16.0.2:6000", false),
("tcp://172.16.0.1:8000", false),
("https://172.16.0.1:8000", false),
// Testing issue #6531 (Network permissions check doesn't account for well-known default ports) so we dont regress
("https://www.github.com:443/robots.txt", true),
];
for (url_str, is_ok) in url_tests.iter() {