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: Address security vulnerabilities from CodeQL scan (PR #637)

LearningCircuit020f464b2377
diff --git a/src/local_deep_research/config/llm_config.py b/src/local_deep_research/config/llm_config.py
index ad832336a9..5c98c34c68 100644
--- a/src/local_deep_research/config/llm_config.py
+++ b/src/local_deep_research/config/llm_config.py
@@ -149,11 +149,48 @@ def is_llamacpp_available(settings_snapshot=None):
"""Check if LlamaCpp is available and configured"""
try:
from langchain_community.llms import LlamaCpp # noqa: F401
+ from .paths import get_data_directory
model_path = get_setting_from_snapshot(
"llm.llamacpp_model_path", settings_snapshot=settings_snapshot
)
- return bool(model_path) and os.path.exists(model_path)
+
+ if not model_path:
+ return False
+
+ # Sanitize and validate the path to prevent path traversal
+ try:
+ # Resolve to absolute path
+ model_path = os.path.abspath(os.path.expanduser(model_path))
+
+ # Get allowed base directories for models
+ data_dir = str(get_data_directory())
+ home_dir = os.path.expanduser("~")
+
+ # Check if the path is within allowed directories
+ # Models can be in data directory, home directory, or /usr/local
+ allowed_prefixes = [
+ os.path.abspath(data_dir),
+ os.path.abspath(home_dir),
+ "/usr/local",
+ "/opt",
+ ]
+
+ # Verify the path is within an allowed directory
+ is_allowed = any(
+ model_path.startswith(prefix) for prefix in allowed_prefixes
+ )
+
+ if not is_allowed:
+ logger.warning(
+ f"Model path '{model_path}' is outside allowed directories"
+ )
+ return False
+
+ return os.path.exists(model_path) and os.path.isfile(model_path)
+ except (OSError, ValueError) as e:
+ logger.debug(f"Invalid model path: {e}")
+ return False
except Exception:
return False
diff --git a/src/local_deep_research/web/routes/api_routes.py b/src/local_deep_research/web/routes/api_routes.py
index 7110fa84c4..3d1ee08720 100644
--- a/src/local_deep_research/web/routes/api_routes.py
+++ b/src/local_deep_research/web/routes/api_routes.py
@@ -556,21 +556,15 @@ def check_ollama_model():
logger.warning(
f"Model {model_name} not found among {len(models)} available models"
)
- message = (
- f"Model {model_name} is not available. Available models: "
- + ", ".join(model_names[:5])
- ) + (
- f" and {len(model_names) - 5} more"
- if len(model_names) > 5
- else ""
- )
+ # Don't expose available models for security reasons
+ message = f"Model {model_name} is not available"
return jsonify(
{
"available": False,
"model": model_name,
"message": message,
- "all_models": model_names,
+ # Remove all_models to prevent information disclosure
}
)
except ValueError as json_err:
diff --git a/src/local_deep_research/web/static/js/pages/news.js b/src/local_deep_research/web/static/js/pages/news.js
index 43539cbeea..dfb1083615 100644
--- a/src/local_deep_research/web/static/js/pages/news.js
+++ b/src/local_deep_research/web/static/js/pages/news.js
@@ -917,7 +917,7 @@ function renderNewsItems(searchQuery = null) {
<button class="btn btn-secondary btn-sm save-btn" onclick="toggleSaveItem('${escapeAttr(item.id)}')" title="${savedNewsIds.has(item.id) ? 'Remove from saved' : 'Save for later'}">
<i class="${savedNewsIds.has(item.id) ? 'bi bi-bookmark-fill' : 'bi bi-bookmark'}"></i>
</button>
- ${item.query ? `<button class="btn btn-outline-primary btn-sm" onclick="createSubscriptionFromItem('${item.id}')" title="Create subscription from this search">
+ ${item.query ? `<button class="btn btn-outline-primary btn-sm" onclick="createSubscriptionFromItem('${escapeAttr(item.id)}')" title="Create subscription from this search">
<i class="bi bi-bell-plus"></i> Subscribe
</button>` : ''}
</div>