IP range denylist logging, and fix logic error

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-01-24 15:51:13 -05:00 committed by June
parent 382347353e
commit 89d9cdeb3a
2 changed files with 18 additions and 4 deletions

View file

@ -133,7 +133,10 @@ where
} }
if destination.is_ip_literal() { if destination.is_ip_literal() {
info!("Destination is an IP literal, checking against IP range denylist."); info!(
"Destination {} is an IP literal, checking against IP range denylist.",
destination
);
let ip = IPAddress::parse(destination.host()).map_err(|e| { let ip = IPAddress::parse(destination.host()).map_err(|e| {
warn!("Failed to parse IP literal from string: {}", e); warn!("Failed to parse IP literal from string: {}", e);
Error::BadServerResponse("Invalid IP address") Error::BadServerResponse("Invalid IP address")
@ -146,13 +149,17 @@ where
cidr_ranges.push(IPAddress::parse(cidr).expect("we checked this at startup")); cidr_ranges.push(IPAddress::parse(cidr).expect("we checked this at startup"));
} }
debug!("List of pushed CIDR ranges: {:?}", cidr_ranges);
for cidr in cidr_ranges { for cidr in cidr_ranges {
if ip.includes(&cidr) { if cidr.includes(&ip) {
return Err(Error::BadServerResponse( return Err(Error::BadServerResponse(
"Not allowed to send requests to this IP", "Not allowed to send requests to this IP",
)); ));
} }
} }
info!("IP literal {} is allowed.", destination);
} }
debug!("Preparing to send request to {destination}"); debug!("Preparing to send request to {destination}");

View file

@ -718,7 +718,10 @@ impl Service {
T: Debug, T: Debug,
{ {
if destination.is_ip_literal() { if destination.is_ip_literal() {
info!("Destination is an IP literal, checking against IP range denylist."); info!(
"Destination {} is an IP literal, checking against IP range denylist.",
destination
);
let ip = IPAddress::parse(destination.host()).map_err(|e| { let ip = IPAddress::parse(destination.host()).map_err(|e| {
warn!("Failed to parse IP literal from string: {}", e); warn!("Failed to parse IP literal from string: {}", e);
Error::BadServerResponse("Invalid IP address") Error::BadServerResponse("Invalid IP address")
@ -731,13 +734,17 @@ impl Service {
cidr_ranges.push(IPAddress::parse(cidr).expect("we checked this at startup")); cidr_ranges.push(IPAddress::parse(cidr).expect("we checked this at startup"));
} }
debug!("List of pushed CIDR ranges: {:?}", cidr_ranges);
for cidr in cidr_ranges { for cidr in cidr_ranges {
if ip.includes(&cidr) { if cidr.includes(&ip) {
return Err(Error::BadServerResponse( return Err(Error::BadServerResponse(
"Not allowed to send requests to this IP", "Not allowed to send requests to this IP",
)); ));
} }
} }
info!("IP literal {} is allowed.", destination);
} }
debug!("Waiting for permit"); debug!("Waiting for permit");