Skip to content

Add net message validation - #6676

Open
metalgearsloth wants to merge 6 commits into
space-wizards:masterfrom
metalgearsloth:2026-06-28-net-message-validation
Open

Add net message validation#6676
metalgearsloth wants to merge 6 commits into
space-wizards:masterfrom
metalgearsloth:2026-06-28-net-message-validation

Conversation

@metalgearsloth

@metalgearsloth metalgearsloth commented Jun 28, 2026

Copy link
Copy Markdown
Contributor
  • Adds NetMaxSize / NetMaxLength attributes to specify max NetMessage size / collection limits. Also a debug command to make it easier to tune these rather than guessing.
  • MsgEntity relied on the sender to specify buffer size which is now validated first. Same with the type, whether anyone subscribes to it, and that it's a correct type. Deserialization then uses the helper attributes.
  • There's many NetMessages that accept user-supplied length. For now I just added some dummy validation but we will need to go through these at some point and check lengths and set sane maximums. These can't use the helper attributes because they serialize directly and don't go through netserializer.
  • Not sure on the performance cost but I think a 5% slower server would be worth validating messages more and we can profile and adjust in future.

Resolves #6673 but I also am not sure what else we can be doing besides reworking some of the code paths to avoid exceptions (which would be a much larger engine-only change for NetMessage in general; this at least gets the attributes for use now in the existing codepaths). At least this shouldn't cause the game to read int.MaxValue amounts of memory based on trust.

Needs space-wizards/netserializer#9 for the collection length CVars

Tests passing locally on my machine.

Attribute seemed like the easiest way to do it alongside a debug command. Also validates EntityEventArgs.
@metalgearsloth
metalgearsloth marked this pull request as ready for review June 28, 2026 02:34
@metalgearsloth
metalgearsloth marked this pull request as draft June 28, 2026 02:49
@metalgearsloth
metalgearsloth marked this pull request as ready for review June 29, 2026 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NetMessage validation

1 participant