rubenwardy wrote:I wouldn't trust your Lua version.
I wouldn't trust it much without a few good pairs of eyes looking it over and pounding it for holes, but it should be as good as the C++ version in general (except that it doesn't have engine support and may not be loaded first). I did cover more of the possibly unsafe API functions, and also created a pretty paranoid virtual filesystem so it should truly be impossible to access anything outside the mod and world directories. This also included sandboxing any and all functions that take a file path argument, and whitelisting the minetest API itself.
rubenwardy wrote:The debug library's mostly fine, they disabled the ability to get local variables etc. What do you mean by the environment table of Lua functions? _G?
It's possible for the standard API functions to have an environment table, just like you can use setfenv() to set an environment for a Lua function. If no environment table is set, it'll return the global environment (which has indeed been replaced...), but nothing in the Lua spec. guarantees that the standard API functions have no environment table set (whether one implementation of Lua does or not is irrelevant, as changing this would be API compatible and could happen as a minor release or OS-specific change). Therefore, it is a hole that could possibly allow mods to get hold of the original global environment and call any of the original API functions. This is why in the Lua security mod I very carefully only allow getfenv() and getmetatable() to return tables that have previously been explicitly set in the sandbox environment by setfenv() or setmetatable(), respectfully. No way to get hold of a function-containing table installed from outside the sandbox (yes, read-only access is indeed quite dangerous).
It's similar situations that make the debug library absolutely
not safe in general. It's best to remove access to the entire debug library if possible. It's very difficult to sandbox debug functionality completely. For example, there are standard API functions (e.g. pcall() and xpcall()) that make callbacks to user-defined functions. That and debug.setlocal() could be used to change some local variable in the standard API function (if some release of Lua happened to implement them in such a way that they had local variables). Can you think of any security holes that might create? debug.setlocal() is one of the whitelisted functions in that security code, by the way.
rubenwardy wrote:Also, did you make sure you enabled mod security? It's currently disabled by default until 0.5 due to compatibility worries.
I'm simply inspecting the code at this point. I'm still running 0.4.12.
rubenwardy wrote:The point of mod security is to protect the computer from a malicious mod, not protecting other mods (they need to be able to be otherridden) or the Minetest world. (Deleting blocks etc could be intended, backups should be made anyway.)
Certainly. Well understood.
I've worked in computer security. You have to be very paranoid. When in doubt, disallow an operation. Whitelist rather than blacklist. Think of situations where read-only access is as dangerous as write access. Like I said, my standards are very high when something claims to provide security. There's a reason for that; good security is supposed to allow you to do things that would otherwise be risky. Such as running mods where you haven't inspected every line of code, even though they might try to format your harddrive.