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): redact password leak in ThreadSafeMetricsWriter.get_session (#4182) (#4553)

LearningCircuit2ed03445df79
diff --git a/changelog.d/+thread-metrics-redaction.security.md b/changelog.d/+thread-metrics-redaction.security.md
new file mode 100644
index 0000000000..6a5fed0d05
--- /dev/null
+++ b/changelog.d/+thread-metrics-redaction.security.md
@@ -0,0 +1 @@
+Closed another `diagnose=True` frame-locals leak of the SQLCipher master password from the #4182 sweep: `ThreadSafeMetricsWriter.get_session` opened a per-thread metrics session with `password` live in the frame and logged failures with `logger.exception`, so a rendered traceback could persist the plaintext password (unrecoverable — TRUST.md §5). It now logs with `logger.warning` (no traceback); the exception still propagates to the caller via `raise`, so nothing is swallowed. The module is added to the `test_password_redaction_invariant` allow-list so CI permanently blocks any regression. See #4182.
diff --git a/src/local_deep_research/database/thread_metrics.py b/src/local_deep_research/database/thread_metrics.py
index 8b6a96742a..ca9738274a 100644
--- a/src/local_deep_research/database/thread_metrics.py
+++ b/src/local_deep_research/database/thread_metrics.py
@@ -98,7 +98,14 @@ class ThreadSafeMetricsWriter:
yield session
session.commit()
except Exception:
- logger.exception(f"Session error for {username}")
+ # ``logger.warning`` (no traceback) rather than
+ # ``logger.exception``: ``password`` is a live local in this
+ # frame, so rendering a traceback under ``diagnose=True``
+ # would dump the plaintext SQLCipher master password
+ # (unrecoverable — TRUST.md §5). The exception still
+ # propagates via the ``raise`` below, so no detail is
+ # swallowed for the caller (#4182).
+ logger.warning(f"Session error for {username}")
if session:
session.rollback()
raise
diff --git a/tests/security/test_password_redaction_invariant.py b/tests/security/test_password_redaction_invariant.py
index e9dc11f350..f01db94fd5 100644
--- a/tests/security/test_password_redaction_invariant.py
+++ b/tests/security/test_password_redaction_invariant.py
@@ -21,10 +21,10 @@ The required pattern at such sites is::
Scope and limitations (deliberate, keep in sync with the sweep):
-- Only the modules in ``SWEPT_MODULES`` are checked: the three files
- swept by #4530 plus the two ``DatabaseInitializationError`` consumers
- added in the #4182 follow-up. Extend ``SWEPT_MODULES`` when a new
- module starts handling the master password.
+- Only the modules in ``SWEPT_MODULES`` are checked: the files swept by
+ #4530 plus the password-bearing session helpers added in the #4182
+ follow-up. Extend ``SWEPT_MODULES`` when a new module starts handling
+ the master password.
- A "password name" is any identifier containing ``password`` (case-
insensitive), excluding ``session_password_store`` (a module-level store
object, not a credential value).
@@ -57,6 +57,7 @@ import local_deep_research.scheduler.background as background_module
import local_deep_research.web.queue.processor_v2 as processor_v2_module
import local_deep_research.database.thread_local_session as thread_local_session_module
import local_deep_research.library.download_management.status_tracker as status_tracker_module
+import local_deep_research.database.thread_metrics as thread_metrics_module
SWEPT_MODULES = [
encrypted_db_module,
@@ -67,6 +68,9 @@ SWEPT_MODULES = [
# raise site redacts, but these callers re-render via the logger.
thread_local_session_module,
status_tracker_module,
+ # Holds the master password in scope while opening a per-thread
+ # metrics session and logging the failure (#4182 follow-up).
+ thread_metrics_module,
]
# Names that match the password heuristic but are not credential values.