~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: harden prefix boundary check in module path normalization (#2847)
LearningCircuitf9ee0202e55e
diff --git a/src/local_deep_research/security/module_whitelist.py b/src/local_deep_research/security/module_whitelist.pyindex e049846fcd..8a4f0258fc 100644--- a/src/local_deep_research/security/module_whitelist.py+++ b/src/local_deep_research/security/module_whitelist.py@@ -203,7 +203,7 @@ def get_safe_module_class(# paths like "local_deep_research.web_search_engines.engines.search_engine_X"# instead of the required relative form ".engines.search_engine_X"._ABSOLUTE_PREFIX = "local_deep_research.web_search_engines"- if module_path and module_path.startswith(_ABSOLUTE_PREFIX):+ if module_path and module_path.startswith(_ABSOLUTE_PREFIX + "."):original = module_pathmodule_path = module_path[len(_ABSOLUTE_PREFIX) :]logger.debug(diff --git a/src/local_deep_research/web_search_engines/search_engines_config.py b/src/local_deep_research/web_search_engines/search_engines_config.pyindex e2df935951..17409119c2 100644--- a/src/local_deep_research/web_search_engines/search_engines_config.py+++ b/src/local_deep_research/web_search_engines/search_engines_config.py@@ -124,7 +124,9 @@ def search_config(if isinstance(engine_data, dict):for key in ("module_path", "full_search_module"):mp = engine_data.get(key)- if isinstance(mp, str) and mp.startswith(_ABSOLUTE_PREFIX):+ if isinstance(mp, str) and mp.startswith(+ _ABSOLUTE_PREFIX + "."+ ):engine_data[key] = mp[len(_ABSOLUTE_PREFIX) :]search_engines["auto"] = _get_setting(diff --git a/tests/security/test_module_whitelist.py b/tests/security/test_module_whitelist.pyindex 8a968c89c5..c01315254d 100644--- a/tests/security/test_module_whitelist.py+++ b/tests/security/test_module_whitelist.py@@ -307,14 +307,49 @@ class TestGetSafeModuleClass:package="local_deep_research.web_search_engines",)- def test_rejects_exact_prefix_normalizing_to_empty(self):- """Exact prefix without module suffix normalizes to empty string → rejected."""+ def test_rejects_exact_prefix_without_dot_suffix(self):+ """Exact prefix without '.' suffix is not normalized — rejected as non-relative."""with pytest.raises(SecurityError):get_safe_module_class("local_deep_research.web_search_engines","BaseSearchEngine",)+ def test_prefix_boundary_rejects_similar_prefix(self):+ """Prefix that extends the package name without a dot should NOT be normalized.++ 'local_deep_research.web_search_enginesXXX.evil' should not match+ the normalization prefix 'local_deep_research.web_search_engines.'.+ """+ with pytest.raises(SecurityError):+ get_safe_module_class(+ "local_deep_research.web_search_enginesXXX.evil",+ "BaseSearchEngine",+ )++ def test_bypass_path_absolute_module_normalized_by_chokepoint(self):+ """Absolute paths reaching get_safe_module_class() (e.g. from bypass paths+ like _get_search_config or _create_full_search_wrapper) are correctly+ normalized and validated by the security chokepoint."""+ with patch(+ "local_deep_research.security.module_whitelist.importlib.import_module"+ ) as mock_import:+ mock_module = MagicMock()+ mock_module.SearXNGSearchEngine = type(+ "SearXNGSearchEngine", (), {}+ )+ mock_import.return_value = mock_module++ cls = get_safe_module_class(+ "local_deep_research.web_search_engines.engines.search_engine_searxng",+ "SearXNGSearchEngine",+ )+ assert cls.__name__ == "SearXNGSearchEngine"+ mock_import.assert_called_once_with(+ ".engines.search_engine_searxng",+ package="local_deep_research.web_search_engines",+ )+class TestSecurityScenarios:"""Test specific security attack scenarios."""diff --git a/tests/web_search_engines/test_search_engines_config.py b/tests/web_search_engines/test_search_engines_config.pyindex 9f03bb3a51..f543ece47f 100644--- a/tests/web_search_engines/test_search_engines_config.py+++ b/tests/web_search_engines/test_search_engines_config.py@@ -490,6 +490,39 @@ class TestModulePathNormalization:== ".engines.search_engine_duckduckgo")+ @patch(+ "local_deep_research.web_search_engines.retriever_registry.retriever_registry"+ )+ @patch(+ "local_deep_research.web_search_engines.search_engines_config._get_setting"+ )+ def test_prefix_boundary_does_not_strip_similar_prefix(+ self, mock_get_setting, mock_registry+ ):+ """Prefix extending the package name (e.g. 'web_search_enginesXXX') must NOT be stripped."""+ mock_registry.list_registered.return_value = []++ def get_setting_side_effect(key, default, **kwargs):+ if key == "search.engine.web":+ return {+ "evil.module_path": "local_deep_research.web_search_enginesXXX.evil_module",+ "evil.class_name": "EvilEngine",+ }+ return default++ mock_get_setting.side_effect = get_setting_side_effect++ from local_deep_research.web_search_engines.search_engines_config import (+ search_config,+ )++ result = search_config()+ # The path should NOT have been normalized — it doesn't match the exact prefix + "."+ assert (+ result["evil"]["module_path"]+ == "local_deep_research.web_search_enginesXXX.evil_module"+ )+@patch("local_deep_research.web_search_engines.retriever_registry.retriever_registry")