sandbox - Lua Sandboxing - Eliminating Function Creation -
i've read on lua wiki / here / etc. on how sandbox lua code generally. haven't been able find disallows function creation. example, example here provides sample code as:
assert(run [[function f(x) return x^2 end; t={2}; t[1]=f(t[1])]])
and that's empty environment. want eliminate ability create function (the 1st part of code) - e.g., allow expressions. idea on how that? have in c somehow? in advance!
if want evaluate expressions only, try this:
function run(s) return loadstring("return "..s)() end
(error handling omitted)
this simple solution prevent `attacks', not eliminate them because 1 can say
(function () f=function(x) print"hello" end end)()
which defines new function named f
.
your best bet use sandbox , not worry user environment, because it'll not your environment.
Comments
Post a Comment