Merge pull request #3271 from Aneesh-382005/fix/local-model-validation-bypass

fix: generalize local-model validation bypass beyond Ollama tags
This commit is contained in:
Bellman authored and GitHub committed 2026-10-13 07:13:39 +09:00
commit 8aeef8d2e2
6 files changed
+89 -7

No files matched your search

+17
View File
@@ -262,4 +262,21 @@ mod tests {
other => panic!("Expected ProviderClient::OpenAi for local model, got: {other:?}"),
}
}
#[test]
fn is_local_openai_compatible_base_url_is_reachable_via_crate_root() {
// Regression: this helper must stay `pub` and re-exported from the
// crate root so `rusty-claude-cli`'s model-syntax validation can
// reuse the same local/private-address detection used here to
// waive the API-key requirement.
assert!(crate::is_local_openai_compatible_base_url(
"http://127.0.0.1:1234/v1"
));
assert!(crate::is_local_openai_compatible_base_url(
"http://192.168.1.50:8000/v1"
));
assert!(!crate::is_local_openai_compatible_base_url(
"https://openrouter.ai/api/v1"
));
}
}
+3 -3
View File
@@ -22,9 +22,9 @@ pub use prompt_cache::{
pub use providers::anthropic::{AnthropicClient, AnthropicClient as ApiClient, AuthSource};
pub use providers::openai_compat::{
build_chat_completion_request, check_request_body_size, estimate_request_body_size,
flatten_tool_result_content, is_reasoning_model, model_rejects_is_error_field,
model_requires_reasoning_content_in_history, translate_message, OpenAiCompatClient,
OpenAiCompatConfig,
flatten_tool_result_content, is_local_openai_compatible_base_url, is_reasoning_model,
model_rejects_is_error_field, model_requires_reasoning_content_in_history, translate_message,
OpenAiCompatClient, OpenAiCompatConfig,
};
pub use providers::{
detect_provider_kind, max_tokens_for_model, max_tokens_for_model_with_override,
@@ -1027,7 +1027,12 @@ fn url_host(url: &str) -> &str {
host_port.split(':').next().unwrap_or("")
}
fn is_local_openai_compatible_base_url(url: &str) -> bool {
/// Returns true when `url`'s host is loopback or a private-network address
/// (`localhost`, `127.0.0.1`, `10.x`, `192.168.x`, `172.16-31.x`). Used to
/// waive auth requirements for local OpenAI-compatible servers (Ollama, LM
/// Studio, llama.cpp, vLLM) that don't expect a real API key.
#[must_use]
pub fn is_local_openai_compatible_base_url(url: &str) -> bool {
let host = url_host(url.trim());
if host.eq_ignore_ascii_case("localhost") || host == "::1" {
return true;