Security: never trust the client

Learn Roblox game security with Beacon Yard. Server validation, rate limits, movement sanity checks, Toolbox backdoors and require-by-id malware, the common exploit types, and why client anti-cheat is weak, with runnable checks.

Concept lesson, about 70 minutes, 12 steps

By the end you can

  • Build a small threat model: what must stay true, and which entry points a client can reach
  • Validate a request on the server by shape, permission, distance and rate, using Beacon Yard's real checks
  • Write a movement sanity check, and say why it is a heuristic
  • Explain how a free model can hide a backdoor, how require-by-id malware works, and why client-side anti-cheat is weak
  • Quarantine an untrusted model in a sandboxed container with the fewest script capabilities

Before this: Remotes: events, functions, unreliable, buffers, Types: strict mode, the new type solver, generics

Step 1 of 12

The note that says 9999 coins

Open the Studio command bar on the client during Play and run:

game.ReplicatedStorage.Remotes.ShopBuy:FireServer("Speed", 9999, "I am rich")

The shop never reads the 9999 or the claim. ShopService.purchase takes the player the engine supplied and the item, and nothing else. The price, the balance and the owner of the profile all come from the server's own tables.

function ShopService.purchase(player: Player, item: unknown)
	if item == "Speed" then
		buySpeed(player)
		return
	end
	if item == "Shield" then
		buyShield(player)
		return
	end
	if item == "CoinPack" then
		MonetizationService.prompt(player)
		return
	end
	feedback(player, "deny", "Unknown item")

That is the whole idea of this lesson in three lines. The client can send anything. The server decides using only what the server already knows.

Choose one

A client fires ShopBuy with the arguments ("Speed", 9999) and has 3 coins. What does ShopService.purchase use to decide?

A client fires ShopBuy with the arguments ("Speed", 9999) and has 3 coins. What does ShopService.purchase use to decide?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 2 of 12

A threat model in four columns

Security work starts with a list, before any code: what must stay true, and every door a client can reach it through. In Beacon Yard the things that must stay true are the profile's coins, the speed flag, the shield charge, the drone's health and the Coin Pack grant. The HUD number and the player's WalkSpeed are copies a client can write, so they are not assets.

The doors are the entry points: ShopBuy, Swing, a Touched event on a coin, and the purchase-receipt callback. ShopOpen is not a door that changes coins; the prompt only asks the server to show a menu.

Server sideServer validation is the clerk checks the scoreboard.
In the pictureIn Roblox
A note arriving at the deskA remote event reaching OnServerEvent
Checking the note against the real scoreboardComparing the request with Config and the server's profile
Refusing the noteReturning early or sending a deny Feedback

See the whole analogy cast

The server is a clerk who checks every note against the real scoreboard before acting on it. A note that says "give me 9999 coins" is just paper.

Think of it as The clerk checks the scoreboard

Match the pairs

Match each entry point to the server function that decides it.

Link to this step · This confused me

Step 3 of 12

Four checks: shape, permission, distance, rate

A good handler asks four questions, in order of cost:

  1. Shape. Is it the right kind of value, and a sane one? Beacon Yard's trySwing wants two Vector3 values, both finite, with a direction longer than a thousandth of a stud.
  2. Permission. Is the sender allowed right now? The swing needs a Wrench equipped, not just owned.
  3. Distance. Is the claim physically possible? The origin must be within 8 studs of the head. A coin pays only if the player's root part is within 12 studs.
  4. Rate. Has the sender done this too often? Swings are 0.4 seconds apart at least.

Only after all four does the server apply its own number, WRENCH_DAMAGE of 34. The client never supplied it.

function CombatService.trySwing(player: Player, origin: unknown, direction: unknown): string
	if typeof(origin) ~= "Vector3" or typeof(direction) ~= "Vector3" then
		return "rejected"
	end
	if not isFiniteVector(origin) or not isFiniteVector(direction) then
		return "rejected"
	end
	if direction.Magnitude < 1e-3 then
		return "rejected"
	end
 
	local character = player.Character
	if character == nil then
		return "rejected"
	end
	local tool = character:FindFirstChild("Wrench")
	if tool == nil or not tool:IsA("Tool") then
		return "rejected"
	end
	local head = character:FindFirstChild("Head")
	if head == nil or not head:IsA("BasePart") then
		return "rejected"
	end
	if (origin - head.Position).Magnitude > ORIGIN_MAX_STUDS then
		return "rejected"
	end
 
	local now = workspace:GetServerTimeNow()
	local previousSwing = lastSwing[player]
	if previousSwing ~= nil and now - previousSwing < SWING_GAP then
		return "rejected"
	end
	lastSwing[player] = now
Roblox Studio
Roblox Studio with CombatService open: the constants ORIGIN_MAX_STUDS equals 8, DRONE_TAG, SWING_GAP equals 0.4, and the lastSwing table are visible.

Select a numbered pin, or a row below, to read what it marks.

CombatService's two constants. Neither is in Config, so a client reading Config learns nothing about them.

Match the pairs

Match each number to what it limits in Beacon Yard at m06.

Link to this step · This confused me

Step 4 of 12

Write the checks yourself

The cell below is a toy shop with the same four questions. Run it, then read the output against the code: every forged request is stopped by a different check.

Luau
Ctrl Enter runs the cell. Checked against the expected output
Choose one

In the toy shop, lastBuy is written before the item is checked. Why not write it only after a successful purchase?

In the toy shop, lastBuy is written before the item is checked. Why not write it only after a successful purchase?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 5 of 12

Movement: the part the client owns

Most checks work because the server owns the thing being changed. Movement is different: each client simulates its own character and sends the result up, otherwise walking would lag. A modified client can therefore report a position it never walked to, or set WalkSpeed to any value locally1.

Roblox's guidance is plain: there is no universal solution. A server check compares where a player was with where they are, over the time between. Three details matter:

  • Allow for latency. Positions arrive late and in bursts, so average over time and add a tolerance, or honest players on bad connections get flagged.
  • Measure on the ground plane. Project onto X and Z so jumping and falling do not count as running.
  • Exempt legitimate teleports. A teleport pad or respawn is not cheating, so the game must tell the check.

Beacon Yard does not have a movement check at m06. Its speed numbers (16 normally, 24 with the upgrade) are what a check would be built from. The cell below is such a check, as a heuristic.

Luau with roblox-lite (not Roblox)
Ctrl Enter runs the cell. Checked against the expected output
Work it out

Using the cell's check with TOLERANCE 1.5: a player with the Speed upgrade (BOOST_SPEED 24) is measured over 2 seconds. What is the farthest flat distance, in studs, that still passes?

studs

Link to this step · This confused me

Step 6 of 12

What attackers actually do

Cheaters are not one kind of person with one trick. A few families cover most of what you will meet:

  • Remote abuse. Fire a remote with forged, extreme or malformed arguments, or far too often. Defence: the four checks.
  • Local tampering. Change values on their own client: WalkSpeed, a fake coin count, a GUI. Harmless if the server ignores the copy, harmful if it believes it.
  • Movement and physics exploits. Teleport, fly, or take control of loose parts through network ownership. Defence: server movement checks, and anchoring or owning parts that matter.
  • Reading the client. Anything replicated can be read, and scripts that reach the client can be decompiled. Server-only scripts in ServerStorage or ServerScriptService never replicate, so they cannot be2.
  • Backdoors. Code hidden in something you installed yourself, which runs on your server with full power. The next step is about these.
Match the pairs

Match each exploit to the defence that actually stops it.

Link to this step · This confused me

Step 7 of 12

Toolbox backdoors and require-by-id

The Toolbox is full of free models, and many of them contain scripts. Most animate a door or play a sound. A few hide a backdoor: a short script that gives its author control of your game.

The classic trick uses require with a number. A ModuleScript uploaded to Roblox with the name MainModule can be loaded with require(assetId). That works on a server only and errors on a client, and other users can load it only when the model is public, which is why a backdoor author publishes theirs. The code then runs inside your game3. A backdoor is one line, often hidden under a boring name in a model's deep folders, that requires someone else's uploaded module. Whatever that module contains now runs with the power of your own server scripts, and its author can change it later without touching your game.

Defences, from cheapest to strongest:

  • Look at the scripts in anything you install: search the model for require( followed by a long number, and for scripts with strange names.
  • Install the model, then use Disable Scripts on it in Explorer, if you only need the parts4.
  • Keep account ids and asset ids in one reviewed place, so an id anywhere else is a red flag. Beacon Yard does this and enforces it in CI.
const LONG_NUMBER = /(?<![\w.])\d{9,}(?!\w|\.\d)/g;

The id guard was built so real account ids do not leak, but it works against backdoors too: a nine-digit number that is not in Ids.luau fails the build.

The cell below scans lines of code for a numeric require. It is a toy version of what a reviewer, or a CI job, does.

Luau
Ctrl Enter runs the cell. Checked against the expected output
Choose one

A free model contains a script with require(<a long number>). Why is that more dangerous than a script that only plays a sound?

A free model contains a script with require(<a long number>). Why is that more dangerous than a script that only plays a sound?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 8 of 12

A quarantine folder for free models

Read every script before using a free model. Studio also blocks high-risk script capabilities on new Creator Store inserts. To configure your own sandboxed container or adjust its capabilities manually, enable the client-beta controls by setting Workspace.SandboxedInstanceMode to Experimental5.

Then a Model, Folder or Script has a Sandboxed property. Tick it, and scripts inside can do only what its Capabilities list allows. A few that matter for free models:

  • RunServerScript: without it, a server script inside does not start at all, and Output shows a warning.
  • CreateInstances: needed for Instance.new and Clone.
  • LoadUnownedAsset: needed for require with an asset id, the backdoor line from the last step.
  • AccessOutsideWrite: without it, a script can only reach instances inside its own container. The docs advise never granting it.

A missing capability stops the call with an error that names it, such as The current thread cannot call 'Clone' (lacking capability CreateInstances). Try it on a stand-in for a free model, in a copy of the yard you will not publish. Never test with a real backdoored model.

Build along

m14-ship

  1. Open a copy of the yard's place. Set Workspace.SandboxedInstanceMode to Experimental, add a Folder named Quarantine to Workspace, and tick its Sandboxed property.

    You should see Workspace shows SandboxedInstanceMode Experimental, and a Folder named Quarantine has Sandboxed ticked and an empty Capabilities list.

  2. Inside Quarantine, add a Model named FreeCrate with a Script: print("free crate running"), then local part = Instance.new("Part"), part.Parent = workspace, and require(1234). Press Play.

    You should see On Play, Output shows a warning that the script cannot start because it lacks RunServerScript, and nothing from the script runs.

  3. Stop, add only RunServerScript to the folder's Capabilities, and press Play again.

    You should see The print appears, then the Instance.new line stops with an error that names a missing capability, such as CreateInstances. No part appears and require never runs.

  4. Delete the Quarantine folder and close the copy without publishing.

    You should see The place is back as it was, with no Quarantine folder.

Choose one

A free windmill model only sets the AngularVelocity of a HingeConstraint motor inside its own model. Which capabilities do you grant its sandboxed container?

A free windmill model only sets the AngularVelocity of a HingeConstraint motor inside its own model. Which capabilities do you grant its sandboxed container?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 9 of 12

Why client-side anti-cheat is weak

A common first idea is a script on the client that watches for cheating: it checks WalkSpeed and kicks the player if it is too high. It feels safe. It is not, for one reason: the cheater controls the machine that script runs on.

They can delete the script, stop it from running, change what it reads, or answer its questions with lies. Roblox's own security guide says client-side enforcement will eventually be bypassed, and that this is a basic fact of client-server design rather than a Roblox flaw6. A client check is only useful for friction and for reporting suspicious cases to the server. The decision has to be made where the cheater cannot reach.

Server sideRemember: Server validation is the clerk checks the scoreboard.

Where does it break?“The clerk checks the scoreboard” is a good picture of server validation. Where does it stop being true?

It breaks here. A clerk checks only what they remember to check, so every field of every note is a place a check can be missing; one unchecked note is the exploit. Some claims, such as a position the client simulated itself, cannot be checked against anything, only judged as plausible.

The true model. Validation is a function per entry point: shape, permission, distance, rate, then the server's own numbers. Anything the client can both send and have believed is a hole. Where the client owns the state, as with its own movement, the server can only apply heuristics.

Choose one

Beacon Yard's server checks every Swing. A teammate suggests also adding a LocalScript that stops the swing button when it detects a macro. What is that script worth?

Beacon Yard's server checks every Swing. A teammate suggests also adding a LocalScript that stops the swing button when it detects a macro. What is that script worth?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 10 of 12

Build it: close the shop's open door

Beacon Yard's honest gap at m06 is that ShopBuy has no rate limit, while Swing does. Studios choose from a few approaches to this whole problem.

Ways to keep a game honest

OptionWhat it isWhen pros pick itTrade-offs
Server-side validationCheck every request against the server's own state. Beacon Yard's approach.Always. It is the foundation under every other option.You must write and test a check for every entry point, and movement checks are heuristics that need tuning.
Server authority modelRoblox's documented architecture (Workspace.AuthorityMode = Server) where the server simulates characters from client input while clients predict and roll back.Competitive games where movement itself must not be faked.Requires Deferred signals, Input Action System, StreamingEnabled and fixed simulation; physics and combat must be written for rollback.
Device Trust APIIntegrityService.EvaluatePlayerDeviceTrust and Player.DeviceTrustLevel rate how tamper-resistant a player's device is (Pending, Unknown, None, Standard, Full).Gating sensitive features like trading or matching players of similar device trust, on top of server checks.Optional and leaves all action to you; supported on Android, Chromebook and Meta Quest today (Web reports None; iOS, desktop and consoles currently report Unknown).
Telemetry and moderationThe server logs suspicious events (impossible speed, repeated denials) and a person or a rule reviews and acts.Games with a competitive economy or a community that reports cheaters.Slow, needs people, and false positives hurt honest players.
Client-side anti-cheat scriptsLocal scripts that look for cheating and report or kick.As friction on top of server checks, never alone.The cheater controls the machine, so these can be removed, so they cannot be relied on.

Two engine tools extend this foundation once a game grows. Roblox's Server Authority model moves simulation onto the server with client prediction and rollback7, covered hands-on in Server authority. The Device Trust API reports hardware and OS integrity on supported platforms without taking action itself8, which you combine with a shared remote wrapper and cross-server strike sync in Security at scale.

Build along

m06-drone-wrench

  • src/server/ShopService.luau
  1. Check out m06-drone-wrench, run rojo serve, press Play, and in the client command bar run game.ReplicatedStorage.Remotes.ShopBuy:FireServer("Speed", 9999, "I am rich").

    You should see The HUD at the bottom of the screen shows the usual deny or buy toast, and your coin count is unchanged by the 9999.

  2. Run the same call twice in one line: local r = game.ReplicatedStorage.Remotes.ShopBuy r:FireServer("Speed") r:FireServer("Speed"). At m06, nothing slows the second call.

    You should see A Not enough coins or Already owned toast appears; no second purchase happens.

  3. Open src/server/CombatService.luau and find the two constants.

    You should see Studio shows CombatService with ORIGIN_MAX_STUDS equal to 8 and SWING_GAP equal to 0.4.

Link to this step · This confused me

Step 11 of 12

Challenges

Level 1, Apprentice

Challenge

Fill in the threat model for Beacon Yard's four entry points.

Start from
The game at milestone m06 (download)

Done means

  • A four-row table: swing, shop, coin, Coin Pack
  • Each row names the asset, the entry point, the existing control and what the client must not decide
  • Swing names the 8 stud cap and damage 34; the shop names prices 25 and 40; the coin names 12 studs and 5 coins

Meet the criteria above, then record your own result. No test grades this check.

Luau with roblox-lite (not Roblox)
Ctrl Enter runs the cell. Checked by tests

Level 3, Professional

Challenge

Rate-limit the shop on the server. The written solution, including the edit to the suite's shop_shield check, is challenges/solutions/security.md in the game repo.

Start from
The game at milestone m06 (download)
Grade it
To grade work from an earlier milestone, apply your challenge changes to a checkout based on m14-ship, which includes the Course Runner. In Studio, press Play, then run require(game.ReplicatedStorage.GameTests.RunChallenge)("security") in the client command bar. Copy the pass code from Output.

Done means

  • ShopService.purchase records workspace:GetServerTimeNow() per player before the item branches
  • A second purchase right after the first is denied with the Feedback text Too fast (self-check, the test cannot see it: the gap is 0.5 seconds)
  • Self-check, the test cannot see it: the shop_shield check in tests/init.luau waits out the new gap and still expects the shield to be bought
  • The Course Runner prints TEST PASS security_shop_rate and a pass code

The Course Runner prints this code when the test passes.

Link to this step · This confused me

Step 12 of 12

Recap

Retiring the analogy

You no longer need “the clerk checks the scoreboard”. Validation is a function per entry point: shape, permission, distance, rate, then the server's own numbers. Anything the client can both send and have believed is a hole. Where the client owns the state, as with its own movement, the server can only apply heuristics.

Recap

  1. A threat model lists what must stay true and every entry point that can change it. Each handler checks shape, permission, distance and rate, then applies its own numbers, never one the client sent.
  2. The client owns its character, so movement checks on the server are heuristics: allow for latency, measure on the ground plane, and exempt real teleports. WalkSpeed on a client is only a copy.
  3. Free models can hide backdoors such as require-by-id, which run with your server's power. Inspect what you install, keep ids in one guarded place, and remember a client-side anti-cheat can always be removed.
  4. Studio blocks high-risk capabilities on new Creator Store inserts. The client-beta controls let you set capabilities on your own sandboxed container. Start with none and add only what your scripts need.

Server validation is the clerk checks the scoreboard, until a clerk checks only what they remember to check, so every field of every note is a place a check can be missing; one unchecked note is the exploit. Some claims, such as a position the client simulated itself, cannot be checked against anything, only judged as plausible.

A RemoteEvent is a note to the front-desk clerk, until the engine stamps the sender for you, but every other word on the note can be a lie.

Next Core loop design: act, reward, spend, repeat

Link to this step · This confused me