Skip to content

Commit 405d2b6

Browse files
factorydroidechobt
authored andcommitted
fix(cli): warn when serve --host uses broadcast or special addresses
Fixes bounty issue #1632 Add validation for the --host argument in the serve command to warn users when they specify problematic IP addresses such as broadcast addresses (255.255.255.255), multicast addresses (224.0.0.0 - 239.255.255.255), or documentation addresses. These addresses cannot be properly bound and would result in confusing errors.
1 parent 3022681 commit 405d2b6

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

cortex-cli/src/main.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,9 +824,58 @@ async fn list_features() -> Result<()> {
824824
Ok(())
825825
}
826826

827+
/// Check if an IP address is a special address that may cause issues when binding.
828+
/// Returns Some(warning_message) if the address is problematic, None otherwise.
829+
fn check_special_ip_address(host: &str) -> Option<&'static str> {
830+
use std::net::IpAddr;
831+
832+
let ip: IpAddr = match host.parse() {
833+
Ok(ip) => ip,
834+
Err(_) => return None, // Not a valid IP, could be a hostname - let the server handle it
835+
};
836+
837+
match ip {
838+
IpAddr::V4(ipv4) => {
839+
// Broadcast address
840+
if ipv4.is_broadcast() {
841+
return Some(
842+
"Warning: 255.255.255.255 is the broadcast address and cannot be used for binding a server.",
843+
);
844+
}
845+
// Multicast addresses (224.0.0.0 - 239.255.255.255)
846+
if ipv4.is_multicast() {
847+
return Some(
848+
"Warning: Multicast addresses (224.0.0.0 - 239.255.255.255) are not suitable for binding a server.",
849+
);
850+
}
851+
// Documentation addresses (reserved for documentation, not routable)
852+
if ipv4.is_documentation() {
853+
return Some(
854+
"Warning: Documentation addresses (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24) are reserved and may not work as expected.",
855+
);
856+
}
857+
}
858+
IpAddr::V6(ipv6) => {
859+
// Multicast addresses
860+
if ipv6.is_multicast() {
861+
return Some(
862+
"Warning: IPv6 multicast addresses are not suitable for binding a server.",
863+
);
864+
}
865+
}
866+
}
867+
868+
None
869+
}
870+
827871
async fn run_serve(serve_cli: ServeCommand) -> Result<()> {
828872
use cortex_engine::MdnsService;
829873

874+
// Validate the host address and warn about special addresses
875+
if let Some(warning) = check_special_ip_address(&serve_cli.host) {
876+
eprintln!("{}", warning);
877+
}
878+
830879
let config = cortex_app_server::ServerConfig {
831880
listen_addr: format!("{}:{}", serve_cli.host, serve_cli.port),
832881
..Default::default()

0 commit comments

Comments
 (0)