{"record":{"id":"72e6e1c9eb7c12bc","repo":"BigPizzaV3/CodexPlusPlus","slug":"base-url-72e6e1","errorCode":null,"errorMessage":"Base URL 不得指向本机或私有网络","messagePattern":"Base URL 不得指向本机或私有网络","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/routes.rs","lineNumber":796,"sourceCode":"        \"ok\": ok,\n        \"body_text\": body_text,\n        \"body_json\": body_json,\n    }))\n}\n\nfn validate_llm_proxy_url(raw: &str) -> anyhow::Result<reqwest::Url> {\n    let url = reqwest::Url::parse(raw.trim()).map_err(|_| anyhow::anyhow!(\"Base URL 格式无效\"))?;\n    if url.scheme() != \"https\" {\n        anyhow::bail!(\"Base URL 必须使用 HTTPS\");\n    }\n    if !url.username().is_empty() || url.password().is_some() {\n        anyhow::bail!(\"Base URL 不得包含用户名或密码\");\n    }\n    let host = url\n        .host_str()\n        .ok_or_else(|| anyhow::anyhow!(\"Base URL 缺少主机名\"))?;\n    if is_blocked_llm_proxy_host(host) {\n        anyhow::bail!(\"Base URL 不得指向本机或私有网络\");\n    }\n    Ok(url)\n}\n\nfn is_blocked_llm_proxy_host(host: &str) -> bool {\n    let host = host\n        .trim()\n        .trim_start_matches('[')\n        .trim_end_matches(']')\n        .to_lowercase();\n    if host.is_empty()\n        || host == \"localhost\"\n        || host.ends_with(\".localhost\")\n        || host.ends_with(\".local\")\n    {\n        return true;\n    }\n    if let Ok(ip) = std::net::IpAddr::from_str(&host) {","sourceCodeStart":778,"sourceCodeEnd":814,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/routes.rs#L778-L814","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use the public HTTPS endpoint of the provider instead of a loopback/private address","Expose the local server through a public HTTPS tunnel (e.g. ngrok/cloudflared) with a non-private hostname","If local endpoints are legitimately required, adjust is_blocked_llm_proxy_host with an explicit opt-in allowlist"],"exampleFix":"// before\nlet url = validate_llm_proxy_url(\"https://localhost:8080/v1\")?;\n// after\nlet url = validate_llm_proxy_url(\"https://tunnel.example.com/v1\")?; // public HTTPS hostname","handlingStrategy":"validation","validationCode":"fn host_is_private(raw: &str) -> bool {\n    reqwest::Url::parse(raw.trim()).ok()\n        .and_then(|u| u.host_str().map(|h| h.to_owned()))\n        .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.\") })\n        .unwrap_or(false)\n} // reject when true","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use public HTTPS endpoints for LLM proxies","Tunnel local dev servers via a public HTTPS hostname","Treat SSRF blocking as intentional; don't bypass it for local services without an explicit allowlist"],"tags":["ssrf","security","url"],"backgroundTag":"invalid-argument-value","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}