BigPizzaV3/CodexPlusPlus · error · anyhow::Error

Base URL 不得指向本机或私有网络

Error message

Base URL 不得指向本机或私有网络

What it means

validate_llm_proxy_url ends by checking the extracted host against is_blocked_llm_proxy_host, which matches localhost, loopback, and private-network names/IPs. This is an SSRF guard: the LLM Bridge must not be used to reach services on the operator's own machine or LAN.

Solutions

  1. Use the public HTTPS endpoint of the provider instead of a loopback/private address
  2. Expose the local server through a public HTTPS tunnel (e.g. ngrok/cloudflared) with a non-private hostname
  3. If local endpoints are legitimately required, adjust is_blocked_llm_proxy_host with an explicit opt-in allowlist

Example fix

// before
let url = validate_llm_proxy_url("https://localhost:8080/v1")?;
// after
let url = validate_llm_proxy_url("https://tunnel.example.com/v1")?; // public HTTPS hostname
Defensive patterns

Strategy: validation

Validate before calling

fn host_is_private(raw: &str) -> bool {
    reqwest::Url::parse(raw.trim()).ok()
        .and_then(|u| u.host_str().map(|h| h.to_owned()))
        .map(|h| { let l = h.to_lowercase(); l == "localhost" || l == "127.0.0.1" || l.ends_with(".local") || l.starts_with("10.") || l.starts_with("192.168.") || l.starts_with("172.") })
        .unwrap_or(false)
} // reject when true

Prevention

When it happens

Trigger: Calling llm_proxy_value with a Base URL whose host is "localhost", "127.0.0.1", a 10.x/192.168.x/172.16-31.x address, or other private/local host names.

Common situations: Trying to point the bridge at a locally running LLM server (ollama, llama.cpp) or an internal corporate gateway; testing against a dev server on the same machine.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/72e6e1c9eb7c12bc. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/routes.rs:796

        "ok": ok,
        "body_text": body_text,
        "body_json": body_json,
    }))
}

fn validate_llm_proxy_url(raw: &str) -> anyhow::Result<reqwest::Url> {
    let url = reqwest::Url::parse(raw.trim()).map_err(|_| anyhow::anyhow!("Base URL 格式无效"))?;
    if url.scheme() != "https" {
        anyhow::bail!("Base URL 必须使用 HTTPS");
    }
    if !url.username().is_empty() || url.password().is_some() {
        anyhow::bail!("Base URL 不得包含用户名或密码");
    }
    let host = url
        .host_str()
        .ok_or_else(|| anyhow::anyhow!("Base URL 缺少主机名"))?;
    if is_blocked_llm_proxy_host(host) {
        anyhow::bail!("Base URL 不得指向本机或私有网络");
    }
    Ok(url)
}

fn is_blocked_llm_proxy_host(host: &str) -> bool {
    let host = host
        .trim()
        .trim_start_matches('[')
        .trim_end_matches(']')
        .to_lowercase();
    if host.is_empty()
        || host == "localhost"
        || host.ends_with(".localhost")
        || host.ends_with(".local")
    {
        return true;
    }
    if let Ok(ip) = std::net::IpAddr::from_str(&host) {

View on GitHub (pinned to b1ed92e5e4)