Hmbown/CodeWhale · error · anyhow::Error

The Codewhale service returned an untrusted verification…

Error message

The Codewhale service returned an untrusted verification origin

What it means

Thrown by `validate_verification_url` in crates/cli/src/cloud.rs:1071 when the API base is the canonical `https://api.codewhale.net` (port 443) but the verification URL is not served from the matching trusted origin: scheme must be https, host must be app.codewhale.net (case-insensitive), and the port must resolve to 443. Anything else is rejected as an untrusted origin the browser should not be pointed at.

Solutions

  1. Make the device-authorization endpoint return `https://app.codewhale.net/cli/authorize` when the API base is canonical api.codewhale.net
  2. Remove explicit ports from the verification URL (443 is implied for https)
  3. Check whether a proxy or env override is intercepting traffic and returning a non-production URL; unset the override and retry
  4. If this is a legit test environment, set the API base to a loopback host instead, which the CLI permits

Example fix

// before
{ "verification_url": "http://app.codewhale.net:8443/cli/authorize" }
// after
{ "verification_url": "https://app.codewhale.net/cli/authorize" }
Defensive patterns

Strategy: validation

Validate before calling

fn is_trusted_origin(value: &str) -> bool {
    url::Url::parse(value).map(|u| {
        u.scheme() == "https"
            && u.host_str().map(|h| h.eq_ignore_ascii_case("app.codewhale.net")).unwrap_or(false)
            && u.port_or_known_default() == Some(443)
    }).unwrap_or(false)
}

Type guard

fn verification_origin_canonical(value: &str) -> bool {
    matches!(url::Url::parse(value).ok(), Some(u)
        if u.scheme() == "https"
            && u.host_str().is_some_and(|h| h.eq_ignore_ascii_case("app.codewhale.net"))
            && u.port_or_known_default() == Some(443))
}

Try / catch

match run_device_login() {
    Err(e) if e.to_string().contains("untrusted verification origin") => {
        eprintln!("Verification URL is not on https://app.codewhale.net:443; refusing.");
    }
    other => return other,
}

Prevention

When it happens

Trigger: Using the production API while the device-authorization response returns a verification URL on a different host (`verify.staging.codewhale.net`), a non-https scheme (`http://app.codewhale.net/cli/authorize`), or an explicit non-443 port (`https://app.codewhale.net:8443/cli/authorize`).

Common situations: A corporate proxy or custom CODEWHALE_API_BASE value makes the CLI think it is on canonical API while a test environment hands back a staging verification host; server misconfiguration emitting http or an alternate port; DNS hijack serving a look-alike host.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/954592712b0afa4c. Report an issue: GitHub.

Appendix: source

Thrown at crates/cli/src/cloud.rs:1071

    })?;
    if !url.username().is_empty() || url.password().is_some() || url.fragment().is_some() {
        bail!("The Codewhale service returned an unsafe verification URL");
    }
    if url.path() != "/cli/authorize" {
        bail!("The Codewhale service returned an unsafe verification URL");
    }

    let api = Url::parse(api_base).context("invalid Codewhale account API base URL")?;
    let canonical_api = api.scheme() == "https"
        && api.host_str() == Some("api.codewhale.net")
        && api.port_or_known_default() == Some(443);
    let loopback_api = api.host_str().is_some_and(is_loopback_host);
    if canonical_api {
        if url.scheme() != "https"
            || !host.eq_ignore_ascii_case("app.codewhale.net")
            || url.port_or_known_default() != Some(443)
        {
            bail!("The Codewhale service returned an untrusted verification origin");
        }
    } else if loopback_api {
        if !matches!(url.scheme(), "http" | "https") || !is_loopback_host(host) {
            bail!("The Codewhale service returned an untrusted verification origin");
        }
    } else {
        bail!(
            "Browser login is only enabled for the canonical Codewhale account API or a loopback test API"
        );
    }

    let query = url.query_pairs().collect::<Vec<_>>();
    if complete {
        if query.len() != 1 || query[0].0 != "user_code" || query[0].1 != user_code {
            bail!("The Codewhale service returned an unsafe verification URL");
        }
    } else if !query.is_empty() {
        bail!("The Codewhale service returned an unsafe verification URL");

View on GitHub (pinned to 73e0f67d83)