Update modding docs
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
# 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. Client scripts show things. Server scripts decide what happens.
|
||||
- Check permissions on the server, in the server script, before acting for a player, like `requires` on a
|
||||
[command](../misc/commands.md).
|
||||
- Never use a value from a client as an item id, a count or a position without checking it.
|
||||
|
||||
Server script code and tile data are never sent to clients, so a mod can keep anti-cheat logic or secrets there.
|
||||
|
||||
## Server Scripts
|
||||
|
||||
Server scripts run 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.
|
||||
|
||||
## Client Scripts
|
||||
|
||||
Client scripts run in the game page 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 `.bmod` 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.
|
||||
Reference in New Issue
Block a user