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): pin diagnose=False on the MCP stderr sink (follow-up to #4384, #4185) (#4394)

LearningCircuite5456be2cd23
diff --git a/changelog.d/+mcp-loguru-diagnose-lockdown.security.md b/changelog.d/+mcp-loguru-diagnose-lockdown.security.md
new file mode 100644
index 0000000000..8f54ec6350
--- /dev/null
+++ b/changelog.d/+mcp-loguru-diagnose-lockdown.security.md
@@ -0,0 +1 @@
+The MCP server subprocess (``ldr-mcp``) now pins ``diagnose=False`` on its stderr sink. loguru defaults ``diagnose=True``, which renders ``repr()`` of every traceback frame's locals on exception, so the many ``logger.exception(...)`` paths in the MCP request handlers were writing frame-local credentials (``api_key``, ``Authorization`` headers, search-engine secrets) into the MCP client's stderr log on any failure. Companion to the ``LDR_LOGURU_DIAGNOSE`` lockdown for the web/CLI logger; the MCP subprocess has no debug mode, so the gate is unconditionally off.
diff --git a/src/local_deep_research/mcp/server.py b/src/local_deep_research/mcp/server.py
index 29eff6baef..e831fe7760 100644
--- a/src/local_deep_research/mcp/server.py
+++ b/src/local_deep_research/mcp/server.py
@@ -900,10 +900,18 @@ def run_server():
# This runs in a separate subprocess (ldr-mcp) — logger.remove() only
# affects this MCP process, not the main LDR application.
logger.remove()
+ # diagnose=False: loguru's default is True, which renders repr() of every
+ # local in every traceback frame on exception. The many logger.exception()
+ # call sites in this file run with frame locals that hold credentials
+ # (api_key, Authorization headers, search-engine secrets), so leaving the
+ # default on would write them to the MCP client's stderr log on any
+ # failure. Companion to #4185 / config_logger's LDR_LOGURU_DIAGNOSE gate;
+ # the MCP subprocess has no debug mode, so the gate is unconditionally off.
logger.add(
sys.stderr,
level="INFO",
format="{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {name}:{function}:{line} | {message}",
+ diagnose=False,
)
logger.info("Starting Local Deep Research MCP server...")
mcp.run(transport="stdio")
diff --git a/src/local_deep_research/utilities/log_utils.py b/src/local_deep_research/utilities/log_utils.py
index 7b63132179..8f2560628a 100644
--- a/src/local_deep_research/utilities/log_utils.py
+++ b/src/local_deep_research/utilities/log_utils.py
@@ -540,11 +540,9 @@ def config_logger(name: str, debug: bool = False) -> None:
# Authorization headers) into every sink. Gate diagnose behind a separate
# explicit opt-in so enabling LDR_APP_DEBUG for general debug output does
# not also enable localvar dumps. Default OFF even when debug is on.
- diagnose = debug and os.environ.get("LDR_LOGURU_DIAGNOSE", "").lower() in (
- "1",
- "true",
- "yes",
- )
+ diagnose = debug and os.environ.get(
+ "LDR_LOGURU_DIAGNOSE", ""
+ ).strip().lower() in ("1", "true", "yes")
logger.add(sys.stderr, level=stderr_level, diagnose=diagnose)
logger.add(database_sink, level="DEBUG", diagnose=diagnose)
diff --git a/tests/mcp/test_additional_coverage.py b/tests/mcp/test_additional_coverage.py
index 6354a845a7..b7dedd91ef 100644
--- a/tests/mcp/test_additional_coverage.py
+++ b/tests/mcp/test_additional_coverage.py
@@ -173,6 +173,28 @@ class TestEntryPoints:
assert callable(run_server)
+ def test_run_server_disables_loguru_diagnose(self):
+ """The MCP stderr sink must pin diagnose=False (issue #4185).
+
+ loguru defaults diagnose=True, which dumps repr() of every traceback
+ frame's locals on exception. The MCP server calls logger.exception()
+ in many request handlers whose frame locals hold credentials
+ (api_key, Authorization headers, search-engine secrets); leaving the
+ default on would write them to the MCP client's stderr log.
+ """
+ import local_deep_research.mcp.server as server_module
+
+ with patch.object(server_module, "logger") as mock_logger:
+ with patch.object(server_module.mcp, "run"):
+ server_module.run_server()
+
+ assert mock_logger.add.call_args_list, "stderr sink was not added"
+ for add_call in mock_logger.add.call_args_list:
+ assert add_call.kwargs.get("diagnose") is False, (
+ f"MCP logger.add must pass diagnose=False; got "
+ f"{add_call.kwargs.get('diagnose')!r}"
+ )
+
class TestTemperatureParameter:
"""Tests for temperature parameter in research tools."""
diff --git a/tests/utilities/test_log_utils_extended.py b/tests/utilities/test_log_utils_extended.py
index 74c659840f..12a4c973ed 100644
--- a/tests/utilities/test_log_utils_extended.py
+++ b/tests/utilities/test_log_utils_extended.py
@@ -634,6 +634,30 @@ class TestConfigLoggerExtended:
for add_call in mock_logger.add.call_args_list:
assert add_call[1].get("diagnose") is False
+ def test_diagnose_optin_tolerates_surrounding_whitespace(self):
+ """LDR_LOGURU_DIAGNOSE=' true ' must still enable diagnose.
+
+ Env vars exported via shell scripts, k8s ConfigMaps, or copy-paste
+ commonly carry stray whitespace; without strip() the opt-in would
+ silently fail and the operator would assume diagnose was on.
+ """
+ from local_deep_research.utilities.log_utils import config_logger
+ import local_deep_research.utilities.log_utils as module
+
+ with patch.dict(
+ os.environ,
+ {
+ "LDR_ENABLE_FILE_LOGGING": "",
+ "LDR_LOGURU_DIAGNOSE": " true ",
+ },
+ ):
+ with patch.object(module, "logger") as mock_logger:
+ config_logger("test_app", debug=True)
+
+ assert mock_logger.add.call_args_list
+ for add_call in mock_logger.add.call_args_list:
+ assert add_call[1].get("diagnose") is True
+
def test_creates_milestone_level(self):
"""Should create MILESTONE log level with level no=26."""
from local_deep_research.utilities.log_utils import config_logger