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.

refactor: address code review feedback from djpetti

LearningCircuitcc2a4009d4cd
diff --git a/src/local_deep_research/security/ssrf_validator.py b/src/local_deep_research/security/ssrf_validator.py
index 5ab79308bc..1fb62d3852 100644
--- a/src/local_deep_research/security/ssrf_validator.py
+++ b/src/local_deep_research/security/ssrf_validator.py
@@ -6,12 +6,15 @@ by blocking requests to internal/private networks and enforcing safe schemes.
"""
import ipaddress
-import os
import socket
from urllib.parse import urlparse
from typing import Optional
from loguru import logger
+from ..settings.env_definitions.testing import TESTING
+from ..settings.env_definitions.security import PYTEST_CURRENT_TEST
+from ..settings.env_registry import registry
+
# Blocked IP ranges (RFC1918 private networks, localhost, link-local, etc.)
# nosec B104 - These hardcoded IPs are intentional for SSRF prevention (blocking private networks)
@@ -85,14 +88,13 @@ def validate_url(url: str, allow_redirects: bool = True) -> bool:
SSRF validation can be disabled for testing by setting environment variables:
- TESTING=true
- PYTEST_CURRENT_TEST (automatically set by pytest)
- - DISABLE_SSRF_CHECK=true
+ - LDR_SECURITY_SSRF_DISABLE_VALIDATION=true
"""
# Bypass SSRF validation in test mode
- if (
- os.getenv("TESTING") == "true"
- or os.getenv("PYTEST_CURRENT_TEST")
- or os.getenv("DISABLE_SSRF_CHECK") == "true"
- ):
+ disable_ssrf = registry.get_env_setting(
+ "security.ssrf.disable_validation", default=False
+ )
+ if TESTING or PYTEST_CURRENT_TEST or disable_ssrf:
logger.debug(f"SSRF validation bypassed in test mode for URL: {url}")
return True
diff --git a/src/local_deep_research/settings/env_definitions/__init__.py b/src/local_deep_research/settings/env_definitions/__init__.py
index d29f4ad726..f1a0f56848 100644
--- a/src/local_deep_research/settings/env_definitions/__init__.py
+++ b/src/local_deep_research/settings/env_definitions/__init__.py
@@ -6,6 +6,7 @@ from .testing import TESTING_SETTINGS
from .bootstrap import BOOTSTRAP_SETTINGS
from .db_config import DB_CONFIG_SETTINGS
from .news_scheduler import NEWS_SCHEDULER_SETTINGS
+from .security import SECURITY_SETTINGS
# Combine all settings for easy access
ALL_SETTINGS = {
@@ -13,6 +14,7 @@ ALL_SETTINGS = {
"bootstrap": BOOTSTRAP_SETTINGS,
"db_config": DB_CONFIG_SETTINGS,
"news_scheduler": NEWS_SCHEDULER_SETTINGS,
+ "security": SECURITY_SETTINGS,
}
__all__ = [
@@ -20,5 +22,6 @@ __all__ = [
"BOOTSTRAP_SETTINGS",
"DB_CONFIG_SETTINGS",
"NEWS_SCHEDULER_SETTINGS",
+ "SECURITY_SETTINGS",
"ALL_SETTINGS",
]
diff --git a/src/local_deep_research/settings/env_definitions/security.py b/src/local_deep_research/settings/env_definitions/security.py
new file mode 100644
index 0000000000..5a27d0dc0f
--- /dev/null
+++ b/src/local_deep_research/settings/env_definitions/security.py
@@ -0,0 +1,23 @@
+"""
+Security environment settings.
+
+These settings control security-related behavior like SSRF validation.
+"""
+
+import os
+from ..env_settings import BooleanSetting
+
+
+# External environment variables (set by pytest, CI systems)
+# These are read directly since we don't control them
+PYTEST_CURRENT_TEST = os.environ.get("PYTEST_CURRENT_TEST")
+
+
+# LDR Security settings (our application's security configuration)
+SECURITY_SETTINGS = [
+ BooleanSetting(
+ key="security.ssrf.disable_validation", # gitleaks:allow
+ description="Disable SSRF validation (test/dev only - NEVER in production)",
+ default=False,
+ ),
+]
diff --git a/src/local_deep_research/web/services/research_service.py b/src/local_deep_research/web/services/research_service.py
index e095bfa3d7..c31bd1970a 100644
--- a/src/local_deep_research/web/services/research_service.py
+++ b/src/local_deep_research/web/services/research_service.py
@@ -1575,40 +1575,6 @@ def run_research_process(
# NOTE: Database updates from threads are handled by queue processor
# The queue_processor.queue_error_update() method is already being used below
# to safely update the database from the main thread
- """
- # DEPRECATED: Direct database updates from background threads
- # Get the start time from the database
- duration_seconds = None
- with get_user_db_session(username) as db_session:
- research = (
- db_session.query(ResearchHistory)
- .filter_by(id=research_id)
- .first()
- )
- assert research is not None, "Research not in database"
-
- duration_seconds = calculate_duration(research.created_at)
-
- with get_user_db_session(username) as db_session:
- research = (
- db_session.query(ResearchHistory)
- .filter_by(id=research_id)
- .first()
- )
- assert research is not None, "Research not in database"
-
- # Update the ResearchHistory object with the new status and completion time
- research.status = status
- research.completed_at = completed_at
- research.duration_seconds = duration_seconds
- research.research_meta = metadata
-
- # Add error report path if available
- if "report_path_to_save" in locals() and report_path_to_save:
- research.report_path = report_path_to_save
-
- db_session.commit()
- """
# Queue the error update to be processed in main thread
# Using the queue processor v2 system
@@ -1683,46 +1649,6 @@ def cleanup_research_resources(
# NOTE: Queue processor already handles database updates from the main thread
# The notify_research_completed() method is called at the end of this function
# which safely updates the database status
- """
- # DEPRECATED: Direct database access from background threads
- try:
- with get_user_db_session(username) as db_session:
- research = (
- db_session.query(ResearchHistory)
- .filter(ResearchHistory.id == research_id)
- .first()
- )
- if research:
- current_status = research.status
- else:
- logger.error("Research with ID %s not found", research_id)
-
- # Clean up UserActiveResearch record
- if username:
- from ...database.models import UserActiveResearch
-
- active_record = (
- db_session.query(UserActiveResearch)
- .filter_by(username=username, research_id=research_id)
- .first()
- )
- if active_record:
- logger.info(
- f"Cleaning up active research {research_id} for user {username} (was started at {active_record.started_at})"
- )
- db_session.delete(active_record)
- db_session.commit()
- logger.info(
- f"Cleaned up active research record for user {username}"
- )
- else:
- logger.warning(
- f"No active research record found to clean up for {research_id} / {username}"
- )
-
- except Exception:
- logger.exception("Error retrieving research status during cleanup")
- """
# Notify queue processor that research completed
# This uses processor_v2 which handles database updates in the main thread