fix(CORE-001D3B): reject malformed alert history entries

This commit is contained in:
Bu5hm4nn
2026-03-26 15:16:21 +01:00
parent ff76e326b1
commit 65da5b8f1d
2 changed files with 31 additions and 2 deletions

View File

@@ -67,7 +67,18 @@ class AlertHistoryRepository:
raise AlertHistoryLoadError(self.history_path, f"Alert history could not be read: {exc}") from exc
if not isinstance(data, list):
raise AlertHistoryLoadError(self.history_path, "Alert history payload must be a list")
return [AlertEvent.from_dict(item) for item in data if isinstance(item, dict)]
events: list[AlertEvent] = []
for index, item in enumerate(data):
if not isinstance(item, dict):
raise AlertHistoryLoadError(self.history_path, f"Alert history entry {index} must be an object")
try:
events.append(AlertEvent.from_dict(item))
except (TypeError, ValueError) as exc:
raise AlertHistoryLoadError(
self.history_path,
f"Alert history entry {index} is invalid: {exc}",
) from exc
return events
def save(self, events: list[AlertEvent]) -> None:
with self.history_path.open("w") as f: