Skip to content

~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.

fix: remove local engine dead code and standardize null byte rejection (#2500)

LearningCircuit202dd2f6c6ce
diff --git a/src/local_deep_research/security/path_validator.py b/src/local_deep_research/security/path_validator.py
index 5e1a81a075..c5dadec435 100644
--- a/src/local_deep_research/security/path_validator.py
+++ b/src/local_deep_research/security/path_validator.py
@@ -50,6 +50,9 @@ class PathValidator:
if not user_input or not isinstance(user_input, str):
raise ValueError("Invalid path input")
+ if "\x00" in user_input:
+ raise ValueError("Null bytes are not allowed in path")
+
# Strip whitespace
user_input = user_input.strip()
@@ -323,12 +326,14 @@ class PathValidator:
Raises:
ValueError: If the path is invalid
"""
- # Sanitize input first - remove any null bytes and normalize
+ # Validate input: reject null bytes, then normalize whitespace
if not config_path or not isinstance(config_path, str):
raise ValueError("Invalid config path input")
- # Remove null bytes and normalize
- config_path = config_path.replace("\x00", "").strip()
+ if "\x00" in config_path:
+ raise ValueError("Null bytes are not allowed in config path")
+
+ config_path = config_path.strip()
# Check for path traversal attempts in the string itself
# Define restricted system directories that should never be accessed
diff --git a/src/local_deep_research/web_search_engines/engines/meta_search_engine.py b/src/local_deep_research/web_search_engines/engines/meta_search_engine.py
index 5f389f0a92..a03743695f 100644
--- a/src/local_deep_research/web_search_engines/engines/meta_search_engine.py
+++ b/src/local_deep_research/web_search_engines/engines/meta_search_engine.py
@@ -122,21 +122,7 @@ class MetaSearchEngine(BaseSearchEngine):
if name in ["meta", "auto"]:
continue
- # Determine if this is a local engine (starts with "local.")
- is_local_engine = name.startswith("local.")
-
- # Determine the appropriate setting path based on engine type
- if is_local_engine:
- # Format: search.engine.local.{engine_name}.use_in_auto_search
- local_name = name.replace("local.", "")
- auto_search_setting = (
- f"search.engine.local.{local_name}.use_in_auto_search"
- )
- else:
- # Format: search.engine.web.{engine_name}.use_in_auto_search
- auto_search_setting = (
- f"search.engine.web.{name}.use_in_auto_search"
- )
+ auto_search_setting = f"search.engine.web.{name}.use_in_auto_search"
# Get setting from database, default to False if not found
use_in_auto_search = get_setting_from_snapshot(
diff --git a/tests/search_engines/test_meta_search_logic.py b/tests/search_engines/test_meta_search_logic.py
index 1ca46906ad..164bd61a61 100644
--- a/tests/search_engines/test_meta_search_logic.py
+++ b/tests/search_engines/test_meta_search_logic.py
@@ -135,42 +135,7 @@ class TestAPIKeyValidation:
# ===========================================================================
-# 3. Local engine filtering
-# ===========================================================================
-
-
-class TestLocalEngineFiltering:
- """Verify local.* engine prefix handling in _get_available_engines."""
-
- def test_local_engine_uses_local_setting_path(self):
- """local.* engines look up use_in_auto_search under search.engine.local.* path."""
- # _get_search_config parser splits on dots, so "local.myindex" can't survive
- # as a single engine name from settings keys. We mock _get_search_config
- # to test the _get_available_engines logic for local engine names directly.
- snapshot = {
- "search.engine.local.myindex.use_in_auto_search": True,
- "search.engine.web.searxng.use_in_auto_search": True,
- }
-
- with patch(
- "local_deep_research.web_search_engines.engines.meta_search_engine.WikipediaSearchEngine"
- ):
- with patch.object(
- MetaSearchEngine,
- "_get_search_config",
- return_value={"local.myindex": {}, "searxng": {}},
- ):
- engine = MetaSearchEngine(
- llm=MagicMock(),
- max_results=5,
- settings_snapshot=snapshot,
- )
-
- assert "local.myindex" in engine.available_engines
-
-
-# ===========================================================================
-# 4. analyze_query — specialized domain detection
+# 3. analyze_query — specialized domain detection
# ===========================================================================
@@ -230,7 +195,7 @@ class TestAnalyzeQuery:
# ===========================================================================
-# 5. analyze_query — exception handling
+# 4. analyze_query — exception handling
# ===========================================================================
@@ -284,7 +249,7 @@ class TestAnalyzeQueryExceptions:
# ===========================================================================
-# 6. _get_full_content — failure scenarios
+# 5. _get_full_content — failure scenarios
# ===========================================================================
@@ -332,7 +297,7 @@ class TestGetFullContent:
# ===========================================================================
-# 7. _get_engine_instance — caching and failure
+# 6. _get_engine_instance — caching and failure
# ===========================================================================
@@ -391,7 +356,7 @@ class TestGetEngineInstance:
# ===========================================================================
-# 8. _get_previews — engine fallthrough
+# 7. _get_previews — engine fallthrough
# ===========================================================================
diff --git a/tests/security/test_path_validator.py b/tests/security/test_path_validator.py
index 65361f5bd7..5d4f9b6867 100644
--- a/tests/security/test_path_validator.py
+++ b/tests/security/test_path_validator.py
@@ -237,15 +237,13 @@ class TestValidateConfigPath:
)
assert "traversal" in str(exc_info.value).lower()
- def test_null_bytes_sanitized(self, temp_config_dir):
- """Sanitizes null bytes in config path."""
- # PathValidator removes null bytes instead of raising
- result = PathValidator.validate_config_path(
- "set\x00tings.json",
- config_root=str(temp_config_dir),
- )
- # Null byte is removed, so path is valid (settings.json exists)
- assert result.exists()
+ def test_null_bytes_rejected(self, temp_config_dir):
+ """Rejects null bytes in config path."""
+ with pytest.raises(ValueError, match="Null bytes"):
+ PathValidator.validate_config_path(
+ "set\x00tings.json",
+ config_root=str(temp_config_dir),
+ )
def test_etc_prefix_blocked(self, temp_config_dir):
"""Blocks paths starting with /etc/."""
diff --git a/tests/security/test_path_validator_edge_cases.py b/tests/security/test_path_validator_edge_cases.py
index 991c67d2e8..cc3044027c 100644
--- a/tests/security/test_path_validator_edge_cases.py
+++ b/tests/security/test_path_validator_edge_cases.py
@@ -27,23 +27,16 @@ class TestControlCharactersRejected:
PathValidator.validate_local_filesystem_path("/tmp/test\ndir")
-class TestMultipleNullBytesStripped:
- """Verify validate_config_path strips ALL null bytes, not just the first."""
+class TestNullBytesRejected:
+ """Verify validate_config_path rejects null bytes."""
- def test_multiple_null_bytes_all_stripped(self):
- """Multiple null bytes in config path should all be removed."""
- with tempfile.TemporaryDirectory() as tmpdir:
- # Create a settings.json file
- config_file = Path(tmpdir) / "settings.json"
- config_file.write_text('{"key": "value"}')
-
- # "s\x00e\x00ttings.json" → "settings.json" after null removal
- result = PathValidator.validate_config_path(
+ def test_multiple_null_bytes_rejected(self):
+ """Multiple null bytes in config path should raise ValueError."""
+ with pytest.raises(ValueError, match="Null bytes"):
+ PathValidator.validate_config_path(
"s\x00e\x00ttings.json",
- config_root=tmpdir,
+ config_root="/tmp",
)
- assert result.exists()
- assert result.name == "settings.json"
class TestEtcWithDifferentCasingBlocked:
diff --git a/tests/security/test_path_validator_security.py b/tests/security/test_path_validator_security.py
index 3b0112afc2..a1e95b7666 100644
--- a/tests/security/test_path_validator_security.py
+++ b/tests/security/test_path_validator_security.py
@@ -30,6 +30,11 @@ class TestValidateSafePath:
with pytest.raises(ValueError, match="Invalid path input"):
PathValidator.validate_safe_path("", "/tmp")
+ def test_null_bytes_rejected_in_safe_path(self, tmp_path):
+ """Null bytes in validate_safe_path raise ValueError."""
+ with pytest.raises(ValueError, match="Null bytes"):
+ PathValidator.validate_safe_path("file\x00.txt", str(tmp_path))
+
def test_traversal_blocked(self, tmp_path):
"""Path traversal attempt via .. is blocked."""
with pytest.raises(ValueError):
@@ -231,7 +236,7 @@ class TestValidateModelPath:
# ===========================================================================
-# 5. validate_config_path — restricted prefixes and null byte stripping
+# 5. validate_config_path — restricted prefixes and null byte rejection
# ===========================================================================
@@ -248,19 +253,13 @@ class TestValidateConfigPath:
with pytest.raises(ValueError, match="Invalid config path"):
PathValidator.validate_config_path("")
- def test_null_bytes_stripped(self, tmp_path):
- """Null bytes are stripped from config paths (not rejected)."""
- # Create a config file
- config_file = tmp_path / "config.json"
- config_file.write_text("{}")
-
- # validate_config_path strips null bytes rather than rejecting
- # This means "config\x00.json" becomes "config.json" after stripping
- result = PathValidator.validate_config_path(
- "config\x00.json",
- config_root=str(tmp_path),
- )
- assert result is not None
+ def test_null_bytes_rejected(self, tmp_path):
+ """Null bytes in config paths raise ValueError."""
+ with pytest.raises(ValueError, match="Null bytes"):
+ PathValidator.validate_config_path(
+ "config\x00.json",
+ config_root=str(tmp_path),
+ )
def test_traversal_rejected(self):
""".. in config path raises ValueError."""
diff --git a/tests/web_search_engines/engines/test_meta_search_engine_extended.py b/tests/web_search_engines/engines/test_meta_search_engine_extended.py
index 14c3f2e97e..c29ee8bc54 100644
--- a/tests/web_search_engines/engines/test_meta_search_engine_extended.py
+++ b/tests/web_search_engines/engines/test_meta_search_engine_extended.py
@@ -8,7 +8,7 @@ Covers:
- analyze_query() exception → fallback
- analyze_query() no engines_info → reliability sort
- _get_search_config() from settings_snapshot
-- _get_available_engines() API key filtering, local engine path
+- _get_available_engines() API key filtering
- _get_full_content() exception in selected engine
- _get_previews() engine init failure → skip
"""
@@ -227,11 +227,11 @@ class TestGetSearchConfigFromSnapshot:
assert config["brave"]["timeout"] == 30
-# ── _get_available_engines: API key and local engines ────────────
+# ── _get_available_engines: API key filtering ────────────────────
class TestGetAvailableEnginesFiltering:
- """Tests for _get_available_engines API key and local engine handling."""
+ """Tests for _get_available_engines API key filtering."""
def test_requires_api_key_but_missing_excluded(self):
"""Engine with requires_api_key=True but no key is excluded."""
@@ -325,50 +325,6 @@ class TestGetAvailableEnginesFiltering:
assert "brave" not in engine.available_engines
assert "wikipedia" in engine.available_engines
- def test_local_engine_setting_path(self):
- """Local engines use correct setting path format."""
- from local_deep_research.web_search_engines.engines.meta_search_engine import (
- MetaSearchEngine,
- )
-
- mock_llm = Mock()
- settings = {"search.max_results": {"value": 10}}
-
- setting_keys_checked = []
-
- def capture_setting(key, default, settings_snapshot=None):
- setting_keys_checked.append(key)
- return True # Enable all
-
- with patch(
- "local_deep_research.web_search_engines.engines.meta_search_engine.get_setting_from_snapshot",
- side_effect=capture_setting,
- ):
- with patch.object(
- MetaSearchEngine,
- "_get_search_config",
- return_value={
- "local.myfiles": {},
- "wikipedia": {},
- },
- ):
- MetaSearchEngine(
- llm=mock_llm,
- settings_snapshot=settings,
- programmatic_mode=True,
- )
-
- # local engine should check "search.engine.local.myfiles.use_in_auto_search"
- assert any(
- "search.engine.local.myfiles.use_in_auto_search" in k
- for k in setting_keys_checked
- )
- # web engine should check "search.engine.web.wikipedia.use_in_auto_search"
- assert any(
- "search.engine.web.wikipedia.use_in_auto_search" in k
- for k in setting_keys_checked
- )
-
# ── _get_full_content: exception in selected engine ──────────────