tinyhumansai/openhuman · error · anyhow::Error

URL port must be numeric

Error message

URL port must be numeric

What it means

extract_port split the authority on the last ':' and the right-hand side is not a parseable number, so no port can be derived for the request; this catches malformed authorities like 'host:abc'.

Source

Thrown at src/openhuman/tools/impl/network/url_guard.rs:276

fn extract_port(url: &str) -> anyhow::Result<u16> {
    let is_http = url.starts_with("http://");
    let rest = url
        .strip_prefix("http://")
        .or_else(|| url.strip_prefix("https://"))
        .ok_or_else(|| anyhow::anyhow!("Only http:// and https:// URLs are allowed"))?;

    let authority = rest
        .split(['/', '?', '#'])
        .next()
        .ok_or_else(|| anyhow::anyhow!("Invalid URL"))?;

    if authority.starts_with('[') {
        anyhow::bail!("IPv6 hosts are not supported in http_request");
    }

    if let Some((_, port)) = authority.rsplit_once(':') {
        if port.is_empty() || !port.chars().all(|ch| ch.is_ascii_digit()) {
            anyhow::bail!("URL port must be numeric");
        }
        return port
            .parse::<u16>()
            .map_err(|_| anyhow::anyhow!("URL port is out of range"));
    }

    Ok(if is_http { 80 } else { 443 })
}

pub(super) fn host_matches_allowlist(host: &str, allowed_domains: &[String]) -> bool {
    allowed_domains.iter().any(|domain| {
        // `"*"` is the explicit allow-all wildcard (the "Allow all sites"
        // toggle), mirroring the browser tool. Local/private hosts are still
        // rejected upstream by `is_private_or_local_host`, so a wildcard only
        // opens *public* hosts, never the loopback/RFC1918 SSRF surface.
        domain == "*"
            || host == domain
            || host

View on GitHub (pinned to 7491200858)

Solutions

  1. Omit the port to use the scheme default (80/443)
  2. Write the port in decimal form, e.g. 'https://host:8443/path'
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/openhuman/tools/impl/network/url_guard.rs:276 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of tinyhumansai/openhuman@7491200858 (2026-08-17). Data as JSON: /api/errors/ed92af23bff84c84. Report an issue: GitHub.