You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
running inside a C function under the Lua interpreter.</dd>
137
137
</dl>
138
138
139
-
<dl>
139
+
<dlid="sandbox">
140
+
<dt>Q: Can Lua code be safely sandboxed?</dt>
141
+
<dd>
142
+
Maybe for an extremly restricted subset of Lua and if you relentlessly
143
+
scrutinize every single interface function you offer to the untrusted code.<br>
144
+
145
+
Although Lua provides some sandboxing functionality (<tt>setfenv()</tt>, hooks),
146
+
it's very hard to get this right even for the Lua core libraries. Of course,
147
+
you'll need to inspect any extension library, too. And there are libraries
148
+
that are inherently unsafe, e.g. the <ahref="ext_ffi.html">FFI library</a>.<br>
149
+
150
+
Relatedly, <b>loading untrusted bytecode is not safe!</b> It's trivial
151
+
to crash the Lua or LuaJIT VM with maliciously crafted bytecode. This is
152
+
well known and there's no bytecode verification on purpose, so please
153
+
don't report a bug about it. Check the <tt>mode</tt> parameter for the
154
+
<tt>load*()</tt> functions to disable loading of bytecode.<br>
155
+
156
+
In general, the only promising approach is to sandbox Lua code at the
157
+
process level and not the VM level.<br>
158
+
159
+
More reading material at the <ahref="http://lua-users.org/wiki/SandBoxes"><spanclass="ext">»</span> Lua Wiki</a> and <ahref="https://en.wikipedia.org/wiki/Sandbox_(computer_security)">Wikipedia</a>.
160
+
</dd>
161
+
</dl>
162
+
163
+
<dlid="patches">
140
164
<dt>Q: Why doesn't my favorite power-patch for Lua apply against LuaJIT?</dt>
141
165
<dd>Because it's a completely redesigned VM and has very little code
142
166
in common with Lua anymore. Also, if the patch introduces changes to
0 commit comments