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 additional security vulnerabilities from CodeQL scan

LearningCircuit99ba03d717a5
diff --git a/src/local_deep_research/memory_cache/config.py b/src/local_deep_research/memory_cache/config.py
index 0782f09167..803c3717bf 100644
--- a/src/local_deep_research/memory_cache/config.py
+++ b/src/local_deep_research/memory_cache/config.py
@@ -45,7 +45,9 @@ if not CACHE_KEY_SECRET:
try:
os.makedirs(os.path.dirname(cache_secret_file), exist_ok=True)
with open(cache_secret_file, "w") as f:
- f.write(CACHE_KEY_SECRET)
+ # CodeQL: This is intentional - cache key needs to persist across restarts
+ # File is protected with 0o600 permissions (owner read/write only)
+ f.write(CACHE_KEY_SECRET) # nosec B108
os.chmod(cache_secret_file, 0o600) # Secure file permissions
logger.info("Generated new CACHE_KEY_SECRET for this installation")
except Exception:
diff --git a/src/local_deep_research/web/auth/routes.py b/src/local_deep_research/web/auth/routes.py
index 77b0b730a8..fcd56e282d 100644
--- a/src/local_deep_research/web/auth/routes.py
+++ b/src/local_deep_research/web/auth/routes.py
@@ -3,6 +3,7 @@ Authentication routes for login, register, and logout.
Uses SQLCipher encrypted databases with browser password manager support.
"""
+import os
from datetime import datetime
from flask import (
@@ -140,13 +141,28 @@ def login():
# Also allow any path generated by url_for (they start with /)
safe_redirect = url_for("index") # Default safe URL
- # Validate the URL: must be relative (no netloc) and either in whitelist or start with /
+ # Validate the URL: must be relative (no netloc) and safe
if next_page and not parsed_url.netloc and not parsed_url.scheme:
- # Check if it's in the whitelist or is a relative path starting with /
- if parsed_url.path in allowed_paths or (
- parsed_url.path and parsed_url.path.startswith("/")
- ):
+ # Normalize the path to prevent tricks like //example.com
+ normalized_path = (
+ os.path.normpath(parsed_url.path) if parsed_url.path else ""
+ )
+
+ # Check if it's in the whitelist or is a safe relative path
+ if parsed_url.path in allowed_paths:
safe_redirect = next_page
+ elif (
+ parsed_url.path
+ and parsed_url.path.startswith("/")
+ and not parsed_url.path.startswith("//")
+ ):
+ # Additional checks for safety
+ if ".." not in parsed_url.path and normalized_path.startswith("/"):
+ safe_redirect = next_page
+ else:
+ logger.warning(
+ f"Blocked potentially unsafe redirect with path traversal: {next_page}"
+ )
else:
logger.warning(
f"Blocked potentially unsafe redirect to: {next_page}"
diff --git a/src/local_deep_research/web/routes/api_routes.py b/src/local_deep_research/web/routes/api_routes.py
index 32a6d752d1..9a9d089342 100644
--- a/src/local_deep_research/web/routes/api_routes.py
+++ b/src/local_deep_research/web/routes/api_routes.py
@@ -310,7 +310,12 @@ def api_delete_resource(research_id, resource_id):
), 404
except Exception as e:
logger.exception(f"Error deleting resource: {e!s}")
- return jsonify({"status": "error", "message": str(e)}), 500
+ return jsonify(
+ {
+ "status": "error",
+ "message": "An internal error occurred while deleting the resource.",
+ }
+ ), 500
@api_bp.route("/check/ollama_status", methods=["GET"])
@@ -426,7 +431,7 @@ def check_ollama_status():
return jsonify(
{
"running": False,
- "message": f"Error checking Ollama: {e!s}",
+ "message": "An internal error occurred while checking Ollama status.",
"error_type": "exception",
"error_details": "An internal error occurred.",
}
diff --git a/src/local_deep_research/web/routes/history_routes.py b/src/local_deep_research/web/routes/history_routes.py
index 0a40a95188..0609d9b898 100644
--- a/src/local_deep_research/web/routes/history_routes.py
+++ b/src/local_deep_research/web/routes/history_routes.py
@@ -232,7 +232,10 @@ def get_research_details(research_id):
logger.error(traceback.format_exc())
return jsonify(
- {"status": "error", "message": f"Database error: {str(e)}"}
+ {
+ "status": "error",
+ "message": "An internal database error occurred.",
+ }
), 500
if not research:
diff --git a/src/local_deep_research/web/static/js/components/settings.js b/src/local_deep_research/web/static/js/components/settings.js
index 2e93b6522a..ba15a4106a 100644
--- a/src/local_deep_research/web/static/js/components/settings.js
+++ b/src/local_deep_research/web/static/js/components/settings.js
@@ -1499,12 +1499,21 @@
})
.catch(error => {
console.error('Error fetching data location:', error);
- contentElement.innerHTML = `
- <div class="alert alert-danger">
- <i class="fas fa-exclamation-circle"></i>
- Failed to load data location information: ${error.message}
- </div>
- `;
+ // Clear content safely
+ contentElement.innerHTML = '';
+
+ // Create error alert
+ const alertDiv = document.createElement('div');
+ alertDiv.className = 'alert alert-danger';
+
+ const icon = document.createElement('i');
+ icon.className = 'fas fa-exclamation-circle';
+ alertDiv.appendChild(icon);
+
+ const errorText = document.createTextNode(' Failed to load data location information: ' + (error.message || 'Unknown error'));
+ alertDiv.appendChild(errorText);
+
+ contentElement.appendChild(alertDiv);
});
}
@@ -3653,7 +3662,15 @@
// Create alert element
const alert = document.createElement('div');
alert.className = `alert alert-${type}`;
- alert.innerHTML = `<i class="fas ${type === 'success' ? 'fa-check-circle' : 'fa-exclamation-circle'}"></i> ${message}`;
+
+ // Create icon element
+ const icon = document.createElement('i');
+ icon.className = `fas ${type === 'success' ? 'fa-check-circle' : 'fa-exclamation-circle'}`;
+ alert.appendChild(icon);
+
+ // Create text node for message (safe from XSS)
+ const messageText = document.createTextNode(' ' + message);
+ alert.appendChild(messageText);
// Add a close button
const closeBtn = document.createElement('span');