~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(topic-organization): keep URL credentials out of the lead-selection prompt (#8058)
Bhavay Goyaldb31de812c15
diff --git a/changelog.d/+topic-lead-prompt-url-userinfo.security.md b/changelog.d/+topic-lead-prompt-url-userinfo.security.mdnew file mode 100644index 0000000000..63583a8d36--- /dev/null+++ b/changelog.d/+topic-lead-prompt-url-userinfo.security.md@@ -0,0 +1 @@+The topic organization strategy no longer sends a source URL's credentials to the LLM: the lead-selection host label and the per-source categorization prompt both now go through the shared URL redactor, which also catches a password containing an unencoded `/`, `?` or `#` and a `;`-style authority parameter that the previous naive split missed.diff --git a/src/local_deep_research/advanced_search_system/strategies/topic_organization_strategy.py b/src/local_deep_research/advanced_search_system/strategies/topic_organization_strategy.pyindex 92ad6933f2..a597aa9b3f 100644--- a/src/local_deep_research/advanced_search_system/strategies/topic_organization_strategy.py+++ b/src/local_deep_research/advanced_search_system/strategies/topic_organization_strategy.py@@ -13,6 +13,7 @@ from .source_based_strategy import SourceBasedSearchStrategyfrom .focused_iteration_strategy import FocusedIterationStrategyfrom ..findings.topic import Topic, TopicGraphfrom ..findings.repository import FindingsRepository+from ...security.url_redaction import redact_url_credentialsfrom ...utilities.json_utils import extract_json, get_llm_response_textfrom ...utilities.thread_context import preserve_research_context@@ -332,7 +333,14 @@ class TopicOrganizationStrategy(BaseSearchStrategy):ideal_sources_per_topic = ideal_topics # Same as number of topicscurrent_topics = len(topics)- # Create prompt for this specific source+ # Create prompt for this specific source. The URL is redacted+ # through the shared helper so credentials embedded in it+ # (userinfo, an API-key query parameter, ...) never reach the+ # LLM or the debug log of this prompt below.+ source_link = source.get("link", "")+ safe_source_url = (+ redact_url_credentials(source_link) if source_link else ""+ )source_prompt = f"""For the research query: "{query}"@@ -354,7 +362,7 @@ GUIDELINES:CURRENT SOURCE TO CATEGORIZE:Title: {source.get("title", "Untitled")}-URL: {source.get("link", "")}+URL: {safe_source_url}Snippet: {source.get("snippet", "")}EXISTING TOPICS (showing source count):@@ -538,13 +546,22 @@ Response:"""snippet = source.get("snippet", "")url = source.get("url", "")- # Extract domain from URL- from urllib.parse import urlparse-- try:- domain = urlparse(url).netloc if url else ""- except (ValueError, AttributeError):- domain = ""+ # Extract the host via the shared redactor rather than+ # urlparse(url).netloc.rpartition("@")[2]: that naive split+ # misses credentials whenever the password contains an+ # unencoded "/", "?" or "#" (the netloc then ends before the+ # "@", so rpartition finds nothing and the credential text is+ # returned as-is) and leaves a ";api_key=..." authority+ # parameter in place. redact_url_credentials fails closed to+ # "<unknown>" in both cases instead.+ from urllib.parse import urlsplit++ redacted_url = redact_url_credentials(url) if url else ""+ domain = (+ urlsplit(redacted_url).netloc+ if redacted_url and redacted_url != "<unknown>"+ else ""+ )# Format source info without restrictionssource_info = f"{idx}: [{domain}] {title}"diff --git a/tests/advanced_search_system/strategies/test_topic_organization_strategy.py b/tests/advanced_search_system/strategies/test_topic_organization_strategy.pyindex 5792369ffb..a1244823a6 100644--- a/tests/advanced_search_system/strategies/test_topic_organization_strategy.py+++ b/tests/advanced_search_system/strategies/test_topic_organization_strategy.py@@ -337,6 +337,45 @@ class TestTopicExtraction:# No topics should be createdassert topics == []+ def test_extract_topics_prompt_omits_url_credentials(self):+ """The per-source categorization prompt also drops URL credentials.++ This is the same leak as the lead-selection prompt, but earlier in+ the pipeline: ``source.get("link", "")`` is sent to the LLM+ verbatim (and logged in full for the first few sources), so a+ source URL with embedded credentials or an API-key query+ parameter must go through the shared redactor first.+ """+ from local_deep_research.advanced_search_system.strategies.topic_organization_strategy import (+ TopicOrganizationStrategy,+ )++ mock_search = Mock()+ mock_model = Mock()+ mock_model.invoke.return_value = Mock(content="-")++ strategy = TopicOrganizationStrategy(+ search=mock_search,+ model=mock_model,+ )+ strategy.progress_callback = None++ sources = [+ {+ "title": "Source 1",+ "snippet": "Content 1",+ "link": "https://alice:[email protected]/page?api_key=topsecret",+ },+ ]++ strategy._extract_topics_from_sources(sources, "test query")++ prompt = mock_model.invoke.call_args.args[0]+ assert "docs.example.com" in prompt+ assert "alice" not in prompt+ assert "s3cret" not in prompt+ assert "topsecret" not in prompt+class TestLeadSourceReselection:"""Tests for lead source reselection methods."""@@ -372,6 +411,110 @@ class TestLeadSourceReselection:assert result is False+ def test_reselect_lead_prompt_omits_url_credentials(self):+ """Source labels in the lead selection prompt drop URL userinfo."""+ from local_deep_research.advanced_search_system.strategies.topic_organization_strategy import (+ TopicOrganizationStrategy,+ )+ from local_deep_research.advanced_search_system.findings.topic import (+ Topic,+ )++ strategy = TopicOrganizationStrategy(search=Mock(), model=Mock())+ lead = {+ "title": "Lead",+ "snippet": "Content",+ "url": "https://alice:[email protected]/page",+ }+ topic = Topic(id="t1", title="Lead", lead_source=lead)+ topic.add_supporting_source(+ {+ "title": "Other",+ "snippet": "More",+ "url": "http://[email protected]:8080/a",+ }+ )+ topic.add_supporting_source(+ {+ "title": "Plain",+ "snippet": "",+ "url": "https://plain.example.net",+ }+ )++ with patch.object(+ strategy, "_invoke_model", return_value="0"+ ) as invoke:+ assert (+ strategy._reselect_lead_for_single_topic(topic, [topic])+ is False+ )++ prompt = invoke.call_args.args[0]+ assert "0: [docs.example.com] Lead" in prompt+ assert "1: [mirror.example.org:8080] Other" in prompt+ assert "2: [plain.example.net] Plain" in prompt+ assert "alice" not in prompt+ assert "s3cret" not in prompt+ assert "token" not in prompt++ @pytest.mark.parametrize(+ "bad_url",+ [+ # A password containing an unencoded "/" ends the authority+ # early, so urlparse(url).netloc.rpartition("@")[2] finds no+ # "@" in "alice:pa" and returns it unchanged -- leaking the+ # credential into the domain label.+ "https://alice:pa/[email protected]/page",+ # Same, with "?" in the password.+ "https://alice:[email protected]/page",+ # Same, with "#" in the password.+ "https://alice:pa#[email protected]/page",+ # A ";" authority parameter is not part of the host either.+ "https://host.example.com;api_key=topsecret/page",+ ],+ )+ def test_reselect_lead_prompt_omits_credentials_with_delimiter_passwords(+ self, bad_url: str+ ):+ """A password/parameter the naive split can't isolate is dropped.++ These shapes defeat ``urlparse(url).netloc.rpartition("@")[2]``+ (see the parametrized cases), so the label must come from the+ shared redactor, which fails closed to an empty label instead of+ echoing the un-isolated credential text.+ """+ from local_deep_research.advanced_search_system.strategies.topic_organization_strategy import (+ TopicOrganizationStrategy,+ )+ from local_deep_research.advanced_search_system.findings.topic import (+ Topic,+ )++ strategy = TopicOrganizationStrategy(search=Mock(), model=Mock())+ topic = Topic(+ id="t1",+ title="Lead",+ lead_source={"title": "Lead", "snippet": "", "url": bad_url},+ )+ topic.add_supporting_source(+ {+ "title": "Other",+ "snippet": "",+ "url": "https://plain.example.net",+ }+ )++ with patch.object(+ strategy, "_invoke_model", return_value="0"+ ) as invoke:+ strategy._reselect_lead_for_single_topic(topic, [topic])++ prompt = invoke.call_args.args[0]+ assert "0: []" in prompt+ assert "alice" not in prompt+ assert "topsecret" not in prompt+class TestTopicRelationships:"""Tests for topic relationship methods."""