Last active
September 9, 2023 04:41
-
-
Save gboncoffee/625730c410ac3daa2f99b97268484073 to your computer and use it in GitHub Desktop.
Example of evaluating untrusted code in Lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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