Skip to content

Commit

Permalink
resolve static dns mappings in http-acl
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDiam0nd committed Sep 10, 2023
1 parent 669b1ea commit 5bd7fac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/wasi-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bytes = { workspace = true }
hyper = { version = "=1.0.0-rc.3", features = ["full"] }
tokio = { version = "1", default-features = false, features = ["net", "rt-multi-thread", "time"] }
http = { version = "0.2.9" }
http-acl = "0.5.3"
http-acl = "0.5.4"
http-body = "1.0.0-rc.2"
http-body-util = "0.1.0-rc.2"
thiserror = { workspace = true }
Expand Down
32 changes: 21 additions & 11 deletions crates/wasi-http/src/http_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,24 @@ impl WasiHttp {
bail!("Port {} is not allowed - {}", port, acl_port_match);
}

let mut static_dns_mapping = false;

let tcp_addresses = match &authority.host {
http_acl::utils::authority::Host::Domain(domain) => {
let acl_host_match = self.acl.is_host_allowed(domain);
if acl_host_match.is_denied() {
bail!("Host {} is not allowed - {}", domain, acl_host_match);
}
if let Some(tcp_address) = self.acl.resolve_static_dns_mapping(domain) {
static_dns_mapping = true;

vec![tcp_address]
} else {
let acl_host_match = self.acl.is_host_allowed(domain);
if acl_host_match.is_denied() {
bail!("Host {} is not allowed - {}", domain, acl_host_match);
}

tokio::net::lookup_host(&(domain.clone() + ":" + &port.to_string()))
.await?
.collect::<Vec<_>>()
tokio::net::lookup_host(&(domain.clone() + ":" + &port.to_string()))
.await?
.collect::<Vec<_>>()
}
}
http_acl::utils::authority::Host::Ip(ip) => {
let acl_ip_match = self.acl.is_ip_allowed(ip);
Expand All @@ -139,10 +147,12 @@ impl WasiHttp {
}
};

for tcp_address in &tcp_addresses {
let acl_ip_match = self.acl.is_ip_allowed(&tcp_address.ip());
if acl_ip_match.is_denied() {
bail!("IP {} is not allowed - {}", tcp_address.ip(), acl_ip_match);
if !static_dns_mapping {
for tcp_address in &tcp_addresses {
let acl_ip_match = self.acl.is_ip_allowed(&tcp_address.ip());
if acl_ip_match.is_denied() {
bail!("IP {} is not allowed - {}", tcp_address.ip(), acl_ip_match);
}
}
}

Expand Down

0 comments on commit 5bd7fac

Please sign in to comment.