Hmbown/CodeWhale · error · anyhow::Error

Refusing insecure base URL

Error message

Refusing insecure base URL '{display_base_url}'.

Loopback hosts (localhost, 127.0.0.1, [::1]) are auto-allowed.
For other trusted local hosts (LAN, llama.cpp on a private IP, etc.)
set the env var `{ALLOW_INSECURE_HTTP_ENV}=1` in the shell that runs codewhale and re-run.

Example: `{ALLOW_INSECURE_HTTP_ENV}=1 codewhale` (note the underscores).

What it means

The HTTP client guards its base URL: plain http:// is allowed only for loopback hosts (localhost, 127.0.0.1, [::1]) or when CODEWHALE_ALLOW_INSECURE_HTTP=1 (legacy alias DEEPSEEK_ALLOW_INSECURE_HTTP) is set to 1/true in the environment. For any other http:// host this error is returned, with the URL shown redacted. The check exists because an insecure base URL sends your API key and prompts in cleartext.

Solutions

  1. Use the https:// URL when the server supports TLS.
  2. For a trusted LAN host, launch with CODEWHALE_ALLOW_INSECURE_HTTP=1 codewhale (export it in the shell that runs codewhale; DEEPSEEK_ALLOW_INSECURE_HTTP also works as a legacy alias).
  3. Tunnel the remote host to loopback (ssh -N -L 8080:host:8080) and use http://127.0.0.1:8080, which is auto-allowed.
  4. Fix scheme typos — most cloud providers are https-only.

Example fix

# before
export CODEWHALE_BASE_URL=http://192.168.1.20:11434/v1
codewhale   # Refusing insecure base URL

# after (trusted LAN host)
CODEWHALE_ALLOW_INSECURE_HTTP=1 codewhale

# after (safer: loopback tunnel)
ssh -N -L 11434:192.168.1.20:11434 lanbox &
codewhale   # base URL http://127.0.0.1:11434/v1
Defensive patterns

Strategy: validation

Validate before calling

fn base_url_allowed(url: &str) -> bool {
    let scheme_ok = url.starts_with("https://")
        || url.starts_with("http://localhost")
        || url.starts_with("http://127.0.0.1")
        || url.starts_with("http://[::1]");
    scheme_ok || std::env::var("CODEWHALE_ALLOW_INSECURE_HTTP").as_deref() == Ok("1")
}

Prevention

When it happens

Trigger: Constructing the client with base_url = http://192.168.1.20:11434/v1 (LAN ollama/llama.cpp box), http://myserver.local/api, or any non-loopback http URL while neither allow-insecure env var is set.

Common situations: Pointing codewhale at a LAN LLM server; using a plain-http reverse proxy on a trusted host; typing http:// instead of https:// for a cloud provider endpoint.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20). Data as JSON: /api/errors/bf5902fd36cbb024. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/client.rs:681

    {
        return Ok(());
    }

    if base_url.starts_with("http://")
        && std::env::var(ALLOW_INSECURE_HTTP_ENV)
            .or_else(|_| std::env::var(LEGACY_ALLOW_INSECURE_HTTP_ENV))
            .ok()
            .as_deref()
            .is_some_and(|v| v == "1" || v.eq_ignore_ascii_case("true"))
    {
        logging::warn(format!(
            "Using insecure HTTP base URL because {ALLOW_INSECURE_HTTP_ENV} is set"
        ));
        return Ok(());
    }

    if base_url.starts_with("http://") {
        anyhow::bail!(
            "Refusing insecure base URL '{display_base_url}'.\n\
             \n\
             Loopback hosts (localhost, 127.0.0.1, [::1]) are auto-allowed.\n\
             For other trusted local hosts (LAN, llama.cpp on a private IP, etc.)\n\
             set the env var `{ALLOW_INSECURE_HTTP_ENV}=1` in the shell that runs codewhale and re-run.\n\
             \n\
             Example: `{ALLOW_INSECURE_HTTP_ENV}=1 codewhale` (note the underscores).",
        );
    }

    anyhow::bail!(
        "Refusing base URL '{display_base_url}': only HTTPS (or explicitly allowed HTTP) URLs are supported.",
    )
}

pub(crate) fn redact_url_for_display(url: &str) -> String {
    let Ok(mut parsed) = reqwest::Url::parse(url) else {
        return url.to_string();

View on GitHub (pinned to 0c42157ee5)