How to run Open Cloud Luau execution tasks from a game safely

Joining player text into a Luau execution script lets it run its own code with your data stores. How to keep task scripts fixed and pass only checked values.

criticalLuaudit check: player-input-in-luau-tasks

What it looks like

The game server uses Open Cloud's Luau execution API through HttpService to run a script in a place, often an older place or a support place, to read or convert saved data. The script is built as a string, and something a player or moderator typed, such as a username, a save slot name or a data store key, is joined into it.

Luau
local source = `return Saves.load({player.UserId}, "{slotName}")`
HttpService:RequestAsync({ Url = taskUrl, Method = "POST", Headers = headers, Body = HttpService:JSONEncode({ script = source }) })

What an exploiter could do

Roblox's reference says a task's script can call engine APIs that read and change data stored in the cloud, such as data stores, and warns to take care with them. Text that breaks out of the string runs as code in that task, so they can read or rewrite any player's saved data in the experience, hand themselves currency or items, or wipe other players' progress. None of it goes through the game's remotes or checks, and changes to data stores stay after the task ends.

How to fix it

  • Keep each task script as a fixed string on the server. Let the request choose between a few fixed scripts, never write part of one.
  • Put values in only after checking them on the server: whole numbers with string.format("%d", value), or names looked up in a server table. Turn usernames into UserIds on the server first, with Players:GetUserIdFromNameAsync in pcall.
  • Give the key only the universe.place.luau-execution-session:write scope, restricted to this experience where the scope allows it, from an account with no more access than the task needs. Roblox's API key guide recommends the minimum permissions, limited to the games that need them.
  • Check the task's state is COMPLETE and check the types of its output.results before using them.

Vulnerable example

Vulnerable
local HttpService = game:GetService("HttpService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Staff = require(script.Parent.Staff)

local universeId = 5120334
local placeId = 14420871
local apiKey = HttpService:GetSecret("SupportTasks")

ReplicatedStorage.Remotes.InspectSave.OnServerInvoke = function(player: Player, username: unknown)
	if not Staff.isModerator(player) or typeof(username) ~= "string" or #username > 100 then
		return false
	end
	local source = `local id = game:GetService("Players"):GetUserIdFromNameAsync("{username}")\nreturn game:GetService("DataStoreService"):GetDataStore("PlayerData"):GetAsync("Player_" .. id)`
	local ok, response = pcall(HttpService.RequestAsync, HttpService, {
		Url = `https://apis.roblox.com/cloud/v2/universes/{universeId}/places/{placeId}/luau-execution-session-tasks`,
		Method = "POST",
		Headers = { ["x-api-key"] = apiKey, ["Content-Type"] = "application/json" },
		Body = HttpService:JSONEncode({ script = source }),
	})
	return ok and response.Success
end

Fixed example

Fixed
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Staff = require(script.Parent.Staff)

local universeId = 5120334
local placeId = 14420871
local apiKey = HttpService:GetSecret("SupportTasks")
local template = [[return game:GetService("DataStoreService"):GetDataStore("PlayerData"):GetAsync("Player_%d")]]

ReplicatedStorage.Remotes.InspectSave.OnServerInvoke = function(player: Player, username: unknown)
	if not Staff.isModerator(player) or typeof(username) ~= "string" or #username > 20 then
		return false
	end
	local found, userId = pcall(Players.GetUserIdFromNameAsync, Players, username)
	if not found or typeof(userId) ~= "number" then
		return false
	end
	local ok, response = pcall(HttpService.RequestAsync, HttpService, {
		Url = `https://apis.roblox.com/cloud/v2/universes/{universeId}/places/{placeId}/luau-execution-session-tasks`,
		Method = "POST",
		Headers = { ["x-api-key"] = apiKey, ["Content-Type"] = "application/json" },
		Body = HttpService:JSONEncode({ script = string.format(template, userId) }),
	})
	return ok and response.Success
end

The SupportTasks key has only the Luau execution scope, restricted to this experience.

How to spot this in your own scripts, and the cases that only look like it, are part of the Luaudit check your AI runs.