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(downloaders): strip userinfo from the robots.txt request URL (#5805)

LearningCircuit1e61af86b8b8
diff --git a/changelog.d/+robots-request-authority.security.md b/changelog.d/+robots-request-authority.security.md
new file mode 100644
index 0000000000..d2fa968727
--- /dev/null
+++ b/changelog.d/+robots-request-authority.security.md
@@ -0,0 +1 @@
+Omit URL userinfo from robots.txt requests while preserving authority brackets and explicit ports.
diff --git a/src/local_deep_research/research_library/downloaders/playwright_html.py b/src/local_deep_research/research_library/downloaders/playwright_html.py
index b250ffedf3..120ce2dc94 100644
--- a/src/local_deep_research/research_library/downloaders/playwright_html.py
+++ b/src/local_deep_research/research_library/downloaders/playwright_html.py
@@ -897,11 +897,21 @@ class PlaywrightHTMLDownloader(HTMLDownloader):
from urllib.robotparser import RobotFileParser
try:
+ # A backslash, whitespace or control character makes urlparse
+ # and browsers disagree about the host (``http://a\\@b/`` is
+ # host ``a`` to a browser, ``b`` to urlparse). Such a URL is
+ # refused by the SSRF validator anyway; do not derive a robots
+ # request for another host from it.
+ if ssrf_validator.RFC_FORBIDDEN_URL_CHARS_RE.search(url):
+ return True
parsed = urlparse(url)
- if not parsed.netloc:
+ # Keep the authority's bracket and port syntax while omitting
+ # any userinfo from this derived request.
+ authority = parsed.netloc.rpartition("@")[2]
+ if not authority:
return True
scheme = parsed.scheme or "http"
- robots_url = f"{scheme}://{parsed.netloc}/robots.txt"
+ robots_url = f"{scheme}://{authority}/robots.txt"
response = self.session.get(
robots_url,
timeout=min(self.timeout, 10),
diff --git a/tests/research_library/downloaders/test_playwright_html_ssrf_guard.py b/tests/research_library/downloaders/test_playwright_html_ssrf_guard.py
index 306bc943c2..f55b974ef3 100644
--- a/tests/research_library/downloaders/test_playwright_html_ssrf_guard.py
+++ b/tests/research_library/downloaders/test_playwright_html_ssrf_guard.py
@@ -1835,6 +1835,101 @@ class TestGuardedRobots:
def _dl(self):
return PlaywrightHTMLDownloader(timeout=5)
+ @pytest.mark.parametrize(
+ ("page_url", "robots_url"),
+ [
+ (
+ "https://example.com/paper?view=full#section",
+ "https://example.com/robots.txt",
+ ),
+ ("http://192.0.2.1/paper", "http://192.0.2.1/robots.txt"),
+ (
+ "http://192.0.2.1:8080/paper?view=full",
+ "http://192.0.2.1:8080/robots.txt",
+ ),
+ ("http://[2001:db8::1]/paper", "http://[2001:db8::1]/robots.txt"),
+ (
+ "http://[2001:db8::1]:8080/paper?view=full",
+ "http://[2001:db8::1]:8080/robots.txt",
+ ),
+ (
+ "https://reader:[email protected]/paper?view=full",
+ "https://example.com/robots.txt",
+ ),
+ (
+ "https://reader:placeholder@[2001:db8::1]:8443/paper",
+ "https://[2001:db8::1]:8443/robots.txt",
+ ),
+ ("http://example.com:0/paper", "http://example.com:0/robots.txt"),
+ (
+ "http://[v1.example]/paper?view=full",
+ "http://[v1.example]/robots.txt",
+ ),
+ ],
+ ids=[
+ "query-and-fragment",
+ "ipv4",
+ "ipv4-port",
+ "ipv6",
+ "ipv6-port-query",
+ "userinfo",
+ "ipv6-userinfo-port",
+ "zero-port",
+ "bracketed-authority",
+ ],
+ )
+ def test_robots_request_uses_normalized_authority(
+ self, page_url, robots_url
+ ):
+ dl = self._dl()
+ try:
+ response = MagicMock(
+ status_code=200, text="User-agent: *\nAllow: /\n"
+ )
+ with patch.object(dl.session, "get", return_value=response) as get:
+ assert dl._robots_allows(page_url) is True
+ get.assert_called_once_with(
+ robots_url, timeout=5, allow_redirects=True
+ )
+ finally:
+ dl.close()
+
+ def test_robots_request_strips_every_userinfo_at_sign(self):
+ """The last ``@`` ends the userinfo, as urllib3 and browsers agree."""
+ dl = self._dl()
+ try:
+ response = MagicMock(
+ status_code=200, text="User-agent: *\nAllow: /\n"
+ )
+ with patch.object(dl.session, "get", return_value=response) as get:
+ assert dl._robots_allows("http://a@[email protected]/p") is True
+ get.assert_called_once_with(
+ "http://good.example/robots.txt",
+ timeout=5,
+ allow_redirects=True,
+ )
+ finally:
+ dl.close()
+
+ @pytest.mark.parametrize(
+ "page_url",
+ [
+ "http://evil.example\\@good.example/p",
+ "http://evil.example /@good.example/p",
+ "http://evil.example\[email protected]/p",
+ ],
+ ids=["backslash", "space", "nul"],
+ )
+ def test_robots_skips_urls_whose_host_parsers_disagree_on(self, page_url):
+ """Never send a robots request to a host the browser would not visit."""
+ dl = self._dl()
+ try:
+ with patch.object(dl.session, "get") as get:
+ assert dl._robots_allows(page_url) is True
+ get.assert_not_called()
+ finally:
+ dl.close()
+
def test_robots_redirect_to_blocked_is_guarded_and_fails_open(self):
sentinel_hits = {"n": 0}
diff --git a/tests/security/test_notification_host_alias_fragments.py b/tests/security/test_notification_host_alias_fragments.py
index 7c566cd792..dad96dd109 100644
--- a/tests/security/test_notification_host_alias_fragments.py
+++ b/tests/security/test_notification_host_alias_fragments.py
@@ -221,8 +221,8 @@ def test_percent_encoded_numeric_ipv4_fragment_fails_closed(
# ``[/?#]`` trailer is what keeps a recipient whose domain part IS
# spelled like a loopback host one too.
"admin@localhost",
# A one-component inet_aton host is any integer below 2**32, so every