fix: reject noncanonical cursors and verify storage failover

This commit is contained in:
2026-11-06 18:20:32 +03:00
parent 619155f1e0
commit ff17362bcd
8 changed files with 246 additions and 16 deletions
+11 -2
View File
@@ -30,10 +30,19 @@ def boundary(scope: str, cursor: str | None) -> tuple[str, str] | None:
if not cursor or len(cursor) > 1024 or not re.fullmatch(r"[A-Za-z0-9_-]+", cursor):
raise ValueError
data = json.loads(base64.urlsafe_b64decode(cursor + "=" * (-len(cursor) % 4)))
if not isinstance(data, list) or len(data) != 4 or data[:2] != [1, scope]:
if (
not isinstance(data, list)
or len(data) != 4
or type(data[0]) is not int
or data[0] != 1
or data[1] != scope
):
raise ValueError
date, uid = data[2:]
if not isinstance(date, str) or not date.endswith("Z"):
if not isinstance(date, str) or not re.fullmatch(
r"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\.[0-9]{1,6})?Z",
date,
):
raise ValueError
datetime.fromisoformat(date.replace("Z", "+00:00"))
if not isinstance(uid, str) or str(UUID(uid)) != uid: