Hmbown/CodeWhale · error · anyhow::Error

Refusing base URL ' ': only HTTPS (or explicitly allowed…

Error message

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

What it means

This is a fail-closed security guard in the client's base-URL validation: it refuses any provider base_url whose scheme is not HTTPS. HTTP (plaintext) base URLs are only permitted when the user has explicitly opted in via `allow_insecure_http = true` in the provider's `[providers.<name>]` config table or via the ALLOW_INSECURE_HTTP_ENV environment variable, because plaintext HTTP exposes API keys and message contents on the wire.

Solutions

  1. Switch the provider base_url to an HTTPS endpoint (e.g. https://...).
  2. If the endpoint is genuinely local or trusted HTTP, add `allow_insecure_http = true` under its `[providers.<name>]` table in config.toml.
  3. Alternatively set the shell env var ALLOW_INSECURE_HTTP_ENV=1 to allow HTTP for every provider in this shell, then re-run.
  4. If you meant HTTPS but typed http://, fix the scheme typo.

Example fix

# before (config.toml)
[providers.ollama]
base_url = "http://localhost:11434"

# after
[providers.ollama]
base_url = "http://localhost:11434"
allow_insecure_http = true
Defensive patterns

Strategy: validation

Validate before calling

fn ensure_https(base_url: &str, allow_http: bool) -> Result<(), String> {
    let url = url::Url::parse(base_url).map_err(|e| format!("invalid base URL: {e}"))?;
    match url.scheme() {
        "https" => Ok(()),
        "http" if allow_http => Ok(()),
        _ => Err(format!("base URL must be HTTPS (got '{}'); set allow_insecure_http to permit HTTP", url.scheme())),
    }
}

Type guard

fn is_https(url: &str) -> bool {
    url::Url::parse(url).map(|u| u.scheme() == "https").unwrap_or(false)
}

Prevention

When it happens

Trigger: Configuring a `[providers.<name>]` base_url starting with `http://` (or scheme-less) in config.toml and starting a session; a provider preset/default pointing at a local plaintext endpoint (e.g. http://localhost:11434) without opting in.

Common situations: Pointing Codewhale at a local LLM server (Ollama, llama.cpp, LM Studio) using its http:// URL; copying an on-prem gateway URL that is plain HTTP; typos like `http://https://...`.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


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

Appendix: source

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

        logging::warn(format!(
            "Using insecure HTTP base URL because {ALLOW_INSECURE_HTTP_ENV} is set"
        ));
        return Ok(());
    }

    if parsed.scheme() == "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 one trusted local provider (LAN, llama.cpp on a private IP, etc.) set\n\
             `allow_insecure_http = true` under its `[providers.<name>]` table in config.toml.\n\
             To allow it for every provider in this shell instead, set the env var\n\
             `{ALLOW_INSECURE_HTTP_ENV}=1` and re-run.",
        );
    }

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

/// Mask credentials in a URL for display.
///
/// Delegates to the single shared implementation in
/// [`codewhale_secrets::sanitize`] (FEAT-025 D4) so command sanitization and
/// client diagnostics cannot drift.
pub(crate) fn redact_url_for_display(url: &str) -> String {
    codewhale_secrets::sanitize::redact_url_for_display(url)
}

pub(super) fn versioned_base_url(base_url: &str) -> String {
    let trimmed = base_url.trim_end_matches('/');
    if base_url_has_version_suffix(trimmed) {
        trimmed.to_string()
    } else {

View on GitHub (pinned to 73e0f67d83)