Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions dashboard_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1920,9 +1920,10 @@ def handle_api_campaign_history(self, query_params: Dict[str, List[str]]):
if "limit" in query_params:
try:
limit = int(query_params["limit"][0])
limit = min(limit, _MAX_API_LIMIT)
except (ValueError, IndexError):
limit = 25
self.send_error_response(400, "limit must be an integer")
return
limit = min(limit, _MAX_API_LIMIT)
try:
self.send_json_response(load_campaign_history(CAMPAIGN_HISTORY_ROOT, limit=limit))
except Exception:
Expand All @@ -1934,9 +1935,10 @@ def handle_api_validation_history(self, query_params: Dict[str, List[str]]):
if "limit" in query_params:
try:
limit = int(query_params["limit"][0])
limit = min(limit, _MAX_API_LIMIT)
except (ValueError, IndexError):
limit = 10
self.send_error_response(400, "limit must be an integer")
return
limit = min(limit, _MAX_API_LIMIT)
try:
self.send_json_response(load_validation_history(VALIDATION_HISTORY_ROOT, limit=limit))
except Exception:
Expand All @@ -1948,9 +1950,10 @@ def handle_api_preflight_history(self, query_params: Dict[str, List[str]]):
if "limit" in query_params:
try:
limit = int(query_params["limit"][0])
limit = min(limit, _MAX_API_LIMIT)
except (ValueError, IndexError):
limit = 10
self.send_error_response(400, "limit must be an integer")
return
limit = min(limit, _MAX_API_LIMIT)
try:
self.send_json_response(load_preflight_history(PREFLIGHT_HISTORY_ROOT, limit=limit))
except Exception:
Expand All @@ -1969,9 +1972,10 @@ def handle_api_evidence_chain_history(self, query_params: Dict[str, List[str]]):
if "limit" in query_params:
try:
limit = int(query_params["limit"][0])
limit = min(limit, _MAX_API_LIMIT)
except (ValueError, IndexError):
limit = 10
self.send_error_response(400, "limit must be an integer")
return
limit = min(limit, _MAX_API_LIMIT)
try:
self.send_json_response(load_evidence_chain_history(EVIDENCE_CHAIN_HISTORY_ROOT, limit=limit))
except Exception:
Expand Down
12 changes: 12 additions & 0 deletions test_dashboard_api_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ def test_cleanup_non_integer_keep_latest_keeps_default(self):
candidate_limit=25,
)

def test_history_non_integer_limit_is_400(self):
handler = _handler()
for method in (
handler.handle_api_campaign_history,
handler.handle_api_validation_history,
handler.handle_api_preflight_history,
handler.handle_api_evidence_chain_history,
):
handler.send_error_response.reset_mock()
method({"limit": ["nope"]})
handler.send_error_response.assert_called_once_with(400, "limit must be an integer")

def test_options_preflight_does_not_require_a_bearer(self):
old_token = dashboard_server.DASHBOARD_TOKEN
old_origin = dashboard_server.DASHBOARD_CORS_ORIGIN
Expand Down
Loading