Skip to content

Instantly share code, notes, and snippets.

@gboncoffee
Last active September 9, 2023 04:41
Show Gist options
  • Save gboncoffee/625730c410ac3daa2f99b97268484073 to your computer and use it in GitHub Desktop.
Save gboncoffee/625730c410ac3daa2f99b97268484073 to your computer and use it in GitHub Desktop.
Example of evaluating untrusted code in Lua
local oldprint = print
print = function(a)
oldprint("load print: " .. a)
end
a = 1
local f = load "print(a)"
f() -- this will print 'load print: 1'
--
-- the code below would get a 'attempt to call a nil value':
--
-- local f = load "oldprint(a)"
-- f()
--
-- this happens because loaded code can only access globals. override all
-- dangerous functions and combine this with pcall and ya get a simple way of
-- running untrusted code
--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment