~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(security): redact api_key in NASA ADS search engine error log (#4131 follow-up) (#4432)
LearningCircuitcb7d3f2f3994
diff --git a/changelog.d/+nasa-ads-redact-api-key.security.md b/changelog.d/+nasa-ads-redact-api-key.security.mdnew file mode 100644index 0000000000..38be3f69c8--- /dev/null+++ b/changelog.d/+nasa-ads-redact-api-key.security.md@@ -0,0 +1 @@+Extended `redact_secrets()` coverage to the NASA ADS search engine, which was missed by the original #4131 sweep. Its `_get_previews` catch-all used `logger.exception`, whose traceback frames hold `self.headers` (the `Authorization: Bearer <key>` value) and would render the API key under loguru diagnose mode. The except block now uses a redacted `logger.warning`. Follow-up to #4131.diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_nasa_ads.py b/src/local_deep_research/web_search_engines/engines/search_engine_nasa_ads.pyindex 553aac4379..ab20f48e53 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_nasa_ads.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_nasa_ads.py@@ -9,6 +9,7 @@ from ...constants import SNIPPET_LENGTH_LONG, USER_AGENTfrom ...advanced_search_system.filters.journal_reputation_filter import (JournalReputationFilter,)+from ...security.log_sanitizer import redact_secretsfrom ...security.safe_requests import safe_getfrom ..rate_limiting import RateLimitErrorfrom ..search_engine_base import BaseSearchEngine@@ -243,8 +244,13 @@ class NasaAdsSearchEngine(BaseSearchEngine):except RateLimitError:# Re-raise rate limit errors for base class retry handlingraise- except Exception:- logger.exception("Error searching NASA ADS")+ except Exception as e:+ # logger.warning rather than logger.exception: the traceback+ # frames hold self.headers (the "Authorization: Bearer <key>"+ # value) and would render it under loguru diagnose. Redact the+ # api_key from the message as defense-in-depth.+ safe_msg = redact_secrets(str(e), self.api_key)+ logger.warning(f"Error searching NASA ADS: {safe_msg}")return []def _format_doc_preview(diff --git a/tests/security/test_api_key_leakage.py b/tests/security/test_api_key_leakage.pyindex ba8a598e79..b07cbd3ff2 100644--- a/tests/security/test_api_key_leakage.py+++ b/tests/security/test_api_key_leakage.py@@ -475,3 +475,64 @@ class TestSearchEngineKeyLeakage:f"{engine_class} test did not exercise the except branch. "f"Captured logs: {loguru_caplog_full.text!r}")++ def test_nasa_ads_get_previews_does_not_leak_on_request_exception(+ self, loguru_caplog_full+ ):+ """NASA ADS sends its key as an ``Authorization: Bearer`` header+ (``self.headers``) and its ``_get_previews`` catch-all logged the+ exception unredacted. This engine was *not* in the original #4131+ engine list — it is covered by the #4131 follow-up. The except+ block must redact ``self.api_key`` from the rendered exception+ text. We drive this by patching ``safe_get`` to raise an exception+ whose ``str()`` embeds the sentinel in the URL.+ """+ from local_deep_research.web_search_engines.engines import (+ search_engine_nasa_ads as mod,+ )++ EngineCls = mod.NasaAdsSearchEngine++ engine = EngineCls.__new__(EngineCls)+ engine.api_key = _LEAKED_KEY+ engine.headers = {"Authorization": f"Bearer {_LEAKED_KEY}"}+ engine.api_base = "https://api.adsabs.harvard.edu/v1"+ engine.max_results = 10+ engine.sort_by = "relevance"+ engine.from_publication_date = None+ engine.min_citations = 0+ engine.include_arxiv = True+ engine.engine_type = "test_engine"+ engine.rate_tracker = type(+ "_T",+ (),+ {+ "enabled": False,+ "record_event": lambda *a, **k: None,+ "apply_rate_limit": lambda *a, **k: 0,+ },+ )()++ exc = requests.exceptions.ConnectionError(+ f"HTTPSConnectionPool: Max retries exceeded with url: "+ f"/v1/search/query?token={_LEAKED_KEY}"+ )++ with loguru_caplog_full.at_level("DEBUG"):+ with patch.object(mod, "safe_get", side_effect=exc, create=True):+ try:+ engine._get_previews("test query")+ except Exception:+ pass++ for encoding in _all_encodings_of(_LEAKED_KEY):+ assert encoding not in loguru_caplog_full.text, (+ "NASAADSSearchEngine leaked api_key as encoding "+ f"{encoding!r}. The except block must call "+ "redact_secrets(str(e), self.api_key) before logging."+ )+ # Sanity: the except branch must have actually run.+ assert "Error searching NASA ADS" in loguru_caplog_full.text, (+ "NASA ADS test did not exercise the except branch. "+ f"Captured logs: {loguru_caplog_full.text!r}"+ )