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(security): bound the file-location finder subprocess (#6543)

LearningCircuit4ed7740242bb
diff --git a/src/local_deep_research/research_library/utils/__init__.py b/src/local_deep_research/research_library/utils/__init__.py
index dad599245b..db9da835cd 100644
--- a/src/local_deep_research/research_library/utils/__init__.py
+++ b/src/local_deep_research/research_library/utils/__init__.py
@@ -466,7 +466,11 @@ def open_file_location(file_path: str) -> bool:
os.startfile(folder)
elif sys.platform == "darwin": # macOS
result = subprocess.run(
- ["open", folder], capture_output=True, text=True, shell=False
+ ["open", folder],
+ capture_output=True,
+ text=True,
+ shell=False,
+ timeout=10,
)
if result.returncode != 0:
logger.error(f"Failed to open folder on macOS: {result.stderr}")
@@ -477,6 +481,7 @@ def open_file_location(file_path: str) -> bool:
capture_output=True,
text=True,
shell=False,
+ timeout=10,
)
if result.returncode != 0:
logger.error(f"Failed to open folder on Linux: {result.stderr}")
diff --git a/tests/research_library/utils/test_finder_subprocess_timeout.py b/tests/research_library/utils/test_finder_subprocess_timeout.py
new file mode 100644
index 0000000000..807be9c301
--- /dev/null
+++ b/tests/research_library/utils/test_finder_subprocess_timeout.py
@@ -0,0 +1,87 @@
+"""Timeout contracts for the file-location finder subprocess.
+
+``open_file_location`` launches the platform file manager
+(``xdg-open`` / macOS ``open``) with ``subprocess.run(..., shell=False)``
+and a ``PathValidator``-checked directory. The argv shape and the path
+validation are already pinned by ``test_bearer_security_fixes`` and
+``test_utils``; what nothing pins is that the subprocess is **bounded**
+— a desktop-environment hang (xdg-open waiting on a dead dbus session,
+a mounted-but-unresponsive remote folder) pins the calling worker
+indefinitely.
+"""
+
+from __future__ import annotations
+
+import subprocess
+from unittest.mock import patch
+
+from local_deep_research.research_library import utils as rl_utils
+
+
+def _recording_run(into):
+ """Patch subprocess.run for the *platform* branch and record kwargs."""
+
+ def fake_run(cmd, **kwargs):
+ into.update(kwargs)
+ into["cmd"] = cmd
+ return subprocess.CompletedProcess(cmd, 0)
+
+ return fake_run
+
+
+class TestFinderSubprocessTimeout:
+ def test_xdg_open_receives_a_timeout(self, monkeypatch, tmp_path):
+ recorded: dict = {}
+ monkeypatch.setattr(rl_utils.sys, "platform", "linux")
+ monkeypatch.setattr(
+ rl_utils.PathValidator,
+ "validate_local_filesystem_path",
+ classmethod(lambda cls, p: tmp_path),
+ )
+ with patch.object(
+ rl_utils.subprocess,
+ "run",
+ side_effect=_recording_run(recorded),
+ ):
+ assert rl_utils.open_file_location(str(tmp_path)) is True
+
+ assert recorded.get("timeout") is not None and (
+ recorded["timeout"] >= 5
+ ), f"xdg-open runs without a timeout: {recorded}"
+
+ def test_open_darwin_receives_a_timeout(self, monkeypatch, tmp_path):
+ recorded: dict = {}
+ monkeypatch.setattr(rl_utils.sys, "platform", "darwin")
+ monkeypatch.setattr(
+ rl_utils.PathValidator,
+ "validate_local_filesystem_path",
+ classmethod(lambda cls, p: tmp_path),
+ )
+ with patch.object(
+ rl_utils.subprocess,
+ "run",
+ side_effect=_recording_run(recorded),
+ ):
+ assert rl_utils.open_file_location(str(tmp_path)) is True
+
+ assert recorded.get("timeout") is not None and (
+ recorded["timeout"] >= 5
+ ), f"open(1) runs without a timeout: {recorded}"
+
+ def test_hang_degrades_to_false_not_an_exception(
+ self, monkeypatch, tmp_path
+ ):
+ monkeypatch.setattr(rl_utils.sys, "platform", "linux")
+ monkeypatch.setattr(
+ rl_utils.PathValidator,
+ "validate_local_filesystem_path",
+ classmethod(lambda cls, p: tmp_path),
+ )
+
+ def hanging_run(cmd, **kwargs):
+ raise subprocess.TimeoutExpired(cmd, kwargs.get("timeout", 0))
+
+ with patch.object(rl_utils.subprocess, "run", side_effect=hanging_run):
+ # Graceful False along the function's bool contract — not a
+ # TimeoutExpired escaping to the caller.
+ assert rl_utils.open_file_location(str(tmp_path)) is False
diff --git a/tests/research_library/utils/test_utils.py b/tests/research_library/utils/test_utils.py
index e6e632a36c..8952597bc9 100644
--- a/tests/research_library/utils/test_utils.py
+++ b/tests/research_library/utils/test_utils.py
@@ -146,6 +146,7 @@ class TestOpenFileLocation:
capture_output=True,
text=True,
shell=False,
+ timeout=10,
)
@patch("local_deep_research.research_library.utils.PathValidator")
@@ -184,6 +185,7 @@ class TestOpenFileLocation:
capture_output=True,
text=True,
shell=False,
+ timeout=10,
)
@patch("local_deep_research.research_library.utils.PathValidator")