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: eliminate reflected XSS vectors in delete route validation (CodeQL #7584-7587) (#3316)

LearningCircuit9a2686434361
diff --git a/src/local_deep_research/research_library/deletion/routes/delete_routes.py b/src/local_deep_research/research_library/deletion/routes/delete_routes.py
index 1909f6573f..49d007fd90 100644
--- a/src/local_deep_research/research_library/deletion/routes/delete_routes.py
+++ b/src/local_deep_research/research_library/deletion/routes/delete_routes.py
@@ -27,38 +27,31 @@ delete_bp = Blueprint("delete", __name__, url_prefix="/library/api")
# if the decorator is ever removed.
-def _validate_document_ids():
+class _ValidationError(Exception):
+ """Raised when request validation fails."""
+
+ def __init__(self, message: str):
+ self.message = message
+
+
+def _validate_document_ids() -> list:
"""Extract and validate document_ids from the JSON request body.
Returns:
- tuple: (document_ids, error_response) where error_response is None
- on success, or a (jsonify(...), status_code) tuple on failure.
+ list: The validated document IDs.
+
+ Raises:
+ _ValidationError: If the request body is missing or invalid.
"""
data = request.get_json()
if not data or "document_ids" not in data:
- return None, (
- jsonify(
- {
- "success": False,
- "error": "document_ids required in request body",
- }
- ),
- 400,
- )
+ raise _ValidationError("document_ids required in request body")
document_ids = data["document_ids"]
if not isinstance(document_ids, list) or not document_ids:
- return None, (
- jsonify(
- {
- "success": False,
- "error": "document_ids must be a non-empty list",
- }
- ),
- 400,
- )
+ raise _ValidationError("document_ids must be a non-empty list")
- return document_ids, None
+ return document_ids
# =============================================================================
@@ -276,16 +269,15 @@ def delete_documents_bulk():
JSON with bulk deletion results
"""
try:
- document_ids, error = _validate_document_ids()
- if error:
- return error
-
+ document_ids = _validate_document_ids()
username = session["username"]
service = BulkDeletionService(username)
result = service.delete_documents(document_ids)
return jsonify({"success": True, **result})
+ except _ValidationError as e:
+ return jsonify({"success": False, "error": e.message}), 400
except Exception as e:
return handle_api_error("bulk deleting documents", e)
@@ -306,16 +298,15 @@ def delete_documents_blobs_bulk():
JSON with bulk blob deletion results
"""
try:
- document_ids, error = _validate_document_ids()
- if error:
- return error
-
+ document_ids = _validate_document_ids()
username = session["username"]
service = BulkDeletionService(username)
result = service.delete_blobs(document_ids)
return jsonify({"success": True, **result})
+ except _ValidationError as e:
+ return jsonify({"success": False, "error": e.message}), 400
except Exception as e:
return handle_api_error("bulk deleting blobs", e)
@@ -337,10 +328,7 @@ def remove_documents_from_collection_bulk(collection_id):
JSON with bulk removal results
"""
try:
- document_ids, error = _validate_document_ids()
- if error:
- return error
-
+ document_ids = _validate_document_ids()
username = session["username"]
service = BulkDeletionService(username)
result = service.remove_documents_from_collection(
@@ -349,6 +337,8 @@ def remove_documents_from_collection_bulk(collection_id):
return jsonify({"success": True, **result})
+ except _ValidationError as e:
+ return jsonify({"success": False, "error": e.message}), 400
except Exception as e:
return handle_api_error("bulk removing documents from collection", e)
@@ -369,10 +359,7 @@ def get_bulk_deletion_preview():
JSON with preview information
"""
try:
- document_ids, error = _validate_document_ids()
- if error:
- return error
-
+ document_ids = _validate_document_ids()
data = request.get_json()
operation = data.get("operation", "delete")
@@ -382,5 +369,7 @@ def get_bulk_deletion_preview():
return jsonify({"success": True, **result})
+ except _ValidationError as e:
+ return jsonify({"success": False, "error": e.message}), 400
except Exception as e:
return handle_api_error("getting bulk preview", e)