~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: allow localhost for local search engines like searxng
LearningCircuit30a265c0b598
diff --git a/src/local_deep_research/security/safe_requests.py b/src/local_deep_research/security/safe_requests.pyindex c51edd6c75..8b2d0136c4 100644--- a/src/local_deep_research/security/safe_requests.py+++ b/src/local_deep_research/security/safe_requests.py@@ -22,6 +22,7 @@ def safe_get(url: str,params: Optional[dict] = None,timeout: int = DEFAULT_TIMEOUT,+ allow_localhost: bool = False,**kwargs,) -> requests.Response:"""@@ -31,6 +32,9 @@ def safe_get(url: URL to requestparams: URL parameterstimeout: Request timeout in seconds+ allow_localhost: Whether to allow localhost/loopback addresses.+ Set to True for trusted internal services like self-hosted+ search engines (e.g., searxng). Default False.**kwargs: Additional arguments to pass to requests.get()Returns:@@ -41,7 +45,7 @@ def safe_get(requests.RequestException: If request fails"""# Validate URL to prevent SSRF- if not validate_url(url):+ if not validate_url(url, allow_localhost=allow_localhost):raise ValueError(f"URL failed security validation (possible SSRF): {url}")@@ -87,6 +91,7 @@ def safe_post(data: Optional[Any] = None,json: Optional[dict] = None,timeout: int = DEFAULT_TIMEOUT,+ allow_localhost: bool = False,**kwargs,) -> requests.Response:"""@@ -97,6 +102,9 @@ def safe_post(data: Data to send in request bodyjson: JSON data to send in request bodytimeout: Request timeout in seconds+ allow_localhost: Whether to allow localhost/loopback addresses.+ Set to True for trusted internal services like self-hosted+ search engines (e.g., searxng). Default False.**kwargs: Additional arguments to pass to requests.post()Returns:@@ -107,7 +115,7 @@ def safe_post(requests.RequestException: If request fails"""# Validate URL to prevent SSRF- if not validate_url(url):+ if not validate_url(url, allow_localhost=allow_localhost):raise ValueError(f"URL failed security validation (possible SSRF): {url}")@@ -156,12 +164,26 @@ class SafeSession(requests.Session):Usage:with SafeSession() as session:response = session.get(url)++ # For trusted internal services (e.g., searxng):+ with SafeSession(allow_localhost=True) as session:+ response = session.get(url)"""+ def __init__(self, allow_localhost: bool = False):+ """+ Initialize SafeSession.++ Args:+ allow_localhost: Whether to allow localhost/loopback addresses.+ """+ super().__init__()+ self.allow_localhost = allow_localhost+def request(self, method: str, url: str, **kwargs) -> requests.Response:"""Override request method to add SSRF validation."""# Validate URL- if not validate_url(url):+ if not validate_url(url, allow_localhost=self.allow_localhost):raise ValueError(f"URL failed security validation (possible SSRF): {url}")diff --git a/src/local_deep_research/security/ssrf_validator.py b/src/local_deep_research/security/ssrf_validator.pyindex 568474a0b5..83c53ec4e1 100644--- a/src/local_deep_research/security/ssrf_validator.py+++ b/src/local_deep_research/security/ssrf_validator.py@@ -39,22 +39,34 @@ AWS_METADATA_IP = "169.254.169.254"ALLOWED_SCHEMES = {"http", "https"}-def is_ip_blocked(ip_str: str) -> bool:+def is_ip_blocked(ip_str: str, allow_localhost: bool = False) -> bool:"""Check if an IP address is in a blocked range.Args:ip_str: IP address as string+ allow_localhost: Whether to allow localhost/loopback addressesReturns:True if IP is blocked, False otherwise"""+ # Loopback ranges that can be allowed for trusted internal services+ LOOPBACK_RANGES = [+ ipaddress.ip_network("127.0.0.0/8"), # IPv4 loopback+ ipaddress.ip_network("::1/128"), # IPv6 loopback+ ]+try:ip = ipaddress.ip_address(ip_str)# Check if IP is in any blocked rangefor blocked_range in BLOCKED_IP_RANGES:if ip in blocked_range:+ # If allow_localhost is True, skip blocking for loopback addresses+ if allow_localhost:+ is_loopback = any(ip in lr for lr in LOOPBACK_RANGES)+ if is_loopback:+ continuereturn True# Specifically block AWS metadata endpoint@@ -68,7 +80,9 @@ def is_ip_blocked(ip_str: str) -> bool:return False-def validate_url(url: str, allow_redirects: bool = True) -> bool:+def validate_url(+ url: str, allow_redirects: bool = True, allow_localhost: bool = False+) -> bool:"""Validate URL to prevent SSRF attacks.@@ -80,6 +94,9 @@ def validate_url(url: str, allow_redirects: bool = True) -> bool:Args:url: URL to validateallow_redirects: Whether to allow redirects (future use)+ allow_localhost: Whether to allow localhost/loopback addresses.+ Set to True for trusted internal services like self-hosted+ search engines (e.g., searxng). Default False.Returns:True if URL is safe, False otherwise@@ -116,7 +133,7 @@ def validate_url(url: str, allow_redirects: bool = True) -> bool:# Check if hostname is an IP addresstry:ip = ipaddress.ip_address(hostname)- if is_ip_blocked(str(ip)):+ if is_ip_blocked(str(ip), allow_localhost=allow_localhost):logger.warning(f"Blocked URL with internal/private IP: {hostname} - {url}")@@ -136,7 +153,7 @@ def validate_url(url: str, allow_redirects: bool = True) -> bool:for info in addr_info:ip_str = info[4][0] # Extract IP address from addr_info tuple- if is_ip_blocked(ip_str):+ if is_ip_blocked(ip_str, allow_localhost=allow_localhost):logger.warning(f"Blocked URL - hostname {hostname} resolves to "f"internal/private IP: {ip_str} - {url}"diff --git a/src/local_deep_research/web/queue/processor_v2.py b/src/local_deep_research/web/queue/processor_v2.pyindex a71e15b577..4b032460a7 100644--- a/src/local_deep_research/web/queue/processor_v2.py+++ b/src/local_deep_research/web/queue/processor_v2.py@@ -825,7 +825,9 @@ class QueueProcessorV2:try:db_session.rollback()except Exception:- pass # Ignore rollback errors+ logger.warning(+ f"Failed to rollback after error in operation {op_id}"+ )return processed_countdiff --git a/src/local_deep_research/web_search_engines/engines/search_engine_searxng.py b/src/local_deep_research/web_search_engines/engines/search_engine_searxng.pyindex bd84f22761..a1804d6e52 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_searxng.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_searxng.py@@ -82,7 +82,10 @@ class SearXNGSearchEngine(BaseSearchEngine):)try:# Make sure it's accessible.- response = safe_get(self.instance_url, timeout=5)+ # allow_localhost=True since searxng is typically self-hosted locally+ response = safe_get(+ self.instance_url, timeout=5, allow_localhost=True+ )if response.status_code == 200:logger.info("SearXNG instance is accessible.")self.is_available = True@@ -189,7 +192,10 @@ class SearXNGSearchEngine(BaseSearchEngine):try:initial_response = safe_get(- self.instance_url, headers=initial_headers, timeout=10+ self.instance_url,+ headers=initial_headers,+ timeout=10,+ allow_localhost=True,)cookies = initial_response.cookiesexcept Exception:@@ -231,6 +237,7 @@ class SearXNGSearchEngine(BaseSearchEngine):headers=headers,cookies=cookies,timeout=15,+ allow_localhost=True,)if response.status_code == 200: