fix(multiplayer): validate allocated config ids

This commit is contained in:
Josh Creek
2026-09-01 22:44:12 +01:00
parent 75f9026ea1
commit 56e8e2554c
3 changed files with 20 additions and 0 deletions
+11
View File
@@ -276,6 +276,10 @@ func _validate() -> void:
for key in ["match-id", "server-id", "playlist-version", "playlist", "client-build", "assignment-expiry-unix", "server-image-digest", "transport", "region"]:
if str(values[key]).is_empty():
errors.append("--allocated-mode requires --%s" % key)
if not _is_opaque_id(String(values["match-id"])):
errors.append("--match-id must be an opaque ID of 16-128 safe characters")
if not _is_opaque_id(String(values["server-id"])):
errors.append("--server-id must be an opaque ID of 16-128 safe characters")
if int(values["assignment-expiry-unix"]) <= int(Time.get_unix_time_from_system()):
errors.append("--assignment-expiry-unix must be in the future")
if String(values["join-authorisations-file"]).is_empty():
@@ -307,6 +311,13 @@ static func _is_sha256_digest(value: String) -> bool:
return true
static func _is_opaque_id(value: String) -> bool:
if value.length() < 16 or value.length() > 128:
return false
var resource_pattern := RegEx.create_from_string("^[A-Za-z0-9_-]+$")
return resource_pattern.search(value) != null
static func _kind_name(kind: int) -> String:
match kind:
Kind.BOOL: return "bool"
+7
View File
@@ -152,6 +152,13 @@ func test_allocated_mode_rejects_invalid_transport_region_or_digest() -> void:
]
var config = _parse(args)
assert_true(not config.is_valid(), "invalid compatibility values are rejected")
var unsafe_id = _parse([
"--allocated-mode", "--match-id=short", "--server-id=server/unsafe", "--playlist-version=v",
"--client-build=client", "--assignment-expiry-unix=%d" % (Time.get_unix_time_from_system() + 3600),
"--server-image-digest=sha256:" + "a".repeat(64), "--playlist=casual", "--transport=enet", "--region=EU",
"--join-authorisations-file=/run/secrets/join-authorisations.json", "--join-authorisations-key-file=/run/secrets/join-authorisations.key"
])
assert_true(not unsafe_id.is_valid(), "short or unsafe allocated identifiers are rejected")
func test_allocated_mode_rejects_missing_or_expired_assignment_manifest_fields() -> void: