~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 CGNAT and container networking IPs with allow_private_ips
LearningCircuit0307b8382787
diff --git a/src/local_deep_research/security/notification_validator.py b/src/local_deep_research/security/notification_validator.pyindex ffc83c11fc..4970a8aa30 100644--- a/src/local_deep_research/security/notification_validator.py+++ b/src/local_deep_research/security/notification_validator.py@@ -52,12 +52,15 @@ class NotificationURLValidator:"form", # Form-encoded webhooks)- # Private IP ranges (RFC 1918 + loopback + link-local)+ # Private IP ranges (RFC 1918 + loopback + link-local + CGNAT)PRIVATE_IP_RANGES = [ipaddress.ip_network("127.0.0.0/8"), # Loopbackipaddress.ip_network("10.0.0.0/8"), # Privateipaddress.ip_network("172.16.0.0/12"), # Privateipaddress.ip_network("192.168.0.0/16"), # Private+ ipaddress.ip_network(+ "100.64.0.0/10"+ ), # CGNAT - used by Podman/rootless containersipaddress.ip_network("169.254.0.0/16"), # Link-localipaddress.ip_network("::1/128"), # IPv6 loopbackipaddress.ip_network("fc00::/7"), # IPv6 unique localdiff --git a/src/local_deep_research/security/safe_requests.py b/src/local_deep_research/security/safe_requests.pyindex 059a5895c3..2e2d7db98c 100644--- a/src/local_deep_research/security/safe_requests.py+++ b/src/local_deep_research/security/safe_requests.py@@ -36,9 +36,11 @@ def safe_get(allow_localhost: Whether to allow localhost/loopback addresses.Set to True for trusted internal services like self-hostedsearch engines (e.g., searxng). Default False.- allow_private_ips: Whether to allow all RFC1918 private IPs (10.x, 172.16-31.x,- 192.168.x) plus localhost. Use for trusted self-hosted services like SearXNG- that may be running on a different machine on the local network.+ allow_private_ips: Whether to allow all private/internal IPs plus localhost.+ This includes RFC1918 (10.x, 172.16-31.x, 192.168.x), CGNAT (100.64.x.x+ used by Podman/rootless containers), link-local (169.254.x.x), and IPv6+ private ranges (fc00::/7, fe80::/10). Use for trusted self-hosted services+ like SearXNG or Ollama in containerized environments.Note: AWS metadata endpoint (169.254.169.254) is ALWAYS blocked.**kwargs: Additional arguments to pass to requests.get()@@ -115,9 +117,11 @@ def safe_post(allow_localhost: Whether to allow localhost/loopback addresses.Set to True for trusted internal services like self-hostedsearch engines (e.g., searxng). Default False.- allow_private_ips: Whether to allow all RFC1918 private IPs (10.x, 172.16-31.x,- 192.168.x) plus localhost. Use for trusted self-hosted services like SearXNG- that may be running on a different machine on the local network.+ allow_private_ips: Whether to allow all private/internal IPs plus localhost.+ This includes RFC1918 (10.x, 172.16-31.x, 192.168.x), CGNAT (100.64.x.x+ used by Podman/rootless containers), link-local (169.254.x.x), and IPv6+ private ranges (fc00::/7, fe80::/10). Use for trusted self-hosted services+ like SearXNG or Ollama in containerized environments.Note: AWS metadata endpoint (169.254.169.254) is ALWAYS blocked.**kwargs: Additional arguments to pass to requests.post()@@ -200,8 +204,10 @@ class SafeSession(requests.Session):Args:allow_localhost: Whether to allow localhost/loopback addresses.- allow_private_ips: Whether to allow all RFC1918 private IPs (10.x, 172.16-31.x,- 192.168.x) plus localhost. Use for trusted self-hosted services like SearXNG.+ allow_private_ips: Whether to allow all private/internal IPs plus localhost.+ This includes RFC1918, CGNAT (100.64.x.x used by Podman), link-local, and+ IPv6 private ranges. Use for trusted self-hosted services like SearXNG or+ Ollama in containerized environments.Note: AWS metadata endpoint (169.254.169.254) is ALWAYS blocked."""super().__init__()diff --git a/src/local_deep_research/security/ssrf_validator.py b/src/local_deep_research/security/ssrf_validator.pyindex 87398c17f9..ee9ffe9e98 100644--- a/src/local_deep_research/security/ssrf_validator.py+++ b/src/local_deep_research/security/ssrf_validator.py@@ -47,8 +47,11 @@ def is_ip_blocked(Args:ip_str: IP address as stringallow_localhost: Whether to allow localhost/loopback addresses- allow_private_ips: Whether to allow all RFC1918 private IPs (10.x, 172.16-31.x,- 192.168.x) plus localhost. Use for trusted self-hosted services like SearXNG.+ allow_private_ips: Whether to allow all private/internal IPs plus localhost.+ This includes RFC1918 (10.x, 172.16-31.x, 192.168.x), CGNAT (100.64.x.x+ used by Podman/rootless containers), link-local (169.254.x.x), and IPv6+ private ranges (fc00::/7, fe80::/10). Use for trusted self-hosted services+ like SearXNG or Ollama in containerized environments.Note: AWS metadata endpoint (169.254.169.254) is ALWAYS blocked.Returns:@@ -61,12 +64,23 @@ def is_ip_blocked(ipaddress.ip_network("::1/128"), # IPv6 loopback]- # RFC1918 private network ranges - allowed with allow_private_ips=True+ # Private/internal network ranges - allowed with allow_private_ips=True# nosec B104 - These hardcoded IPs are intentional for SSRF allowlistPRIVATE_RANGES = [+ # RFC1918 Private Rangesipaddress.ip_network("10.0.0.0/8"), # Class A privateipaddress.ip_network("172.16.0.0/12"), # Class B privateipaddress.ip_network("192.168.0.0/16"), # Class C private+ # Container/Virtual Network Ranges+ ipaddress.ip_network(+ "100.64.0.0/10"+ ), # CGNAT - used by Podman/rootless containers+ ipaddress.ip_network(+ "169.254.0.0/16"+ ), # Link-local (AWS metadata blocked separately)+ # IPv6 Private Ranges+ ipaddress.ip_network("fc00::/7"), # IPv6 Unique Local Addresses+ ipaddress.ip_network("fe80::/10"), # IPv6 Link-Local]try:@@ -119,9 +133,11 @@ def validate_url(allow_localhost: Whether to allow localhost/loopback addresses.Set to True for trusted internal services like self-hostedsearch engines (e.g., searxng). Default False.- allow_private_ips: Whether to allow all RFC1918 private IPs (10.x, 172.16-31.x,- 192.168.x) plus localhost. Use for trusted self-hosted services like SearXNG- that may be running on a different machine on the local network.+ allow_private_ips: Whether to allow all private/internal IPs plus localhost.+ This includes RFC1918 (10.x, 172.16-31.x, 192.168.x), CGNAT (100.64.x.x+ used by Podman/rootless containers), link-local (169.254.x.x), and IPv6+ private ranges (fc00::/7, fe80::/10). Use for trusted self-hosted services+ like SearXNG or Ollama in containerized environments.Note: AWS metadata endpoint (169.254.169.254) is ALWAYS blocked.Returns:diff --git a/tests/security/test_ssrf_validator.py b/tests/security/test_ssrf_validator.pyindex 147179bcf1..2fb9770158 100644--- a/tests/security/test_ssrf_validator.py+++ b/tests/security/test_ssrf_validator.py@@ -5,13 +5,19 @@ Tests for the SSRF (Server-Side Request Forgery) protection that validates URLsbefore making outgoing HTTP requests.Security model:-- By default, block all private/internal IPs (RFC1918, localhost, link-local)+- By default, block all private/internal IPs (RFC1918, localhost, link-local, CGNAT)- allow_localhost=True: Allow only loopback addresses (127.x.x.x, ::1)-- allow_private_ips=True: Allow all RFC1918 private IPs + localhost+- allow_private_ips=True: Allow all private/internal IPs + localhost:+ - RFC1918: 10.x.x.x, 172.16-31.x.x, 192.168.x.x+ - CGNAT: 100.64.x.x (used by Podman/rootless containers)+ - Link-local: 169.254.x.x (except AWS metadata)+ - IPv6 ULA: fc00::/7+ - IPv6 Link-local: fe80::/10- AWS metadata endpoint (169.254.169.254) is ALWAYS blockedThe allow_private_ips parameter is designed for trusted self-hosted services like-SearXNG that may be running on a different machine on the local network.+SearXNG or Ollama that may be running in containerized environments (Docker, Podman)+or on a different machine on the local network."""import pytest@@ -146,6 +152,75 @@ class TestIsIpBlocked:assert is_ip_blocked("169.254.1.1") is Trueassert is_ip_blocked("169.254.100.100") is True+ def test_cgnat_blocked_by_default(self):+ """CGNAT addresses (100.64.x.x) should be blocked by default."""+ from src.local_deep_research.security.ssrf_validator import (+ is_ip_blocked,+ )++ assert is_ip_blocked("100.64.0.1") is True+ assert is_ip_blocked("100.100.100.100") is True+ assert is_ip_blocked("100.127.255.255") is True++ def test_cgnat_allowed_with_allow_private_ips(self):+ """CGNAT addresses (100.64.x.x) should be allowed with allow_private_ips=True."""+ from src.local_deep_research.security.ssrf_validator import (+ is_ip_blocked,+ )++ # CGNAT range used by Podman rootless containers+ assert is_ip_blocked("100.64.0.1", allow_private_ips=True) is False+ assert is_ip_blocked("100.100.100.100", allow_private_ips=True) is False+ assert is_ip_blocked("100.127.255.255", allow_private_ips=True) is False++ def test_link_local_allowed_with_allow_private_ips(self):+ """Link-local addresses (169.254.x.x) should be allowed with allow_private_ips=True."""+ from src.local_deep_research.security.ssrf_validator import (+ is_ip_blocked,+ )++ # Non-AWS-metadata link-local addresses should be allowed+ assert is_ip_blocked("169.254.1.1", allow_private_ips=True) is False+ assert is_ip_blocked("169.254.100.100", allow_private_ips=True) is False+ # AWS metadata endpoint MUST still be blocked+ assert is_ip_blocked("169.254.169.254", allow_private_ips=True) is True++ def test_ipv6_ula_blocked_by_default(self):+ """IPv6 Unique Local Addresses (fc00::/7) should be blocked by default."""+ from src.local_deep_research.security.ssrf_validator import (+ is_ip_blocked,+ )++ assert is_ip_blocked("fc00::1") is True+ assert is_ip_blocked("fd00::1") is True++ def test_ipv6_ula_allowed_with_allow_private_ips(self):+ """IPv6 ULA (fc00::/7) should be allowed with allow_private_ips=True."""+ from src.local_deep_research.security.ssrf_validator import (+ is_ip_blocked,+ )++ assert is_ip_blocked("fc00::1", allow_private_ips=True) is False+ assert is_ip_blocked("fd00::1", allow_private_ips=True) is False++ def test_ipv6_link_local_blocked_by_default(self):+ """IPv6 link-local addresses (fe80::/10) should be blocked by default."""+ from src.local_deep_research.security.ssrf_validator import (+ is_ip_blocked,+ )++ assert is_ip_blocked("fe80::1") is True+ assert is_ip_blocked("fe80::1234:5678") is True++ def test_ipv6_link_local_allowed_with_allow_private_ips(self):+ """IPv6 link-local (fe80::/10) should be allowed with allow_private_ips=True."""+ from src.local_deep_research.security.ssrf_validator import (+ is_ip_blocked,+ )++ assert is_ip_blocked("fe80::1", allow_private_ips=True) is False+ assert is_ip_blocked("fe80::1234:5678", allow_private_ips=True) is False+class TestValidateUrl:"""Test the validate_url function."""@@ -332,6 +407,80 @@ class TestSearXNGUseCase:)+class TestContainerNetworking:+ """Test container networking scenarios (Podman, Docker, etc.)."""++ def test_podman_host_containers_internal(self):+ """Podman's host.containers.internal (resolves to CGNAT) should work with allow_private_ips."""+ from src.local_deep_research.security.ssrf_validator import validate_url++ with patch("socket.getaddrinfo") as mock_getaddrinfo:+ # Podman rootless containers typically resolve host.containers.internal to 100.64.x.x+ mock_getaddrinfo.return_value = [(2, 1, 6, "", ("100.64.1.1", 0))]+ assert (+ validate_url(+ "http://host.containers.internal:11434",+ allow_private_ips=True,+ )+ is True+ )++ def test_ollama_in_podman(self):+ """Ollama running on host accessible via Podman's CGNAT should work."""+ from src.local_deep_research.security.ssrf_validator import validate_url++ with patch("socket.getaddrinfo") as mock_getaddrinfo:+ # Ollama on host via Podman CGNAT+ mock_getaddrinfo.return_value = [+ (2, 1, 6, "", ("100.100.100.100", 0))+ ]+ assert (+ validate_url(+ "http://host.containers.internal:11434/api/generate",+ allow_private_ips=True,+ )+ is True+ )++ def test_searxng_in_podman(self):+ """SearXNG running on host accessible via Podman's CGNAT should work."""+ from src.local_deep_research.security.ssrf_validator import validate_url++ with patch("socket.getaddrinfo") as mock_getaddrinfo:+ # SearXNG on host via Podman CGNAT+ mock_getaddrinfo.return_value = [(2, 1, 6, "", ("100.64.0.1", 0))]+ assert (+ validate_url(+ "http://host.containers.internal:8080/search",+ allow_private_ips=True,+ )+ is True+ )++ def test_cgnat_url_blocked_by_default(self):+ """CGNAT URLs should be blocked by default (without allow_private_ips)."""+ from src.local_deep_research.security.ssrf_validator import validate_url++ # Direct CGNAT IP+ assert validate_url("http://100.64.0.1:8080") is False++ with patch("socket.getaddrinfo") as mock_getaddrinfo:+ mock_getaddrinfo.return_value = [(2, 1, 6, "", ("100.64.1.1", 0))]+ assert (+ validate_url("http://host.containers.internal:11434") is False+ )++ def test_docker_bridge_network(self):+ """Docker bridge network IPs should work with allow_private_ips."""+ from src.local_deep_research.security.ssrf_validator import validate_url++ # Docker typically uses 172.17.x.x for bridge network+ assert (+ validate_url("http://172.17.0.2:8080", allow_private_ips=True)+ is True+ )++class TestDocumentation:"""Documentation tests explaining the security model."""@@ -345,10 +494,11 @@ class TestDocumentation:- Internal services often have weaker security (no auth required)THE allow_private_ips PARAMETER:- - Designed for trusted self-hosted services like SearXNG- - SearXNG URL is admin-configured, not arbitrary user input- - Users intentionally run SearXNG on their local network+ - Designed for trusted self-hosted services like SearXNG, Ollama+ - Service URLs are admin-configured, not arbitrary user input+ - Users intentionally run services on their local network or in containers- This is NOT the classic SSRF vector (user submits URL)+ - Covers RFC1918, CGNAT (Podman), link-local, IPv6 private rangesCRITICAL: AWS METADATA IS ALWAYS BLOCKED:- 169.254.169.254 is the #1 SSRF target for credential theft@@ -356,10 +506,10 @@ class TestDocumentation:- This protects against credential theft in cloud environmentsSECURITY MODEL:- | Parameter | Localhost | Private IPs | AWS Metadata |- |---------------------|-----------|-------------|--------------|- | (default) | Blocked | Blocked | Blocked |- | allow_localhost | Allowed | Blocked | Blocked |- | allow_private_ips | Allowed | Allowed | BLOCKED |+ | Parameter | Localhost | RFC1918 | CGNAT (100.64.x) | Link-local | IPv6 Private | AWS Metadata |+ |---------------------|-----------|---------|------------------|------------|--------------|--------------|+ | (default) | Blocked | Blocked | Blocked | Blocked | Blocked | Blocked |+ | allow_localhost | Allowed | Blocked | Blocked | Blocked | Blocked | Blocked |+ | allow_private_ips | Allowed | Allowed | Allowed | Allowed | Allowed | BLOCKED |"""assert True # Documentation test