fix(multiplayer): validate event timestamps

This commit is contained in:
Josh Creek
2026-09-01 22:21:18 +01:00
parent 73e5d64ba2
commit 87d43302e1
3 changed files with 17 additions and 3 deletions
+9 -3
View File
@@ -282,8 +282,7 @@ static func is_valid_access_token(token: String) -> bool:
static func is_session_expired(expires_at: String, now_unix: int = -1) -> bool:
if expires_at.is_empty():
return false
var timestamp_pattern := RegEx.create_from_string("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})$")
if timestamp_pattern.search(expires_at) == null:
if not is_valid_rfc3339_timestamp(expires_at):
return true
var expiry_unix := Time.get_unix_time_from_datetime_string(expires_at)
if expiry_unix < 0:
@@ -294,6 +293,13 @@ static func is_session_expired(expires_at: String, now_unix: int = -1) -> bool:
return expiry_unix <= current_unix
static func is_valid_rfc3339_timestamp(value: String) -> bool:
if value.is_empty():
return false
var timestamp_pattern := RegEx.create_from_string("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})$")
return timestamp_pattern.search(value) != null
static func is_retryable_mutation_response(response_code: int) -> bool:
return response_code == 0 or response_code == HTTPClient.RESPONSE_REQUEST_TIMEOUT or response_code == HTTPClient.RESPONSE_TOO_MANY_REQUESTS or response_code >= 500
@@ -470,7 +476,7 @@ static func _valid_websocket_event(event: Dictionary) -> bool:
return false
if not event.has("resource_id") or not event["resource_id"] is String or String(event["resource_id"]).is_empty():
return false
if not event.has("occurred_at") or not event["occurred_at"] is String or String(event["occurred_at"]).is_empty():
if not event.has("occurred_at") or not event["occurred_at"] is String or not is_valid_rfc3339_timestamp(String(event["occurred_at"])):
return false
var event_name := String(event["event"])
if event_name == "assignment_changed":