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.

security: fix path traversal in FileReportStorage, LDR_DATA_DIR, and symlink checks (#3090)

LearningCircuitaa7fa50845ae
diff --git a/src/local_deep_research/config/paths.py b/src/local_deep_research/config/paths.py
index 627d2c006d..c48a6c7555 100644
--- a/src/local_deep_research/config/paths.py
+++ b/src/local_deep_research/config/paths.py
@@ -27,7 +27,15 @@ def get_data_directory() -> Path:
# Check for explicit override via environment variable
custom_path = os.getenv("LDR_DATA_DIR")
if custom_path:
- data_dir = Path(custom_path)
+ if not Path(custom_path).is_absolute():
+ raise ValueError("LDR_DATA_DIR must be an absolute path")
+ data_dir = Path(custom_path).resolve()
+ # Block SQL-unsafe characters that could be exploited in ATTACH DATABASE statements
+ path_str = str(data_dir)
+ if any(c in path_str for c in ("'", '"', "\0", "\n", "\r")):
+ raise ValueError(
+ f"LDR_DATA_DIR contains unsafe characters: {path_str!r}"
+ )
logger.debug(
f"Using custom data directory from LDR_DATA_DIR: {data_dir}"
)
diff --git a/src/local_deep_research/security/path_validator.py b/src/local_deep_research/security/path_validator.py
index 11dcdf299c..3aed6ba744 100644
--- a/src/local_deep_research/security/path_validator.py
+++ b/src/local_deep_research/security/path_validator.py
@@ -225,6 +225,12 @@ class PathValidator:
if ".." in user_path:
raise ValueError("Path traversal patterns not allowed")
+ # Check for symlinks BEFORE resolve(), since resolve() follows symlinks
+ # making a post-resolve is_symlink() check ineffective (always False)
+ raw_path = Path(user_path)
+ if raw_path.is_symlink():
+ raise ValueError("Symlinks are not permitted for security reasons")
+
# Use safe_join to sanitize the path - this is recognized by static analyzers
# For absolute paths, we validate against the root directory
if user_path.startswith("/"):
diff --git a/src/local_deep_research/storage/file.py b/src/local_deep_research/storage/file.py
index d00bac7411..37950358e4 100644
--- a/src/local_deep_research/storage/file.py
+++ b/src/local_deep_research/storage/file.py
@@ -23,11 +23,21 @@ class FileReportStorage(ReportStorage):
def _get_report_path(self, research_id: str) -> Path:
"""Get the file path for a report."""
- return self.base_dir / f"{research_id}.md"
+ candidate = (self.base_dir / f"{research_id}.md").resolve()
+ if not candidate.is_relative_to(self.base_dir.resolve()):
+ raise ValueError(
+ f"Path traversal attempt with research_id: {research_id!r}"
+ )
+ return candidate
def _get_metadata_path(self, research_id: str) -> Path:
"""Get the file path for report metadata."""
- return self.base_dir / f"{research_id}_metadata.json"
+ candidate = (self.base_dir / f"{research_id}_metadata.json").resolve()
+ if not candidate.is_relative_to(self.base_dir.resolve()):
+ raise ValueError(
+ f"Path traversal attempt with research_id: {research_id!r}"
+ )
+ return candidate
def save_report(
self,