~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix(web): validate custom endpoint by provider (#5255)
March-77451a5c85ce5c
diff --git a/changelog.d/5255.bugfix.md b/changelog.d/5255.bugfix.mdnew file mode 100644index 0000000000..47895ed469--- /dev/null+++ b/changelog.d/5255.bugfix.md@@ -0,0 +1 @@+Prevent unused OpenAI-compatible endpoint settings from blocking research with other model providers.diff --git a/src/local_deep_research/web/routes/research_routes.py b/src/local_deep_research/web/routes/research_routes.pyindex 3726aa4c87..3789f63d49 100644--- a/src/local_deep_research/web/routes/research_routes.py+++ b/src/local_deep_research/web/routes/research_routes.py@@ -149,14 +149,16 @@ def _extract_research_params(data, settings_manager):else:logger.debug(f"Using model from request: {model}")- custom_endpoint = data.get("custom_endpoint")- if not custom_endpoint and model_provider == "openai_endpoint":- custom_endpoint = settings_manager.get_setting(- "llm.openai_endpoint.url", None- )- logger.debug(- f"No custom_endpoint in request, using database setting: {custom_endpoint}"- )+ custom_endpoint = None+ if model_provider == "openai_endpoint":+ custom_endpoint = data.get("custom_endpoint")+ if not custom_endpoint:+ custom_endpoint = settings_manager.get_setting(+ "llm.openai_endpoint.url", None+ )+ logger.debug(+ f"No custom_endpoint in request, using database setting: {custom_endpoint}"+ )ollama_url = data.get("ollama_url")if not ollama_url and model_provider == "ollama":@@ -654,7 +656,9 @@ def start_research():# client is built. Private IPs / localhost are permitted so local LLMs# (vLLM, Ollama, LM Studio) work, including scheme-less endpoints# (the helper normalizes exactly as the provider does).- if not is_safe_custom_llm_endpoint(custom_endpoint):+ if model_provider == "openai_endpoint" and not is_safe_custom_llm_endpoint(+ custom_endpoint+ ):return (jsonify({"status": "error", "message": "Invalid custom endpoint URL"}diff --git a/tests/web/routes/test_research_routes_extracted_helpers.py b/tests/web/routes/test_research_routes_extracted_helpers.pyindex d1d54804c9..70fb644bab 100644--- a/tests/web/routes/test_research_routes_extracted_helpers.py+++ b/tests/web/routes/test_research_routes_extracted_helpers.py@@ -155,12 +155,18 @@ class TestExtractResearchParams:assert result["strategy"] == "source-based"def test_custom_endpoint_only_for_openai_endpoint(self):- """custom_endpoint is only fetched from DB when provider is OPENAI_ENDPOINT."""+ """custom_endpoint is only accepted for the OPENAI_ENDPOINT provider."""sm = _make_settings_manager({"llm.openai_endpoint.url": "http://custom.api"})- # OLLAMA provider — should not fetch custom_endpoint- result = self._call({"model_provider": "OLLAMA"}, sm)+ # Other providers ignore both request and saved OpenAI endpoint values.+ result = self._call(+ {+ "model_provider": "LMSTUDIO",+ "custom_endpoint": "http://169.254.169.254/latest/meta-data/",+ },+ sm,+ )assert result["custom_endpoint"] is None# OPENAI_ENDPOINT provider — should fetch from DBdiff --git a/tests/web/routes/test_research_routes_start_research_coverage.py b/tests/web/routes/test_research_routes_start_research_coverage.pyindex d2095e9374..18df0d1d5c 100644--- a/tests/web/routes/test_research_routes_start_research_coverage.py+++ b/tests/web/routes/test_research_routes_start_research_coverage.py@@ -369,6 +369,7 @@ class TestStartResearchCustomEndpointSSRF:json={"query": "anything","model": "gpt-4",+ "model_provider": "OPENAI_ENDPOINT","custom_endpoint": self._AWS_METADATA,},content_type="application/json",@@ -394,6 +395,7 @@ class TestStartResearchCustomEndpointSSRF:json={"query": "anything","model": "gpt-4",+ "model_provider": "OPENAI_ENDPOINT","custom_endpoint": "not-a-url",},content_type="application/json",@@ -435,6 +437,7 @@ class TestStartResearchCustomEndpointSSRF:json={"query": "anything","model": "gpt-4",+ "model_provider": "OPENAI_ENDPOINT","custom_endpoint": "http://localhost:11434/v1",},content_type="application/json",@@ -444,6 +447,51 @@ class TestStartResearchCustomEndpointSSRF:data = resp.get_json()assert data["status"] == "success"+ def test_unrelated_endpoint_ignored_for_lmstudio(self, client, app):+ """A stale OpenAI endpoint must not block an LM Studio run."""+ ms = _mock_db_session()+ _configure_ms_for_active(ms, active_count=0, max_pos=0)+ sm = _make_settings_manager(provider="LMSTUDIO", model="local-model")+ fake_thread = MagicMock(spec=threading.Thread)+ fake_thread.ident = 99++ @app.before_request+ def _inject_g():+ g.db_session = ms++ with (+ patch(_GET_USER_DB, side_effect=_ctx_factory(ms)),+ patch(_SM_MANAGER, return_value=sm),+ patch(_SM_SETTINGS, return_value=sm),+ patch(+ f"{MODULE}.is_safe_custom_llm_endpoint"+ ) as mock_endpoint_validator,+ patch(+ f"{MODULE}.start_research_process", return_value=fake_thread+ ) as mock_spawn,+ patch(_SAVE_STRATEGY),+ patch(f"{MODULE}.log_settings"),+ patch(_SESSION_PW_STORE) as mock_sps,+ patch(f"{MODULE}.ResearchHistory"),+ patch(f"{MODULE}.UserActiveResearch"),+ ):+ mock_sps.get_session_password.return_value = "pw"++ resp = client.post(+ "/api/start_research",+ json={+ "query": "anything",+ "model": "local-model",+ "model_provider": "LMSTUDIO",+ "custom_endpoint": self._AWS_METADATA,+ },+ content_type="application/json",+ )++ assert resp.status_code == 200+ mock_endpoint_validator.assert_not_called()+ assert mock_spawn.call_args.kwargs["custom_endpoint"] is None+class TestStartResearchShouldQueue:"""active_count >= max_concurrent -> research gets queued."""