在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):APItools/sandbox.lua开源软件地址(OpenSource Url):https://github.com/APItools/sandbox.lua开源编程语言(OpenSource Language):Lua 100.0%开源软件介绍(OpenSource Introduction):sandbox.luaA pure-lua solution for running untrusted Lua code. The default behavior is restricting access to "dangerous" functions in Lua, such as It's possible to provide extra functions via the Infinite loops are prevented via the For now, sandbox.lua only works with Lua 5.1.x. UsageRequire the module like this: local sandbox = require 'sandbox' sandbox.protect
A sandboxed function works as regular functions as long as they don't access any insecure features: local sandboxed_f = sandbox(function() return 'hey' end)
local msg = sandboxed_f() -- msg is now 'hey' Sandboxed options can not access unsafe Lua modules. (See the source code for a list) When a sandboxed function tries to access an unsafe module, an error is produced. local sf = sandbox.protect(function()
os.execute('rm -rf /') -- this will throw an error, no damage done
end)
sf() -- error: os.execute not found Sandboxed functions will eventually throw an error if they contain infinite loops: local sf = sandbox.protect(function()
while true do end
end)
sf() -- error: quota exceeded options.quota
This limit can be tweaked via the It is not possible to exhaust the machine with infinite loops; the following will throw an error after invoking 500000 instructions: sandbox.run('while true do end') -- raise errors after 500000 instructions
sandbox.run('while true do end', {quota=10000}) -- raise error after 10000 instructions Note that if the quota is low enough, sandboxed functions that do lots of calculations might fail: local f = function()
local count = 1
for i=1, 400 do count = count + 1 end
return count
end
sandbox.run(f, {quota=100}) -- raises error before the function ends options.envUse the
Note that the
sandbox.run
You can pass In other words, Notice that if local ok, result = pcall(sandbox.run, 'error("this just throws an error")') InstallationJust copy sandbox.lua wherever you need it. LicenseThis library is released under the MIT license. See MIT-LICENSE.txt for details SpecsThis project uses telescope for its specs. In order to run them, install it and then:
I would love to use busted, but it has some incompatibility with |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论