~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(collections): validate identity field types (#5459)
Ziyang Guoe5b2eef2b25d
diff --git a/changelog.d/+collection-identity-type-validation.bugfix.md b/changelog.d/+collection-identity-type-validation.bugfix.mdnew file mode 100644index 0000000000..eae0ecdde8--- /dev/null+++ b/changelog.d/+collection-identity-type-validation.bugfix.md@@ -0,0 +1 @@+Reject non-string collection names and descriptions with a 400 response instead of returning an internal server error.diff --git a/src/local_deep_research/research_library/routes/rag_routes.py b/src/local_deep_research/research_library/routes/rag_routes.pyindex 0dbe7ca982..d500b78d7c 100644--- a/src/local_deep_research/research_library/routes/rag_routes.py+++ b/src/local_deep_research/research_library/routes/rag_routes.py@@ -1392,6 +1392,17 @@ def get_documents():# Collection Management Routes+def _parse_collection_identity_fields(data):+ """Normalize collection identity fields after validating JSON types."""+ values = {}+ for field in ("name", "description"):+ value = data.get(field, "")+ if not isinstance(value, str):+ return None, None, field+ values[field] = value.strip()+ return values["name"], values["description"], None++@rag_bp.route("/api/collections", methods=["GET"])@login_requireddef get_collections():@@ -1488,8 +1499,16 @@ def create_collection():try:data = request.get_json()- name = data.get("name", "").strip()- description = data.get("description", "").strip()+ name, description, invalid_field = _parse_collection_identity_fields(+ data+ )+ if invalid_field is not None:+ return jsonify(+ {+ "success": False,+ "error": f"Collection {invalid_field} must be a string",+ }+ ), 400collection_type = data.get("type", "user_uploads")if not isinstance(collection_type, str):return jsonify(@@ -1584,8 +1603,16 @@ def update_collection(collection_id):try:data = request.get_json()- name = data.get("name", "").strip()- description = data.get("description", "").strip()+ name, description, invalid_field = _parse_collection_identity_fields(+ data+ )+ if invalid_field is not None:+ return jsonify(+ {+ "success": False,+ "error": f"Collection {invalid_field} must be a string",+ }+ ), 400username = session["username"]with get_user_db_session(username) as db_session:diff --git a/tests/api_tests/test_collections_api.py b/tests/api_tests/test_collections_api.pyindex 8a46c49aa8..1a1f8f04fa 100644--- a/tests/api_tests/test_collections_api.py+++ b/tests/api_tests/test_collections_api.py@@ -10,6 +10,8 @@ Tests the following endpoints:import uuid+import pytest+# Import helpers from conftestfrom .conftest import delete_test_collection@@ -195,6 +197,34 @@ class TestCreateCollection:assert response.status_code == 400+ @pytest.mark.parametrize(+ ("field", "invalid_value"),+ [+ ("name", []),+ ("name", {}),+ ("description", []),+ ("description", {}),+ ],+ )+ def test_create_collection_rejects_non_string_identity_fields(+ self, authenticated_client, field, invalid_value+ ):+ """Malformed identity fields return 400 instead of raising."""+ payload = {"name": f"Invalid {uuid.uuid4().hex[:8]}"}+ payload[field] = invalid_value++ response = authenticated_client.post(+ "/library/api/collections",+ json=payload,+ content_type="application/json",+ )++ assert response.status_code == 400+ data = response.get_json()+ assert data["success"] is False+ assert field in data["error"].lower()+ assert "must be a string" in data["error"].lower()+def test_create_collection_duplicate_name(self, authenticated_client):"""Rejects collection with duplicate name."""unique_name = f"Duplicate Test {uuid.uuid4().hex[:8]}"@@ -296,6 +326,38 @@ class TestUpdateCollection:assert data["success"] is Trueassert data["collection"]["description"] == "Updated description"+ @pytest.mark.parametrize(+ ("field", "invalid_value"),+ [+ ("name", []),+ ("name", {}),+ ("description", []),+ ("description", {}),+ ],+ )+ def test_update_collection_rejects_non_string_identity_fields(+ self,+ authenticated_client,+ create_collection_helper,+ field,+ invalid_value,+ ):+ """Malformed identity fields return 400 instead of raising."""+ created = create_collection_helper()+ assert created is not None++ response = authenticated_client.put(+ f"/library/api/collections/{created['id']}",+ json={field: invalid_value},+ content_type="application/json",+ )++ assert response.status_code == 400+ data = response.get_json()+ assert data["success"] is False+ assert field in data["error"].lower()+ assert "must be a string" in data["error"].lower()+def test_update_collection_not_found(self, authenticated_client):"""Returns 404 for non-existent collection."""fake_id = str(uuid.uuid4())