mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 00:14:00 +00:00
fix(multiplayer): validate event timestamps
This commit is contained in:
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user