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(routes): validate days param on /api/rate-limiting/cleanup (#4722)

LearningCircuit9303ccea3dec
diff --git a/changelog.d/3805.bugfix.md b/changelog.d/3805.bugfix.md
new file mode 100644
index 0000000000..a07c228c8f
--- /dev/null
+++ b/changelog.d/3805.bugfix.md
@@ -0,0 +1 @@
+The `/api/rate-limiting/cleanup` endpoint now rejects out-of-range or non-integer `days` values with HTTP 400 instead of passing them through to the destructive bulk delete (clamped to `1 <= days <= 365`).
diff --git a/src/local_deep_research/web/routes/settings_routes.py b/src/local_deep_research/web/routes/settings_routes.py
index 25ef2c7e67..7585288646 100644
--- a/src/local_deep_research/web/routes/settings_routes.py
+++ b/src/local_deep_research/web/routes/settings_routes.py
@@ -2279,6 +2279,13 @@ def api_cleanup_rate_limiting():
data = request.get_json() if request.is_json else None
days = data.get("days", 30) if data is not None else 30
+ try:
+ days = int(days)
+ except (TypeError, ValueError):
+ return jsonify({"error": "'days' must be an integer"}), 400
+ if days < 1 or days > 365:
+ return jsonify({"error": "'days' must be between 1 and 365"}), 400
+
tracker = get_tracker()
tracker.cleanup_old_data(days)
diff --git a/tests/web/routes/test_settings_routes_rate_limiting.py b/tests/web/routes/test_settings_routes_rate_limiting.py
index 813602161a..ec00d5bf47 100644
--- a/tests/web/routes/test_settings_routes_rate_limiting.py
+++ b/tests/web/routes/test_settings_routes_rate_limiting.py
@@ -4,6 +4,8 @@
from unittest.mock import patch, MagicMock
import time
+import pytest
+
SETTINGS_PREFIX = "/settings"
@@ -148,6 +150,22 @@ class TestApiCleanupRateLimiting:
)
assert response.status_code == 500
+ @pytest.mark.parametrize("days_value", [0, -1, 366, 1000])
+ def test_rejects_out_of_range_days(self, days_value, authenticated_client):
+ response = authenticated_client.post(
+ f"{SETTINGS_PREFIX}/api/rate-limiting/cleanup",
+ json={"days": days_value},
+ )
+ assert response.status_code == 400
+
+ @pytest.mark.parametrize("days_value", ["not-a-number", None, [1, 2]])
+ def test_rejects_non_integer_days(self, days_value, authenticated_client):
+ response = authenticated_client.post(
+ f"{SETTINGS_PREFIX}/api/rate-limiting/cleanup",
+ json={"days": days_value},
+ )
+ assert response.status_code == 400
+
class TestCheckOllamaStatusSettings:
"""Tests for /api/ollama-status endpoint in settings_routes."""