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.

security: add pagination bounds to unbounded database queries

LearningCircuitb4b00448c23e
diff --git a/src/local_deep_research/web/routes/context_overflow_api.py b/src/local_deep_research/web/routes/context_overflow_api.py
index 5bdf5ccd5e..0d3b6afb63 100644
--- a/src/local_deep_research/web/routes/context_overflow_api.py
+++ b/src/local_deep_research/web/routes/context_overflow_api.py
@@ -108,9 +108,9 @@ def get_context_overflow_metrics():
time_series_query = query.order_by(TokenUsage.timestamp)
if start_date:
- # For shorter periods, get all data points
+ # For shorter periods, get all data points (capped at 1000)
if period in ["7d", "30d"]:
- time_series_data = time_series_query.all()
+ time_series_data = time_series_query.limit(1000).all()
else:
# For longer periods, sample data
time_series_data = time_series_query.limit(500).all()
diff --git a/src/local_deep_research/web/routes/history_routes.py b/src/local_deep_research/web/routes/history_routes.py
index ca53a3e29f..1f789d813c 100644
--- a/src/local_deep_research/web/routes/history_routes.py
+++ b/src/local_deep_research/web/routes/history_routes.py
@@ -39,11 +39,18 @@ def get_history():
return jsonify({"status": "error", "message": "Not authenticated"}), 401
try:
+ limit = request.args.get("limit", 200, type=int)
+ limit = max(1, min(limit, 500))
+ offset = request.args.get("offset", 0, type=int)
+ offset = max(0, offset)
+
with get_user_db_session(username) as db_session:
- # Get all history records ordered by latest first
+ # Get history records ordered by latest first with pagination
results = (
db_session.query(ResearchHistory)
.order_by(ResearchHistory.created_at.desc())
+ .limit(limit)
+ .offset(offset)
.all()
)
diff --git a/src/local_deep_research/web/routes/research_routes_orm.py b/src/local_deep_research/web/routes/research_routes_orm.py
index b5aabf09bb..cb92fb72c4 100644
--- a/src/local_deep_research/web/routes/research_routes_orm.py
+++ b/src/local_deep_research/web/routes/research_routes_orm.py
@@ -337,8 +337,9 @@ def clear_history():
@login_required
def api_get_history():
"""Get history using ORM with pagination."""
- page = request.args.get("page", 1, type=int)
+ page = max(1, request.args.get("page", 1, type=int))
per_page = request.args.get("per_page", 50, type=int)
+ per_page = max(1, min(per_page, 500))
db_session = get_user_db_session()