The gateway: deny vs. impossible
Every privileged request goes through one function. First it checks whether the payload is even shaped like something a real client could send. A well-formed request that's denied is a WARN. Your own UI or a lagged replay can cause it. A structurally impossible payload is an ALERT: no legitimate client produces it, so it's high-confidence forgery. And notice it only logs and flags. It never bans. The deny already won; auto-banning would false-positive on real players.
-- Is the request even SHAPED like something a real client sends?
-- A false here means "no legitimate client produced this".
local function validateShape(req: AuthRequest): (boolean, string?)
if typeof(req.actor) ~= "Instance" or not req.actor:IsA("Player") then
return false, "actor is not a Player"
end
if type(req.capability) ~= "string" then
return false, "capability is not a string"
end
if req.requiresTarget then
if typeof(req.target) ~= "Instance" or not req.target:IsA("Player") then
return false, "action requires a Player target but none was given"
end
end
return true, nil
end
function PermissionService.authorize(req: AuthRequest): boolean
-- Identity comes from the ENGINE-PROVIDED actor only, never the payload.
-- 1) Shape validation -- forgery detection.
local shapeOk, reason = validateShape(req)
if not shapeOk then
forgeryFlags[actorId] = (forgeryFlags[actorId] or 0) + 1
AuditLog.record({
severity = AuditLog.Severity.Alert,
event = "forged_payload",
-- + actorId, capability, and a "forgery flag #N" detail
})
return false
end
-- 2) The actual permission check.
local allowed = PermissionService.can(req.actor, req.capability)
-- 3) Permitted -> INFO; denied-but-well-formed -> WARN (never punished).
AuditLog.record({
severity = allowed and AuditLog.Severity.Info or AuditLog.Severity.Warn,
event = allowed and "authorized" or "denied",
})
return allowed
end