fix(events): reject malformed pagination cursors as 400 errors

Wraps DateTimeParseException from Instant.parse in IllegalArgumentException
so the controller maps it to 400. Also rejects cursors with empty
instance_id (trailing '|') which would otherwise produce a vacuous
keyset predicate.
This commit is contained in:
hsiegeln
2026-04-17 12:02:40 +02:00
parent d293dafb99
commit 0194549f25
2 changed files with 29 additions and 2 deletions

View File

@@ -80,10 +80,15 @@ public class ClickHouseAgentEventRepository implements AgentEventRepository {
if (cursor != null && !cursor.isEmpty()) {
String decoded = new String(Base64.getUrlDecoder().decode(cursor), StandardCharsets.UTF_8);
int bar = decoded.indexOf('|');
if (bar <= 0) {
if (bar <= 0 || bar == decoded.length() - 1) {
throw new IllegalArgumentException("Malformed cursor");
}
Instant cursorTs = Instant.parse(decoded.substring(0, bar));
Instant cursorTs;
try {
cursorTs = Instant.parse(decoded.substring(0, bar));
} catch (java.time.format.DateTimeParseException e) {
throw new IllegalArgumentException("Malformed cursor", e);
}
String cursorInstance = decoded.substring(bar + 1);
sql.append(" AND (timestamp < ? OR (timestamp = ? AND instance_id > ?))");
params.add(Timestamp.from(cursorTs));