Merge commit from fork
Signed-off-by: IAmTomahawkx <iamtomahawkx@gmail.com>
This commit is contained in:
@@ -419,21 +419,22 @@ impl Request {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn url_is_blacklisted(url: &Url) -> Result<IPRequest> {
|
pub async fn url_is_blacklisted(url: &Url) -> Result<IPRequest> {
|
||||||
let resolved_address: IpAddr;
|
let mut resolved_address: Option<IpAddr> = None;
|
||||||
|
|
||||||
if let Some(host) = url.host() {
|
if let Some(host) = url.host() {
|
||||||
match host {
|
match host {
|
||||||
Host::Ipv4(ipv4) => {
|
Host::Ipv4(ipv4) => {
|
||||||
resolved_address = ipv4.into();
|
|
||||||
if !IP_BLOCKLIST.is_allowed(&ipv4.to_string()) {
|
if !IP_BLOCKLIST.is_allowed(&ipv4.to_string()) {
|
||||||
return Err(create_error!(InvalidOperation));
|
return Err(create_error!(InvalidOperation));
|
||||||
}
|
}
|
||||||
|
resolved_address = Some(ipv4.into());
|
||||||
}
|
}
|
||||||
Host::Ipv6(ipv6) => {
|
Host::Ipv6(ipv6) => {
|
||||||
resolved_address = ipv6.into();
|
let string = ipv6.to_string();
|
||||||
if !IP_BLOCKLIST.is_allowed(&ipv6.to_string()) {
|
if string.contains("::ffff:") || !IP_BLOCKLIST.is_allowed(&string) {
|
||||||
return Err(create_error!(InvalidOperation));
|
return Err(create_error!(InvalidOperation));
|
||||||
}
|
}
|
||||||
|
resolved_address = Some(ipv6.into());
|
||||||
}
|
}
|
||||||
Host::Domain(domain) => {
|
Host::Domain(domain) => {
|
||||||
let domain = domain.to_string();
|
let domain = domain.to_string();
|
||||||
@@ -449,7 +450,7 @@ impl Request {
|
|||||||
|
|
||||||
// Second step: resolve the IP and check the blocklist
|
// Second step: resolve the IP and check the blocklist
|
||||||
let resolver = CachedDnsResolver {};
|
let resolver = CachedDnsResolver {};
|
||||||
if let Ok(mut resolved_ip) = resolver
|
if let Ok(resolved_ips) = resolver
|
||||||
.resolve(
|
.resolve(
|
||||||
Name::from_str(&domain)
|
Name::from_str(&domain)
|
||||||
.map_err(|_| create_error!(ProxyError))
|
.map_err(|_| create_error!(ProxyError))
|
||||||
@@ -457,16 +458,14 @@ impl Request {
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
if let Some(resolved_ip) = resolved_ip.next() {
|
for resolved in resolved_ips {
|
||||||
resolved_address = resolved_ip.ip();
|
resolved_address = Some(resolved.ip()); // last resolved ip will be the one we hit as a consequence of this for loop.
|
||||||
let resolved_string = resolved_address.to_string();
|
let resolved_string = resolved_address.unwrap().to_string();
|
||||||
if !IP_BLOCKLIST.is_allowed(&resolved_string)
|
if !IP_BLOCKLIST.is_allowed(&resolved_string)
|
||||||
|| resolved_string.contains("::ffff:")
|
|| resolved_string.contains("::ffff:")
|
||||||
{
|
{
|
||||||
return Err(create_error!(InvalidOperation));
|
return Err(create_error!(InvalidOperation));
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return Err(create_error!(InvalidOperation));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(create_error!(ProxyError));
|
return Err(create_error!(ProxyError));
|
||||||
@@ -477,9 +476,13 @@ impl Request {
|
|||||||
return Err(create_error!(ProxyError));
|
return Err(create_error!(ProxyError));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if resolved_address.is_none() {
|
||||||
|
return Err(create_error!(InvalidOperation));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(IPRequest {
|
Ok(IPRequest {
|
||||||
url: url.clone(),
|
url: url.clone(),
|
||||||
ip: resolved_address,
|
ip: resolved_address.unwrap(),
|
||||||
blocked: false,
|
blocked: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user