Securing Godot 4 Multiplayer: RPCs, Authority and Server-Side Validation
Godot's high-level multiplayer API makes networking easy, but as the official docs put it, it "does not automatically make gameplay logic secure". Here is how to lock down your RPCs.
The two @rpc modes that matter
From the Godot high-level multiplayer docs, a bare @rpc is the same as @rpc("authority", "call_remote", "reliable", 0). The mode decides who may call the function remotely:
"authority"(default): only the node's multiplayer authority can call it remotely. The authority is the server (peer ID 1) by default, but you can change it per node withset_multiplayer_authority()."any_peer": any connected client can call it. The docs suggest it for sending user input, which also makes it your attack surface: a modified client can call anyany_peerfunction, with any arguments, as often as it likes.
Rule of thumb: any_peer functions should only ever run on the server, should accept requests ("I want to move left", "I want to buy item 7") and should validate everything before changing game state.
Know who sent it: get_remote_sender_id()
Inside an RPC, multiplayer.get_remote_sender_id() returns the unique ID of the peer that sent the call. Use it instead of trusting a player ID passed as an argument, because arguments can be anything.
# BAD: the client says who it is and what happened
@rpc("any_peer")
func deal_damage(attacker_id: int, target_id: int, amount: int):
players[target_id].health -= amount # attacker_id and amount are lies-on-demand
# BETTER: the server decides, based on who really sent the request
const FIRE_COOLDOWN_MS := 250
@rpc("any_peer", "call_local", "reliable")
func request_fire(aim: Vector2):
if not multiplayer.is_server():
return
var sender := multiplayer.get_remote_sender_id()
if sender == 0: # 0 = called locally, not over the network
sender = multiplayer.get_unique_id()
var p = players.get(sender)
if p == null or not p.alive:
return
if not aim.is_finite() or aim.length() > 1.01:
return # reject NaN / oversized vectors
var now := Time.get_ticks_msec()
if now < p.next_shot_ms or p.ammo <= 0:
return # server-enforced cooldown and ammo
p.next_shot_ms = now + FIRE_COOLDOWN_MS
p.ammo -= 1
resolve_hit_on_server(p, aim.normalized())
(call_local is needed when the host is also a player, as in the docs' example. In that case get_remote_sender_id() returns 0 for the local call, which the snippet handles.)
Be careful who you give authority to
Many tutorials give each client authority over its own player node with set_multiplayer_authority(peer_id), so a MultiplayerSynchronizer replicates that player's position from the client. The MultiplayerSynchronizer docs describe it as synchronizing properties from the multiplayer authority to remote peers, so whatever the authoritative client writes into those properties (position, health, score) is sent to everyone. That's convenient but trusts the client.
For anything competitive, keep the server as authority over gameplay state, and give the client authority only over a small "input" node whose values the server reads and checks. The docs' own secure multiplayer design section recommends exactly this: server-authoritative logic for gameplay-critical decisions, validating RPC arguments, not trusting client-reported positions, timers, cooldowns or resource values, and rate-limiting frequent actions.
Validation checklist for every any_peer RPC
- Run only on the server (
if not multiplayer.is_server(): return). - Identify the caller with
get_remote_sender_id(), never an argument. - Check types, ranges and finiteness (no NaN or INF, no negative quantities, no unknown item IDs).
- Check game rules: is the player alive, in this match, close enough, owning the item, off cooldown?
- Rate-limit per peer, and disconnect peers that flood you (
multiplayer.multiplayer_peer.disconnect_peer(id)on ENet). - Compute results (damage, loot, currency, score) on the server.
Authenticate peers before they can call RPCs
Godot 4's SceneMultiplayer has a built-in authentication step: set auth_callback on the server, have the client send credentials with send_auth(), and call complete_auth() once they check out. Until both sides complete auth, the connection isn't established. Verify a token from your own backend (or a platform ticket such as Steam) here; never trust a username the client simply claims. Note that the docs' example sets auth_timout, but the actual property is auth_timeout.
Don't ship secrets in your .pck
Your exported game's .pck (or ZIP) pack contains your scripts, scenes and resources, as listed in the packs documentation. Community tools can open packs and recover scripts, so treat every string in the export as public: API keys, database passwords, admin tokens, webhook URLs and "secret" server commands included.
Godot can encrypt the PCK with an AES-256 key, but this requires compiling your own export templates, and the docs are explicit that the key "needs to be stored in the binary". It slows down casual ripping; it does not protect secrets. Keep them on a server, and have the game call your server instead.
The same page on packs also warns that loading extra PCKs (mods, patches, DLC) can load malicious code, and suggests signing patch packs with asymmetric cryptography (Godot's Crypto class) if you distribute them through a launcher.
Prompt to paste into your AI coding tool
Audit this Godot 4 project's multiplayer code. List every @rpc function and its mode.
For each "any_peer" RPC: make it run only on the server, identify the caller with
multiplayer.get_remote_sender_id() instead of any argument, validate argument types,
ranges and game rules, add a per-peer rate limit, and compute outcomes server-side.
Flag any node where a client has multiplayer authority over gameplay state (health,
score, inventory, position without checks). Also find any API keys, passwords or
tokens in scripts or resources that would be exported in the .pck.
Want this checked automatically?
BossCheck is a security scanner for indie games built with AI tools. It's in pre-launch: join the waitlist for early access.
Join the waitlist →FAQ
What's the difference between @rpc any_peer and authority in Godot 4?
With "authority" (the default), only the node's multiplayer authority, the server unless you change it, can call the function remotely. With "any_peer", any connected client can call it, so it must validate everything it receives.
How do I know which player called an RPC in Godot?
Call multiplayer.get_remote_sender_id() inside the RPC function. It returns the sender's peer ID. Don't trust player IDs passed as arguments.
Is it safe to give clients multiplayer authority over their player?
It's convenient but means the server and other players accept whatever that client reports for synchronized properties. For competitive games, keep gameplay state server-authoritative and let clients send input only.
Can people extract scripts from a Godot .pck file?
Yes. Exported packs contain your scripts and resources, and community tools can unpack them. Never put secrets in an exported Godot project.
Does Godot PCK encryption protect my API keys?
No. It requires custom-compiled export templates and the key is stored in the game binary, so it only slows down extraction. Keep secrets on a server.
More guides
- How to Keep Your Steam Web API Key Out of Your Game Build
- Firebase and Supabase Security Rules for Multiplayer Games
- Never Trust the Client: Stopping Cheaters in Vibe-Coded Multiplayer Games
- Security Checklist Before Shipping a Game Built with Cursor, Claude or Lovable
- Is Code from Cursor, Lovable or Claude Secure? What to Check Before You Ship
- How to Protect API Keys in a Unity Game
- How to Stop Players Editing Browser Game Saves to Unlock Paid Items
- Is My Vibe-Coded Game Safe? A Free 10-Minute Security Self-Check
- Stop Bots and Scripts from Breaking Your Game Economy Before a Steam Launch