~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix: Address critical security vulnerabilities identified by CodeQL
LearningCircuit7e4fe9380cb8
diff --git a/scripts/debug_db_open.py b/scripts/debug_db_open.pyindex 94745c1075..01de764376 100644--- a/scripts/debug_db_open.py+++ b/scripts/debug_db_open.py@@ -22,7 +22,7 @@ def get_user_hash(username: str) -> str:def test_open_database(username: str, password: str):"""Test opening a database with different methods."""print(f"\n🔍 Testing database access for: {username}")- print(f" Password: {password}")+ print(" Password: [REDACTED]")# Find the database fileuser_hash = get_user_hash(username)diff --git a/src/local_deep_research/web/auth/routes.py b/src/local_deep_research/web/auth/routes.pyindex 5c8fd6c6c5..77b0b730a8 100644--- a/src/local_deep_research/web/auth/routes.py+++ b/src/local_deep_research/web/auth/routes.py@@ -118,19 +118,43 @@ def login():# Redirect to original requested page or dashboard# Validate redirect URL to prevent open redirect vulnerability- next_page = request.args.get("next", url_for("index"))+ from urllib.parse import urlparse- # Only allow relative URLs that start with / or are generated by url_for- if next_page and not next_page.startswith("/"):- logger.warning(f"Blocked potentially unsafe redirect to: {next_page}")- next_page = url_for("index")+ next_page = request.args.get("next", url_for("index"))- # Additional validation: ensure the URL doesn't contain protocol or domain- if next_page and ("://" in next_page or "//" in next_page):+ # Parse the URL and validate its structure+ parsed_url = urlparse(next_page)++ # Whitelist of allowed paths - add more as needed+ allowed_paths = {+ "/",+ "/dashboard",+ "/profile",+ "/settings",+ "/research",+ "/history",+ "/metrics",+ "/benchmark",+ }++ # 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 /+ 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("/")+ ):+ safe_redirect = next_page+ else:+ logger.warning(+ f"Blocked potentially unsafe redirect to: {next_page}"+ )+ elif next_page:logger.warning(f"Blocked redirect with protocol/domain: {next_page}")- next_page = url_for("index")- return redirect(next_page)+ return redirect(safe_redirect)@auth_bp.route("/register", methods=["GET", "POST"])diff --git a/src/local_deep_research/web/routes/api_routes.py b/src/local_deep_research/web/routes/api_routes.pyindex 16458e8459..32a6d752d1 100644--- a/src/local_deep_research/web/routes/api_routes.py+++ b/src/local_deep_research/web/routes/api_routes.py@@ -385,7 +385,7 @@ def check_ollama_status():{"running": True,"message": "Ollama service is running but returned invalid data format",- "error_details": str(json_err),+ "error_details": "Invalid response format from the service.",})else:@@ -407,7 +407,7 @@ def check_ollama_status():"running": False,"message": "Ollama service is not running or not accessible","error_type": "connection_error",- "error_details": str(conn_err),+ "error_details": "Unable to connect to the service. Please check if the service is running.",})except requests.exceptions.Timeout as timeout_err:@@ -417,7 +417,7 @@ def check_ollama_status():"running": False,"message": "Ollama service request timed out after 5 seconds","error_type": "timeout",- "error_details": str(timeout_err),+ "error_details": "Request timed out. The service may be overloaded.",})@@ -428,7 +428,7 @@ def check_ollama_status():"running": False,"message": f"Error checking Ollama: {e!s}","error_type": "exception",- "error_details": str(e),+ "error_details": "An internal error occurred.",})@@ -590,7 +590,7 @@ def check_ollama_model():"model": model_name,"message": "Could not connect to Ollama service","error_type": "connection_error",- "error_details": str(conn_err),+ "error_details": "Unable to connect to the service. Please check if the service is running.",})except requests.exceptions.Timeout:@@ -617,9 +617,9 @@ def check_ollama_model():if "model_name" in locals()else llm_config.get("model", "gemma3:12b")),- "message": f"Error checking model: {e!s}",+ "message": "An internal error occurred while checking the model.","error_type": "exception",- "error_details": str(e),+ "error_details": "An internal error occurred.",})diff --git a/src/local_deep_research/web/routes/research_routes.py b/src/local_deep_research/web/routes/research_routes.pyindex 426f45ebf7..43078df5a1 100644--- a/src/local_deep_research/web/routes/research_routes.py+++ b/src/local_deep_research/web/routes/research_routes.py@@ -823,9 +823,30 @@ def open_file_location():if not file_path:return jsonify({"status": "error", "message": "Path is required"}), 400- # Convert to absolute path if needed- if not os.path.isabs(file_path):- file_path = os.path.abspath(file_path)+ # Get the user's data directory as the safe root+ from ...config.paths import get_data_directory++ safe_root = os.path.abspath(get_data_directory())++ # Normalize the path and ensure it's within the safe root directory+ try:+ # Convert to absolute path and normalize+ file_path = os.path.abspath(os.path.normpath(file_path))++ # Check if the path is within the safe data directory+ if not file_path.startswith(safe_root):+ logger.warning(+ f"Blocked access to path outside data directory: {file_path}"+ )+ return jsonify(+ {+ "status": "error",+ "message": "Access denied: Path is outside the allowed directory",+ }+ ), 403+ except Exception as e:+ logger.error(f"Path validation error: {e}")+ return jsonify({"status": "error", "message": "Invalid path"}), 400# Check if path existsif not os.path.exists(file_path):diff --git a/src/local_deep_research/web/routes/research_routes_orm.py b/src/local_deep_research/web/routes/research_routes_orm.pyindex 8f89e4cc1d..240f844b83 100644--- a/src/local_deep_research/web/routes/research_routes_orm.py+++ b/src/local_deep_research/web/routes/research_routes_orm.py@@ -288,7 +288,12 @@ def delete_research(research_id):except Exception as e:db_session.rollback()logger.error(f"Error deleting research {research_id}: {e}")- return jsonify({"status": "error", "message": str(e)}), 500+ return jsonify(+ {+ "status": "error",+ "message": "An internal error occurred while deleting the research.",+ }+ ), 500finally:db_session.close()@@ -333,7 +338,12 @@ def clear_history():except Exception as e:db_session.rollback()logger.error(f"Error clearing history: {e}")- return jsonify({"status": "error", "message": str(e)}), 500+ return jsonify(+ {+ "status": "error",+ "message": "An internal error occurred while clearing the history.",+ }+ ), 500finally:db_session.close()@@ -398,7 +408,12 @@ def api_get_history():except Exception as e:logger.error(f"Error fetching history: {e}")- return jsonify({"status": "error", "message": str(e)}), 500+ return jsonify(+ {+ "status": "error",+ "message": "An internal error occurred while fetching the history.",+ }+ ), 500finally:db_session.close()@@ -443,7 +458,12 @@ def api_get_research(research_id):except Exception as e:logger.error(f"Error fetching research {research_id}: {e}")- return jsonify({"status": "error", "message": str(e)}), 500+ return jsonify(+ {+ "status": "error",+ "message": "An internal error occurred while fetching the research.",+ }+ ), 500finally:db_session.close()diff --git a/src/local_deep_research/web/routes/settings_routes.py b/src/local_deep_research/web/routes/settings_routes.pyindex afee795bb4..3f86d32edd 100644--- a/src/local_deep_research/web/routes/settings_routes.py+++ b/src/local_deep_research/web/routes/settings_routes.py@@ -1882,14 +1882,14 @@ def fix_corrupted_settings():})- except Exception as e:+ except Exception:logger.exception("Error fixing corrupted settings")db_session.rollback()return (jsonify({"status": "error",- "message": f"Error fixing corrupted settings: {e!s}",+ "message": "An internal error occurred while fixing corrupted settings. Please try again later.",}),500,diff --git a/tests/ui_tests/auth_helper.js b/tests/ui_tests/auth_helper.jsindex 8049545d27..fefee84c1d 100644--- a/tests/ui_tests/auth_helper.js+++ b/tests/ui_tests/auth_helper.js@@ -13,7 +13,16 @@ const crypto = require('crypto');// Generate random username for each test to avoid conflictsfunction generateRandomUsername() {const timestamp = Date.now();- const random = crypto.randomBytes(4).readUInt32BE(0) % 1000;+ let random;+ // Use rejection sampling to avoid bias+ const maxValue = 4294967295; // Max value for 32-bit unsigned int+ const limit = maxValue - (maxValue % 1000); // Largest multiple of 1000 that fits++ do {+ random = crypto.randomBytes(4).readUInt32BE(0);+ } while (random >= limit); // Reject values that would cause bias++ random = random % 1000;return `testuser_${timestamp}_${random}`;}