{"record":{"id":"f0f3f9f40f7ff12d","repo":"BigPizzaV3/CodexPlusPlus","slug":"base-url-f0f3f9","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":790,"sourceCode":"        None\n    };\n\n    Ok(json!({\n        \"status\": \"ok\",\n        \"http_status\": http_status,\n        \"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\"","sourceCodeStart":772,"sourceCodeEnd":808,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/routes.rs#L772-L808","documentation":"In validate_llm_proxy_url, after the HTTPS check, the URL's username() or password() being non-empty triggers this bail. Embedded credentials (user:pass@host) in the Base URL would leak secrets into logs and error messages, so such URLs are rejected.","triggerScenarios":"Calling llm_proxy_value with a URL like \"https://user:pass@api.example.com\" — url.username() is non-empty or url.password() is Some.","commonSituations":"Copying a gateway URL that includes basic-auth credentials, or configuring an API key directly in the URL instead of the auth header.","solutions":["Remove the userinfo portion of the URL and pass credentials via an Authorization header instead","Use an API-key config field rather than embedding secrets in the Base URL","If the endpoint truly requires basic auth, front it with a proxy that adds the header"],"exampleFix":"// before\nlet url = validate_llm_proxy_url(\"https://sk-abc123@api.example.com/v1\")?;\n// after\nlet url = validate_llm_proxy_url(\"https://api.example.com/v1\")?;\n// pass key via Authorization header separately","handlingStrategy":"validation","validationCode":"fn url_has_userinfo(raw: &str) -> bool {\n    reqwest::Url::parse(raw.trim()).map(|u| !u.username().is_empty() || u.password().is_some()).unwrap_or(false)\n} // reject when true","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep credentials out of URLs; use header-based auth","Lint config files for 'user:pass@' patterns in URLs","Store API keys in dedicated config fields"],"tags":["url","security","credentials"],"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"}