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 DatabaseInitializationError consumers (#4182) (#4550)

LearningCircuit5ee573e33f50
diff --git a/changelog.d/+db-init-consumer-redaction.security.md b/changelog.d/+db-init-consumer-redaction.security.md
new file mode 100644
index 0000000000..f3aa72c63e
--- /dev/null
+++ b/changelog.d/+db-init-consumer-redaction.security.md
@@ -0,0 +1 @@
+Closed the last `diagnose=True` frame-locals leak of the SQLCipher master password from the #4182 sweep: the two consumers of `DatabaseInitializationError` — `thread_local_session.get_session` and `ResourceStatusTracker.__init__` — caught the error and logged it with `logger.exception` while `password` was a live local in the frame, so a rendered traceback could persist the plaintext password (unrecoverable — TRUST.md §5). Both now log with `logger.warning` (no traceback); the redacted detail is already logged at the raise site. The two modules are 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_local_session.py b/src/local_deep_research/database/thread_local_session.py
index 96236c67d2..554d39a5f3 100644
--- a/src/local_deep_research/database/thread_local_session.py
+++ b/src/local_deep_research/database/thread_local_session.py
@@ -96,7 +96,14 @@ class ThreadLocalSessionManager:
try:
engine = db_manager.open_user_database(username, password)
except DatabaseInitializationError:
- logger.exception(
+ # ``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 redacted failure detail
+ # is already logged at the raise site in
+ # ``open_user_database`` (#4182).
+ logger.warning(
f"Thread {thread_id}: database init failed for user {username}"
)
return None
diff --git a/src/local_deep_research/library/download_management/status_tracker.py b/src/local_deep_research/library/download_management/status_tracker.py
index 2e46973961..12c1da8583 100644
--- a/src/local_deep_research/library/download_management/status_tracker.py
+++ b/src/local_deep_research/library/download_management/status_tracker.py
@@ -65,7 +65,14 @@ class ResourceStatusTracker:
# callers as a plain RuntimeError — they all wrap construction
# in try/except already, and propagating the typed exception
# would couple every caller to encrypted_db's internals.
- logger.exception(
+ # ``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 redacted failure detail
+ # is already logged at the raise site in
+ # ``open_user_database`` (#4182).
+ logger.warning(
f"[STATUS_TRACKER] Database init failed for user: {username}"
)
raise RuntimeError(
diff --git a/tests/security/test_password_leakage.py b/tests/security/test_password_leakage.py
index 78334ff151..754351732d 100644
--- a/tests/security/test_password_leakage.py
+++ b/tests/security/test_password_leakage.py
@@ -182,10 +182,10 @@ class TestEncryptedDBPasswordLeakage:
):
"""A migration failure re-raises as ``DatabaseInitializationError``.
The typed error must carry a redacted message and no exception
- chain (``from None``, ADR-0003): the caller
- (``thread_local_session``) logs it with ``logger.exception``,
- which would otherwise render the original exception (and its
- frame locals holding the password) in full — defeating the
+ chain (``from None``, ADR-0003): callers (e.g.
+ ``thread_local_session``) log it, and the broken chain plus
+ redacted message ensure the original exception — and its frame
+ locals holding the password — can't be rendered, defeating the
redaction applied at the raise site.
"""
from local_deep_research.database.encrypted_db import (
diff --git a/tests/security/test_password_redaction_invariant.py b/tests/security/test_password_redaction_invariant.py
index af6af43a69..e9dc11f350 100644
--- a/tests/security/test_password_redaction_invariant.py
+++ b/tests/security/test_password_redaction_invariant.py
@@ -21,8 +21,10 @@ The required pattern at such sites is::
Scope and limitations (deliberate, keep in sync with the sweep):
-- Only the three files swept by #4530 are checked. Extend ``SWEPT_MODULES``
- when a new module starts handling the master password.
+- 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.
- A "password name" is any identifier containing ``password`` (case-
insensitive), excluding ``session_password_store`` (a module-level store
object, not a credential value).
@@ -53,11 +55,18 @@ import pytest
import local_deep_research.database.encrypted_db as encrypted_db_module
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
SWEPT_MODULES = [
encrypted_db_module,
background_module,
processor_v2_module,
+ # Consumers of ``DatabaseInitializationError`` that hold the master
+ # password in scope while logging the catch (#4182 follow-up): the
+ # raise site redacts, but these callers re-render via the logger.
+ thread_local_session_module,
+ status_tracker_module,
]
# Names that match the password heuristic but are not credential values.