Skip to content

Commit 1c3c709

Browse files
committed
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 8f839ec commit 1c3c709

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
@@ -820,9 +820,58 @@ async fn list_features() -> Result<()> {
820820
Ok(())
821821
}
822822

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

870+
// Validate the host address and warn about special addresses
871+
if let Some(warning) = check_special_ip_address(&serve_cli.host) {
872+
eprintln!("{}", warning);
873+
}
874+
826875
let config = cortex_app_server::ServerConfig {
827876
listen_addr: format!("{}:{}", serve_cli.host, serve_cli.port),
828877
..Default::default()

0 commit comments

Comments
 (0)