~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
test(security): tripwire for the always-blocked metadata IP set (#6548)
LearningCircuit29f167ff05d5
diff --git a/tests/security/test_metadata_ip_set_tripwire.py b/tests/security/test_metadata_ip_set_tripwire.pynew file mode 100644index 0000000000..d5ca785296--- /dev/null+++ b/tests/security/test_metadata_ip_set_tripwire.py@@ -0,0 +1,73 @@+"""Set-membership tripwire for the always-blocked metadata IPs.++``ALWAYS_BLOCKED_METADATA_IPS`` is the SSRF chain's absolute floor:+every entry is a cloud instance-metadata endpoint, and the review+contract says any **removal** is Critical while additions are fine.+Behavioral coverage today reaches four of the six members (via one+route-level suite); the other two — ``169.254.170.23`` (AWS ECS v4)+and ``169.254.0.23`` (Tencent) — have no test anywhere, and no test+pins the set property itself. A consolidation refactor that drops an+entry therefore lands green.++The IPv6 member deserves its own pin: ``fd00:ec2::254`` is a ULA,+not an IPv4-mapped or NAT64-wrapped form of the IPv4 entries, so no+derived check covers it — it must stay listed explicitly or it is+reachable under ``allow_private_ips=True`` (which permits fc00::/7).+"""++from __future__ import annotations++import pytest++from local_deep_research.security.ssrf_validator import (+ ALWAYS_BLOCKED_METADATA_IPS,+ is_ip_blocked,+)++#: Every endpoint documented for the set (additions to the production+#: set are fine; these may never leave it).+DOCUMENTED_METADATA_IPS = frozenset(+ {+ "169.254.169.254", # AWS IMDSv1/v2, Azure, OCI, DigitalOcean+ "169.254.170.2", # AWS ECS task metadata v3+ "169.254.170.23", # AWS ECS task metadata v4+ "169.254.0.23", # Tencent Cloud+ "100.100.100.200", # AlibabaCloud+ "fd00:ec2::254", # AWS IMDS over IPv6+ }+)+++class TestMetadataIpSetTripwire:+ def test_every_documented_metadata_ip_stays_in_the_set(self):+ missing = DOCUMENTED_METADATA_IPS - ALWAYS_BLOCKED_METADATA_IPS+ assert missing == frozenset(), (+ f"metadata endpoints removed from the always-blocked set: "+ f"{sorted(missing)} — any removal is Critical"+ )++ def test_the_ipv6_imds_entry_is_explicit(self):+ """fd00:ec2::254 is a ULA, not derivable from the IPv4 entries+ or the NAT64 check; dropping the explicit listing reopens it+ under allow_private_ips."""+ assert "fd00:ec2::254" in ALWAYS_BLOCKED_METADATA_IPS++ @pytest.mark.parametrize(+ "ip", sorted(DOCUMENTED_METADATA_IPS), ids=lambda v: v.replace(":", "-")+ )+ def test_each_member_stays_blocked_under_the_permissive_posture(self, ip):+ """The absolute floor: blocked even when localhost AND private+ ranges are allowed — the posture that exists precisely so+ users can point the app at Ollama/LM Studio/vLLM."""+ assert is_ip_blocked(+ ip, allow_localhost=True, allow_private_ips=True+ ), f"{ip} is not blocked under the permissive posture"++ def test_the_set_only_contains_metadata_endpoints_shape(self):+ """Sanity for additions: every member parses as an IP literal,+ so the set cannot silently drift into hostname entries the+ IP-comparison path would never match."""+ import ipaddress++ for member in ALWAYS_BLOCKED_METADATA_IPS:+ ipaddress.ip_address(member)