forked from mtusi2026/mtusi2026lab4
fix: reject noncanonical cursors and verify storage failover
This commit is contained in:
+11
-2
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user