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: Add path validation to LibraryService.open_file_location()

LearningCircuitedc8fd73b2c1
diff --git a/src/local_deep_research/research_library/services/library_service.py b/src/local_deep_research/research_library/services/library_service.py
index cf7660a93e..d0ec36d5b2 100644
--- a/src/local_deep_research/research_library/services/library_service.py
+++ b/src/local_deep_research/research_library/services/library_service.py
@@ -17,19 +17,20 @@ from sqlalchemy import and_, or_, func, Integer, case
from ...database.models.download_tracker import DownloadTracker
from ...database.models.library import (
+ Collection,
Document,
DocumentBlob,
- DocumentStatus,
- Collection,
DocumentCollection,
+ DocumentStatus,
)
-from ...database.models.research import ResearchHistory, ResearchResource
from ...database.models.metrics import ResearchRating
+from ...database.models.research import ResearchHistory, ResearchResource
from ...database.session_context import get_user_db_session
+from ...security import PathValidator
from ..utils import (
+ get_absolute_path_from_settings,
get_url_hash,
open_file_location,
- get_absolute_path_from_settings,
)
@@ -718,11 +719,17 @@ class LibraryService:
)
if tracker and tracker.file_path:
- absolute_path = get_absolute_path_from_settings(
- tracker.file_path
- )
- # Use centralized file location opener with absolute path
- return open_file_location(str(absolute_path))
+ # Validate path is within library root to prevent traversal attacks
+ library_root = get_absolute_path_from_settings("")
+ try:
+ validated_path = PathValidator.validate_safe_path(
+ tracker.file_path, library_root, allow_absolute=False
+ )
+ if validated_path and validated_path.exists():
+ return open_file_location(str(validated_path))
+ except ValueError as e:
+ logger.warning(f"Path validation failed: {e}")
+ return False
return False