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: Implement targeted CSRF exemptions for API endpoints (#420)

LearningCircuitc5a33146a55a
diff --git a/src/local_deep_research/web/api.py b/src/local_deep_research/web/api.py
index bf417355ca..b3d36c78f3 100644
--- a/src/local_deep_research/web/api.py
+++ b/src/local_deep_research/web/api.py
@@ -8,7 +8,6 @@ import time
from functools import wraps
from flask import Blueprint, jsonify, request
-from flask_wtf.csrf import csrf_exempt
from ..api.research_functions import analyze_documents
from .services.settings_service import get_setting
@@ -72,7 +71,6 @@ def api_access_control(f):
@api_blueprint.route("/", methods=["GET"])
-@csrf_exempt
@api_access_control
def api_documentation():
"""
@@ -124,7 +122,6 @@ def api_documentation():
@api_blueprint.route("/health", methods=["GET"])
-@csrf_exempt
def health_check():
"""Simple health check endpoint."""
return jsonify(
diff --git a/src/local_deep_research/web/app_factory.py b/src/local_deep_research/web/app_factory.py
index 74594ece7e..44f29e8e23 100644
--- a/src/local_deep_research/web/app_factory.py
+++ b/src/local_deep_research/web/app_factory.py
@@ -51,11 +51,10 @@ def create_app():
# App configuration
app.config["SECRET_KEY"] = "deep-research-secret-key"
- # Temporarily disable CSRF for API testing
- app.config["WTF_CSRF_ENABLED"] = False
-
- # Initialize CSRF protection (disabled)
- CSRFProtect(app)
+ # Initialize CSRF protection
+ csrf = CSRFProtect(app)
+ # Exempt Socket.IO from CSRF protection
+ csrf.exempt("research.socket_io")
# Database configuration - Use unified ldr.db from the database module
db_path = DB_PATH
@@ -188,8 +187,11 @@ def register_blueprints(app):
csrf = app.extensions["csrf"]
# Exempt the API blueprint routes by actual endpoints
csrf.exempt("api_v1")
+ csrf.exempt("api")
for rule in app.url_map.iter_rules():
- if rule.endpoint.startswith("api_v1."):
+ if rule.endpoint and (
+ rule.endpoint.startswith("api_v1.") or rule.endpoint.startswith("api.")
+ ):
csrf.exempt(rule.endpoint)
# Add favicon route