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: address AI code review recommendations for security headers

LearningCircuitf62289c85494
diff --git a/src/local_deep_research/security/__init__.py b/src/local_deep_research/security/__init__.py
index a2d71c3c28..f7cfe103a9 100644
--- a/src/local_deep_research/security/__init__.py
+++ b/src/local_deep_research/security/__init__.py
@@ -1,6 +1,13 @@
"""Security utilities for Local Deep Research."""
+from .file_write_verifier import FileWriteVerifier
from .path_validator import PathValidator
from .security_headers import SecurityHeaders
+from .url_validator import URLValidator
-__all__ = ["PathValidator", "SecurityHeaders"]
+__all__ = [
+ "FileWriteVerifier",
+ "PathValidator",
+ "SecurityHeaders",
+ "URLValidator",
+]
diff --git a/src/local_deep_research/security/security_headers.py b/src/local_deep_research/security/security_headers.py
index 92cb20180a..46763f5b4b 100644
--- a/src/local_deep_research/security/security_headers.py
+++ b/src/local_deep_research/security/security_headers.py
@@ -26,7 +26,7 @@ class SecurityHeaders:
"""Initialize security headers middleware.
Args:
- app: Flask application instance (optional, can call init_app later)
+ app (Optional[Flask]): Flask application instance (optional, can call init_app later)
"""
if app is not None:
self.init_app(app)
@@ -209,6 +209,19 @@ class SecurityHeaders:
"Set SECURITY_CORS_ALLOWED_ORIGINS to a specific origin or disable credentials."
)
+ # Validate origin format for non-wildcard origins
+ if allowed_origins != "*":
+ origins_list = [
+ origin.strip() for origin in allowed_origins.split(",")
+ ]
+ for origin in origins_list:
+ if not origin.startswith(("http://", "https://")):
+ raise ValueError(
+ f"CORS misconfiguration: Invalid origin format '{origin}'. "
+ f"Origins must start with 'http://' or 'https://'. "
+ f"Example: 'https://example.com'"
+ )
+
# Log info about multi-origin + credentials configuration
if allow_credentials and "," in allowed_origins:
logger.info(
@@ -241,10 +254,13 @@ class SecurityHeaders:
# Determine which origin to send back
origin_to_send = configured_origins
+ request_origin = request.headers.get("Origin")
+ # If wildcard, allow all origins
+ if configured_origins == "*":
+ origin_to_send = "*"
# If multiple origins configured (comma-separated), use origin reflection
- if "," in configured_origins:
- request_origin = request.headers.get("Origin")
+ elif "," in configured_origins:
# Parse configured origins into a set
allowed_origins_set = {
origin.strip() for origin in configured_origins.split(",")
@@ -260,6 +276,16 @@ class SecurityHeaders:
f"Allowed origins: {configured_origins}"
)
return response
+ # Single origin configured - validate request origin matches
+ else:
+ # For single origin, verify request origin matches before setting CORS headers
+ if request_origin and request_origin != configured_origins:
+ logger.warning(
+ f"CORS request from non-matching origin: {request_origin}. "
+ f"Configured origin: {configured_origins}"
+ )
+ return response
+ origin_to_send = configured_origins
response.headers["Access-Control-Allow-Origin"] = origin_to_send
response.headers["Access-Control-Allow-Methods"] = (
diff --git a/src/local_deep_research/web/app_factory.py b/src/local_deep_research/web/app_factory.py
index d967407e2d..4dd778ab15 100644
--- a/src/local_deep_research/web/app_factory.py
+++ b/src/local_deep_research/web/app_factory.py
@@ -318,10 +318,6 @@ def apply_middleware(app):
finally:
g.db_session = None
- # Security headers are now handled by SecurityHeaders middleware
- # See: local_deep_research.security.security_headers
- # Initialized above with SecurityHeaders(app)
-
# Add a middleware layer to handle abrupt disconnections
@app.before_request
def handle_websocket_requests():