Files
bworld/docs/modding/concepts/security.md
T
2026-11-14 12:18:41 -03:00

2.4 KiB

Security

A server runs code from every mod it has installed, and so does every player who joins it. This page is what each of them trusts, and what a mod should never trust.

Players Are Untrusted

Anything a client sends can be forged by a player who edits their client. The engine already checks what it handles: reach and the held item for every break, place and interact, and container rules (slot filters, output-only slots) on the server. A mod's own logic has to do the same:

  • Decide on the server. The client phase shows things. The server phase decides what happens.
  • Check permissions on the server, in the server phase, before acting for a player, like requires on a command.
  • Never use a value from a client as an item id, a count or a position without checking it.

Tile data is never sent to clients, only the fields a script sets as client data. A mod's script is: players get all of it, its server phase too, and only run its shared and client phases. So a mod can keep secrets in the world, in tile data or ctx.storage, but never in its code. Anti-cheat works by the server deciding, not by hiding how it decides.

The Server Phase

The server phase runs in the game worker with no Deno permissions: they can't read files, open connections or run programs. Everything they can do goes through the mod API. Installing a server mod still means trusting it with the game world and everything players send.

The Client Phase

The client phase runs in the game page, like the rest of a mod's script there, with the page's full access. How much that matters depends on where the page came from:

  • The page was served by the game server (the default). That server already chose every line of JavaScript on the page, so running its mods doesn't trust it any more than loading the page did.
  • The page is from one site and the game server from another (a server typed in on the title screen, or ?server=). Mod code from that server runs with the page's origin, including its local storage. So the client lists the server's mods and asks before loading anything, and remembers the answer per server and mod.

Every .cubi a client downloads is checked against the SHA-256 the server listed, and scripts are run from the checked bytes. That guarantees the files are the ones the server listed. It doesn't protect against a malicious server.