~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: Remove unnecessary in-memory encryption for credentials (issue #… (#618)
LearningCircuita071d38392cc
diff --git a/src/local_deep_research/database/encrypted_store_base.py b/src/local_deep_research/database/credential_store_base.pysimilarity index 67%rename from src/local_deep_research/database/encrypted_store_base.pyrename to src/local_deep_research/database/credential_store_base.pyindex 8f7cb57f2d..8d4062886d 100644--- a/src/local_deep_research/database/encrypted_store_base.py+++ b/src/local_deep_research/database/credential_store_base.py@@ -1,6 +1,11 @@"""-Base class for encrypted credential storage.-Provides common functionality for storing encrypted credentials with TTL.+Base class for credential storage with TTL.+Provides common functionality for storing credentials with TTL expiration.++NOTE: Credentials are stored in plain text in memory. The encryption+functionality was removed as it provided no real security benefit -+if an attacker can read process memory, they have sufficient privileges+to bypass any protections anyway."""import time@@ -8,18 +13,16 @@ from abc import ABC, abstractmethodfrom threading import Lockfrom typing import Dict, Optional, Tuple-from cryptography.fernet import Fernet-from loguru import logger--class EncryptedStoreBase(ABC):+class CredentialStoreBase(ABC):"""- Base class for storing encrypted credentials with expiration.+ Base class for storing credentials with expiration.+ Credentials are stored in plain text in memory with TTL-based expiration."""def __init__(self, ttl_seconds: int):"""- Initialize the encrypted store.+ Initialize the store.Args:ttl_seconds: How long to keep data before expiration@@ -27,36 +30,31 @@ class EncryptedStoreBase(ABC):self.ttl = ttl_secondsself._store: Dict[str, Dict] = {}self._lock = Lock()- self._master_key = Fernet.generate_key()- self._cipher = Fernet(self._master_key)- def _store_encrypted(self, key: str, data: Dict[str, str]) -> None:+ def _store_credentials(self, key: str, data: Dict[str, str]) -> None:"""- Store encrypted data with expiration.+ Store credentials with expiration.Args:key: Storage keydata: Dictionary with 'username' and 'password'"""with self._lock:- # Encrypt password- encrypted_password = self._cipher.encrypt(data["password"].encode())-- # Store with expiration+ # Store with expiration (plain text)self._store[key] = {"username": data["username"],- "encrypted_password": encrypted_password,+ "password": data["password"],"expires_at": time.time() + self.ttl,}# Clean up expired entriesself._cleanup_expired()- def _retrieve_encrypted(+ def _retrieve_credentials(self, key: str, remove: bool = False) -> Optional[Tuple[str, str]]:"""- Retrieve encrypted data.+ Retrieve stored credentials.Args:key: Storage key@@ -78,19 +76,13 @@ class EncryptedStoreBase(ABC):# Get datausername = entry["username"]- encrypted_password = entry["encrypted_password"]+ password = entry["password"]# Remove if requestedif remove:del self._store[key]- # Decrypt password- try:- password = self._cipher.decrypt(encrypted_password).decode()- return username, password- except Exception:- logger.exception("Failed to decrypt stored data")- return None+ return username, passworddef _cleanup_expired(self):"""Remove expired entries."""diff --git a/src/local_deep_research/database/session_passwords.py b/src/local_deep_research/database/session_passwords.pyindex 8cef7251f1..e2b7271769 100644--- a/src/local_deep_research/database/session_passwords.py+++ b/src/local_deep_research/database/session_passwords.py@@ -7,7 +7,8 @@ to access encrypted databases for metrics writing.SECURITY NOTES:1. Passwords are only stored in memory, never on disk-2. Passwords are encrypted while in memory+2. Passwords are stored in plain text in memory (encryption removed as it+ provided no real security benefit - see issue #593)3. Passwords are automatically cleared on logout4. This is only used for metrics/logging, not user data access"""@@ -16,10 +17,10 @@ from typing import Optionalfrom loguru import logger-from .encrypted_store_base import EncryptedStoreBase+from .credential_store_base import CredentialStoreBase-class SessionPasswordStore(EncryptedStoreBase):+class SessionPasswordStore(CredentialStoreBase):"""Stores passwords temporarily for active sessions.Used to allow background threads to write metrics to encrypted databases.@@ -46,7 +47,9 @@ class SessionPasswordStore(EncryptedStoreBase):password: The password to store"""key = f"{username}:{session_id}"- self._store_encrypted(key, {"username": username, "password": password})+ self._store_credentials(+ key, {"username": username, "password": password}+ )logger.debug(f"Stored session password for {username}")def get_session_password(@@ -63,7 +66,7 @@ class SessionPasswordStore(EncryptedStoreBase):The decrypted password or None if not found/expired"""key = f"{username}:{session_id}"- result = self._retrieve_encrypted(key, remove=False)+ result = self._retrieve_credentials(key, remove=False)return result[1] if result else Nonedef clear_session(self, username: str, session_id: str) -> None:diff --git a/src/local_deep_research/database/temp_auth.py b/src/local_deep_research/database/temp_auth.pyindex fd98eeaef5..637141b317 100644--- a/src/local_deep_research/database/temp_auth.py+++ b/src/local_deep_research/database/temp_auth.py@@ -1,6 +1,8 @@"""Temporary authentication storage for handling post-registration flow.-Stores encrypted passwords briefly to allow database access after redirect.+Stores passwords briefly in memory to allow database access after redirect.+Note: Passwords are stored in plain text in memory (encryption removed as it+provided no real security benefit - see issue #593)."""import secrets@@ -8,13 +10,13 @@ from typing import Optional, Tuplefrom loguru import logger-from .encrypted_store_base import EncryptedStoreBase+from .credential_store_base import CredentialStoreBase-class TemporaryAuthStore(EncryptedStoreBase):+class TemporaryAuthStore(CredentialStoreBase):"""Stores authentication temporarily for post-registration/login flow.- Passwords are encrypted in memory and expire after a short time.+ Passwords are stored in plain text in memory and expire after a short time."""def __init__(self, ttl_seconds: int = 30):@@ -38,7 +40,7 @@ class TemporaryAuthStore(EncryptedStoreBase):Token to retrieve the auth data"""token = secrets.token_urlsafe(32)- self._store_encrypted(+ self._store_credentials(token, {"username": username, "password": password})logger.debug(f"Stored temporary auth for {username}")@@ -54,7 +56,7 @@ class TemporaryAuthStore(EncryptedStoreBase):Returns:Tuple of (username, password) or None if expired/not found"""- result = self._retrieve_encrypted(token, remove=True)+ result = self._retrieve_credentials(token, remove=True)if result:logger.debug(f"Retrieved temporary auth for {result[0]}")return result@@ -69,7 +71,7 @@ class TemporaryAuthStore(EncryptedStoreBase):Returns:Tuple of (username, password) or None if expired/not found"""- return self._retrieve_encrypted(token, remove=False)+ return self._retrieve_credentials(token, remove=False)# Implement abstract methods for compatibilitydef store(self, username: str, password: str) -> str:diff --git a/tests/auth_tests/test_inmemory_storage.py b/tests/auth_tests/test_inmemory_storage.pynew file mode 100644index 0000000000..36b464f188--- /dev/null+++ b/tests/auth_tests/test_inmemory_storage.py@@ -0,0 +1,223 @@+#!/usr/bin/env python3+"""Test in-memory storage after encryption removal (issue #593)."""++import time++from local_deep_research.database.session_passwords import (+ session_password_store,+)+from local_deep_research.database.temp_auth import temp_auth_store+++class TestSessionPasswordStore:+ """Test session password storage without encryption."""++ def test_store_and_retrieve_password(self):+ """Test storing and retrieving a password."""+ username = "test_user"+ session_id = "test_session_123"+ password = "test_password_456"++ # Store password+ session_password_store.store_session_password(+ username, session_id, password+ )++ # Retrieve password+ retrieved = session_password_store.get_session_password(+ username, session_id+ )+ assert retrieved == password++ def test_wrong_session_returns_none(self):+ """Test that wrong session ID returns None."""+ username = "test_user"+ session_id = "test_session_123"+ password = "test_password_456"++ session_password_store.store_session_password(+ username, session_id, password+ )++ # Try with wrong session+ wrong_retrieved = session_password_store.get_session_password(+ username, "wrong_session"+ )+ assert wrong_retrieved is None++ def test_clear_session(self):+ """Test clearing a session."""+ username = "test_user"+ session_id = "test_session_123"+ password = "test_password_456"++ session_password_store.store_session_password(+ username, session_id, password+ )++ # Clear session+ session_password_store.clear_session(username, session_id)++ # Should return None after clearing+ cleared_retrieved = session_password_store.get_session_password(+ username, session_id+ )+ assert cleared_retrieved is None++ def test_plain_text_storage(self):+ """Test that passwords are stored in plain text internally."""+ username = "internal_test"+ session_id = "internal_session"+ password = "plain_text_password"++ key = f"{username}:{session_id}"+ session_password_store._store_credentials(+ key, {"username": username, "password": password}+ )++ # Check internal storage directly+ with session_password_store._lock:+ stored_entry = session_password_store._store.get(key)+ assert stored_entry is not None+ assert "password" in stored_entry+ assert stored_entry["password"] == password+ assert "encrypted_password" not in stored_entry++ # Clean up+ session_password_store.clear_entry(key)+++class TestTemporaryAuthStore:+ """Test temporary auth storage without encryption."""++ def test_store_and_retrieve_auth(self):+ """Test storing and retrieving authentication."""+ username = "test_user"+ password = "test_password_789"++ # Store auth+ token = temp_auth_store.store_auth(username, password)+ assert token is not None++ # Retrieve auth (removes it)+ retrieved = temp_auth_store.retrieve_auth(token)+ assert retrieved == (username, password)++ # Should be None after retrieval+ retrieved_again = temp_auth_store.retrieve_auth(token)+ assert retrieved_again is None++ def test_peek_auth(self):+ """Test peeking at auth without removing it."""+ username = "test_user"+ password = "test_password_789"++ token = temp_auth_store.store_auth(username, password)++ # Peek at auth (doesn't remove)+ peeked = temp_auth_store.peek_auth(token)+ assert peeked == (username, password)++ # Should still be there+ peeked_again = temp_auth_store.peek_auth(token)+ assert peeked_again == (username, password)++ # Clean up+ temp_auth_store.retrieve_auth(token)++ def test_expiration(self):+ """Test that auth expires after TTL."""+ username = "test_user"+ password = "test_password_789"++ # Store original TTL+ original_ttl = temp_auth_store.ttl++ try:+ # Set very short TTL+ temp_auth_store.ttl = 1 # 1 second++ token = temp_auth_store.store_auth(username, password)++ # Wait for expiration+ time.sleep(2)++ # Should be expired+ expired = temp_auth_store.peek_auth(token)+ assert expired is None++ finally:+ # Restore original TTL+ temp_auth_store.ttl = original_ttl++ def test_plain_text_storage(self):+ """Test that auth is stored in plain text internally."""+ username = "internal_test"+ password = "plain_text_password"++ token = "test_token_123"+ temp_auth_store._store_credentials(+ token, {"username": username, "password": password}+ )++ # Check internal storage directly+ with temp_auth_store._lock:+ stored_entry = temp_auth_store._store.get(token)+ assert stored_entry is not None+ assert "password" in stored_entry+ assert stored_entry["password"] == password+ assert "encrypted_password" not in stored_entry++ # Clean up+ temp_auth_store.clear_entry(token)+++class TestEncryptionRemoval:+ """Test that encryption has been properly removed."""++ def test_no_cryptography_import(self):+ """Test that cryptography is not imported in the base class."""+ import local_deep_research.database.credential_store_base as store_base++ # Check that Fernet is not in the module+ assert not hasattr(store_base, "Fernet")++ # Check that cipher attributes don't exist+ test_store = session_password_store+ assert not hasattr(test_store, "_cipher")+ assert not hasattr(test_store, "_master_key")++ def test_storage_format_consistency(self):+ """Test that all stores use the same plain text format."""+ # Test data+ username = "consistency_test"+ password = "test_password"++ # Session password store+ session_key = f"{username}:session_123"+ session_password_store._store_credentials(+ session_key, {"username": username, "password": password}+ )++ # Temp auth store+ auth_token = "auth_token_123"+ temp_auth_store._store_credentials(+ auth_token, {"username": username, "password": password}+ )++ # Check both have same structure+ with session_password_store._lock:+ session_entry = session_password_store._store.get(session_key)+ assert session_entry["password"] == password+ assert "username" in session_entry+ assert "expires_at" in session_entry++ with temp_auth_store._lock:+ auth_entry = temp_auth_store._store.get(auth_token)+ assert auth_entry["password"] == password+ assert "username" in auth_entry+ assert "expires_at" in auth_entry++ # Clean up+ session_password_store.clear_entry(session_key)+ temp_auth_store.clear_entry(auth_token)