You need to address this with a combination of methods. First, you need to create a suitable sandbox for untrusted scripts, with an environment that provides only those global variables and functions that are safe and necessary. Secondly, you need to provide restrictions on the use of memory and processor. Third, you need to explicitly refuse to download the precompiled bytecode from untrusted sources.
The first point is simple. There is quite a bit of discussion about the Lua sandbox, available on the Lua user wiki, on the mailing list, and here in SO. You almost certainly already do this part if you know that some scripts are more reliable than others.
The second question is the question you ask. I will come back to this in a moment.
The third issue was discussed on the mailing list, but perhaps it was not clearly spelled out in other media. It turned out that in the Lua kernel there are a number of vulnerabilities that are difficult or impossible to address, but which depend on the βwrongβ bytecode to implement. That is, they cannot be used from Lua source code, only from a pre-compiled and carefully corrected byte code. Directly write a bootloader that generally refuses to download any binary bytecode.
Given these points, this raises the question of a denial of service attack, either through CPU consumption, memory consumption, or both. Firstly, the bad news. There are no perfect methods to prevent this. However, one of the most reliable approaches is to interpret Lua in a separate process and use the security features and platform quotas to limit the capabilities of this process. In the worst case, the destruction process can be killed without prejudice to the main application. This technique is used in recent versions of Firefox to contain the side effects of bugs in plugins, so it is not necessarily as crazy as it seems.
One interesting complete example is the Lua Live Demo . This is a web page where you can enter a sample Lua code, execute it on a server and view the results. Because scripts can be entered anonymously from anywhere, they are clearly unreliable. This web application looks as secure as it can be suggested. Its source kit is available for download from one of the authors of Lua.
source share