~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): parse LDR_TEST_MODE as a boolean for the KDF floor (#4564)
LearningCircuit703efd3a056a
diff --git a/changelog.d/+kdf-test-mode-bool-parse.bugfix.md b/changelog.d/+kdf-test-mode-bool-parse.bugfix.mdnew file mode 100644index 0000000000..b84e2740e5--- /dev/null+++ b/changelog.d/+kdf-test-mode-bool-parse.bugfix.md@@ -0,0 +1 @@+Parse ``LDR_TEST_MODE`` as a proper boolean when deciding whether to relax the SQLCipher KDF floor. Previously ``_get_min_kdf_iterations()`` used a bare truthiness check, so any non-empty value — including ``LDR_TEST_MODE=0`` or ``=false`` — enabled the relaxed test minimum, silently weakening database encryption for anyone setting the flag explicitly to disable it. ``PYTEST_CURRENT_TEST`` stays presence-based (pytest sets it to a non-boolean string).diff --git a/src/local_deep_research/database/sqlcipher_utils.py b/src/local_deep_research/database/sqlcipher_utils.pyindex 1a3200f0b7..9447f2a358 100644--- a/src/local_deep_research/database/sqlcipher_utils.py+++ b/src/local_deep_research/database/sqlcipher_utils.py@@ -16,6 +16,7 @@ from typing import Any, Dict, Optional, Unionfrom loguru import loggerfrom ..settings.env_registry import get_env_setting+from ..utilities.type_utils import to_bool# Lock to protect cipher_default_* global state during creation_cipher_default_lock = threading.Lock()@@ -282,9 +283,16 @@ def _get_min_kdf_iterations() -> int:LDR_TEST_MODE (project-specific) is set. Generic env vars like CI orTESTING are NOT checked to avoid accidentally weakening productionencryption in Docker/CD pipelines that set CI=true.++ PYTEST_CURRENT_TEST is presence-based: pytest sets it to a descriptive+ non-boolean string (e.g. "tests/foo.py::test_bar (call)"), so its mere+ presence signals a test run. LDR_TEST_MODE is parsed as a proper boolean+ so an explicit LDR_TEST_MODE=0 / =false does NOT relax the floor — a bare+ truthiness check would treat any non-empty string (including "false") as+ enabled and silently weaken encryption for someone trying to disable it."""- is_testing = os.environ.get("PYTEST_CURRENT_TEST") or os.environ.get(- "LDR_TEST_MODE"+ is_testing = bool(os.environ.get("PYTEST_CURRENT_TEST")) or to_bool(+ os.environ.get("LDR_TEST_MODE"))return (MIN_KDF_ITERATIONS_TESTINGdiff --git a/tests/database/test_sqlcipher_utils.py b/tests/database/test_sqlcipher_utils.pyindex 45e738955f..aab63721c0 100644--- a/tests/database/test_sqlcipher_utils.py+++ b/tests/database/test_sqlcipher_utils.py@@ -1226,6 +1226,28 @@ class TestCIAwareKDFMinimum:settings = get_sqlcipher_settings()assert settings["kdf_iterations"] == 1000+ def test_falsey_test_mode_does_not_relax_kdf(self):+ """LDR_TEST_MODE is parsed as a boolean: an explicit '0'/'false'+ must NOT relax the KDF floor (a bare truthiness check would treat+ the non-empty string 'false' as enabled and silently weaken+ encryption). The low requested value must clamp to the default.+ """+ from local_deep_research.database.sqlcipher_utils import (+ get_sqlcipher_settings,+ DEFAULT_KDF_ITERATIONS,+ )++ for falsey in ("0", "false", "no", "off"):+ with patch.dict(+ os.environ,+ {"LDR_DB_KDF_ITERATIONS": "1000", "LDR_TEST_MODE": falsey},+ clear=True,+ ):+ settings = get_sqlcipher_settings()+ assert settings["kdf_iterations"] == DEFAULT_KDF_ITERATIONS, (+ f"LDR_TEST_MODE={falsey!r} should not relax the KDF floor"+ )+class TestCipherMemorySecurityEnvVar:"""Tests for configurable cipher_memory_security."""