~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: executor shutdown cancel_futures and SSRF hostname test updates (#3311)
LearningCircuit268475230236
diff --git a/src/local_deep_research/notifications/manager.py b/src/local_deep_research/notifications/manager.pyindex 75365b6006..458a74eaf8 100644--- a/src/local_deep_research/notifications/manager.py+++ b/src/local_deep_research/notifications/manager.py@@ -512,12 +512,13 @@ class RateLimiter:Args:user_id: User to reset, or None for all users"""- if user_id:- self._hourly_counts.pop(user_id, None)- self._daily_counts.pop(user_id, None)- else:- self._hourly_counts.clear()- self._daily_counts.clear()+ with self._lock:+ if user_id:+ self._hourly_counts.pop(user_id, None)+ self._daily_counts.pop(user_id, None)+ else:+ self._hourly_counts.clear()+ self._daily_counts.clear()def _cleanup_inactive_users_if_needed(self, now: datetime) -> None:"""diff --git a/src/local_deep_research/security/notification_validator.py b/src/local_deep_research/security/notification_validator.pyindex 1ff19c5146..d4ec3d8838 100644--- a/src/local_deep_research/security/notification_validator.py+++ b/src/local_deep_research/security/notification_validator.py@@ -6,6 +6,8 @@ to prevent Server-Side Request Forgery (SSRF) attacks and other security issues."""import ipaddress+import socket+from concurrent.futures import ThreadPoolExecutor, TimeoutErrorfrom typing import Optional, Tuplefrom urllib.parse import urlparsefrom loguru import logger@@ -86,9 +88,36 @@ class NotificationURLValidator:for network in NotificationURLValidator.PRIVATE_IP_RANGES)except ValueError:- # Not a valid IP address, might be a hostname- # For security, we don't resolve hostnames to avoid DNS rebinding attacks- # Apprise services should be configured with public endpoints+ # Hostname - resolve to IP and check+ # Use concurrent.futures for thread-safe timeout instead of+ # socket.setdefaulttimeout() which is process-global and not+ # thread-safe.+ try:+ executor = ThreadPoolExecutor(max_workers=1)+ try:+ future = executor.submit(+ socket.getaddrinfo,+ hostname,+ None,+ socket.AF_UNSPEC,+ socket.SOCK_STREAM,+ )+ resolved_ips = future.result(timeout=5)+ finally:+ executor.shutdown(wait=False, cancel_futures=True)+ for _family, _, _, _, sockaddr in resolved_ips:+ ip = ipaddress.ip_address(sockaddr[0])+ if any(+ ip in network+ for network in NotificationURLValidator.PRIVATE_IP_RANGES+ ):+ return True+ except (socket.gaierror, OSError, TimeoutError):+ logger.warning(+ "DNS resolution failed for hostname {} — "+ "allowing request (unable to determine if private)",+ hostname,+ )return False@staticmethoddiff --git a/tests/security/test_notification_validator.py b/tests/security/test_notification_validator.pyindex 9b91594a9f..42350ee916 100644--- a/tests/security/test_notification_validator.py+++ b/tests/security/test_notification_validator.py@@ -1,5 +1,8 @@"""Tests for notification_validator module - notification service URL validation."""+from unittest.mock import patch+import socket+import pytestfrom local_deep_research.security.notification_validator import (@@ -77,10 +80,37 @@ class TestIsPrivateIP:assert NotificationURLValidator._is_private_ip("1.1.1.1") is Falseassert NotificationURLValidator._is_private_ip("93.184.216.34") is False- def test_hostname_not_resolved(self):- """Should return False for hostnames (not resolved for security)."""- assert NotificationURLValidator._is_private_ip("example.com") is False- assert NotificationURLValidator._is_private_ip("internal.corp") is False+ def test_hostname_resolving_to_public_ip(self):+ """Should return False for hostnames that resolve to public IPs."""+ fake_result = [+ (socket.AF_INET, socket.SOCK_STREAM, 6, "", ("93.184.216.34", 0)),+ ]+ with patch("socket.getaddrinfo", return_value=fake_result):+ assert (+ NotificationURLValidator._is_private_ip("example.com") is False+ )++ def test_hostname_resolving_to_private_ip(self):+ """Should return True for hostnames that resolve to private IPs."""+ fake_result = [+ (socket.AF_INET, socket.SOCK_STREAM, 6, "", ("127.0.0.1", 0)),+ ]+ with patch("socket.getaddrinfo", return_value=fake_result):+ assert (+ NotificationURLValidator._is_private_ip("evil.example.com")+ is True+ )++ def test_hostname_dns_failure_returns_false(self):+ """Should return False when DNS resolution fails."""+ with patch(+ "socket.getaddrinfo",+ side_effect=socket.gaierror("Name not resolved"),+ ):+ assert (+ NotificationURLValidator._is_private_ip("nonexistent.invalid")+ is False+ )class TestValidateServiceUrl: