~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
security: reject unknown files in integrity check (fail closed) (#4939)
LearningCircuit9ff8f09f13fc
diff --git a/src/local_deep_research/security/file_integrity/integrity_manager.py b/src/local_deep_research/security/file_integrity/integrity_manager.pyindex b80d4d059b..da721f8c1c 100644--- a/src/local_deep_research/security/file_integrity/integrity_manager.py+++ b/src/local_deep_research/security/file_integrity/integrity_manager.py@@ -26,6 +26,13 @@ except ImportError:get_user_db_session = None # type: ignore+# Reason returned by verify_file when a file has no integrity record. Unknown+# files are rejected (fail closed) rather than auto-registered, to avoid a+# trust-on-first-use gap where deleted records or newly injected files would+# otherwise bypass integrity verification.+NO_INTEGRITY_RECORD = "no_integrity_record"++class FileIntegrityManager:"""Central service for file integrity verification.@@ -202,15 +209,10 @@ class FileIntegrityManager:)if not record:- logger.warning(- f"[FILE_INTEGRITY] No record found for {file_path}, creating one"+ logger.error(+ f"[FILE_INTEGRITY] No integrity record found for {file_path}, refusing to load")- try:- self.record_file(file_path)- return True, None- except Exception as e:- logger.exception("[FILE_INTEGRITY] Failed to create record")- return False, f"Failed to create integrity record: {str(e)}"+ return False, NO_INTEGRITY_RECORD# Check if verification neededif not force and not self._needs_verification(record, file_path):diff --git a/tests/security/test_file_integrity_manager_coverage.py b/tests/security/test_file_integrity_manager_coverage.pyindex d8deb0d188..a89bf69678 100644--- a/tests/security/test_file_integrity_manager_coverage.py+++ b/tests/security/test_file_integrity_manager_coverage.py@@ -649,7 +649,10 @@ class TestRecordFile:class TestVerifyFile:- def test_no_record_creates_one(self, integrity_manager):+ def test_no_record_rejects_file(self, integrity_manager):+ # Reject-unknown: a file with no integrity record must fail closed+ # rather than being auto-registered (trust-on-first-use gap). The+ # security property is that record_file is NOT called on this path.mgr, session = integrity_managerv = _make_verifier(checksum="cs")mgr.register_verifier(v)@@ -658,31 +661,36 @@ class TestVerifyFile:path.resolve.return_value = Path("/resolved/path")path.stat.return_value.st_size = 100path.stat.return_value.st_mtime = 500.0- # First query returns no record, triggering record_file+ # No record found -> must be rejected, not auto-createdsession.query.return_value.filter_by.return_value.first.return_value = (None)- passed, reason = mgr.verify_file(path)+ with patch.object(mgr, "record_file") as mock_record:+ passed, reason = mgr.verify_file(path)- assert passed is True- assert reason is None+ assert passed is False+ assert reason == "no_integrity_record"+ mock_record.assert_not_called()- def test_no_record_create_fails(self, integrity_manager):+ def test_no_record_rejects_even_without_verifier(self, integrity_manager):+ # Rejection happens before any verifier lookup, so a missing record+ # is rejected identically whether or not a verifier is registered.mgr, session = integrity_managerpath = MagicMock(spec=Path)path.exists.return_value = Truepath.resolve.return_value = Path("/resolved/path")- # No record found+ # No record found, no verifiers registeredsession.query.return_value.filter_by.return_value.first.return_value = (None)- # No verifiers -> record_file will raise ValueError- passed, reason = mgr.verify_file(path)+ with patch.object(mgr, "record_file") as mock_record:+ passed, reason = mgr.verify_file(path)assert passed is False- assert "Failed to create integrity record" in reason+ assert reason == "no_integrity_record"+ mock_record.assert_not_called()def test_skips_if_unchanged(self, integrity_manager):mgr, session = integrity_manager