Skip to content

~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.

fix(security): strip leading whitespace before redacting a URL for the log (#6773)

Lukasb836e3a2711d
diff --git a/src/local_deep_research/security/ssrf_validator.py b/src/local_deep_research/security/ssrf_validator.py
index 4ee43fb046..ed615bfc5b 100644
--- a/src/local_deep_research/security/ssrf_validator.py
+++ b/src/local_deep_research/security/ssrf_validator.py
@@ -593,7 +593,9 @@ def redact_url_for_log(url: str) -> str:
credentials if a misconfiguration produced it.
"""
try:
- u = parse_url(url)
+ # requests strips leading whitespace before it fetches; parse_url does
+ # not, and would put the scheme in the host slot.
+ u = parse_url(url.lstrip() if isinstance(url, str) else url)
scheme = u.scheme or "?"
host = u.host or "<no-host>"
host_port = f"{host}:{u.port}" if u.port else host
diff --git a/tests/security/test_ssrf_validator.py b/tests/security/test_ssrf_validator.py
index 3584a069ab..646487b2f8 100644
--- a/tests/security/test_ssrf_validator.py
+++ b/tests/security/test_ssrf_validator.py
@@ -1049,6 +1049,22 @@ class TestRedactUrlForLog:
result = redact_url_for_log("//example.com/path")
assert result.startswith("?://") or result == "<unparseable>"
+ def test_leading_whitespace_is_stripped_the_way_requests_strips_it(self):
+ """requests fetches a URL with leading whitespace, so the log must name
+ its real origin rather than put the scheme in the host slot."""
+ from local_deep_research.security.ssrf_validator import (
+ redact_url_for_log,
+ )
+
+ assert (
+ redact_url_for_log(" https://slow-host.example/paper")
+ == "https://slow-host.example"
+ )
+ assert (
+ redact_url_for_log("\thttps://h.example:8443/x?token=abc")
+ == "https://h.example:8443"
+ )
+
def test_unparseable_returns_sentinel(self):
"""urllib3 rejects malformed IPv6 brackets and out-of-range
ports; helper falls back to <unparseable>."""