How can I create a secure Lua sandbox?

2019-01-02 15:01发布

So Lua seems ideal for implementing secure "user scripts" inside my application.

However, most examples of embedding lua seem to include loading all the standard libraries, including "io" and "package".

So I can exclude those libs from my interpreter, but even the base library includes the functions "dofile" and "loadfile" which access the filesystem.

How can I remove/block any unsafe functions like these, without just ending up with an interpreter that doesn't even have basic stuff like the "ipairs" function?

标签: lua sandbox
7条回答
闭嘴吧你
2楼-- · 2019-01-02 15:33

You can override (disable) any Lua function you want and also you can use metatables for more control.

查看更多
登录 后发表回答