How to protect players in P2P multiplayer? (network security)

Godot Version

Godot 4.7

Question

I’m making a peer-to-peer racing game, and I’m wondering how to protect my players.

Should I just avoid the hassle of public lobbies?

The game is intended to be played with friends, but I realize some people might want to host a public lobby, so I want to provide that option if there is a safe way to do it.

I can’t foresee any way a bad actor could harm anyone digitally they couldn’t already in other major multiplayer games.

I am avoiding user generated content, so there shouldn’t be a way for bad players to add anything to the game. There are just RPCs to sync game data like physical position or leaderboard stats.

Knowing someones IP address can already cause some damage, the other player can poke their network for open ports, or if it’s a streamer playing your game, it can very easily and quickly lead to massive DDoS attacks.
If you want your game to purely be P2P, there’s no way to prevent this. However, you CAN go for a hybrid approach, where you use some relay servers, so the players can’t directly see the other persons IP address, but obviously this will cost you a bit of money.
As far as I know, Epic games and Steam can provide this functionality for your game for free, but your game obviously needs to be on those platforms for this to work.

Other than that, “protection” can mean a lot of things depending on how you handle network data. You should never allow code to be sent across the network and executed on the other players game, it should only be purely data which you parse yourself.