Replies: 1 comment 1 reply
-
The whole point of sandboxing is that the entire global state has read-only entries and read-only metatables. You have to maintain this yourself. All of the built-in libraries have this property (once Luau can't possibly expect to cover all edge cases where sandboxing might be broken; for example, In my own implementation of Luau i've set it to set everything as read only after all values to a table have been set but before it has been added to the global state: lua_createtable(L, 0, 8);
// ....
lua_pushlstring(L, classMeta._name.data(), classMeta._name.length());
lua_rawsetfield(L, -2, "__type");
// Hide metatable behind a read-only empty table.
// Luau's `setmetatable` will hide the real metatable if the `__metatable` field is set.
lua_createtable(L, 0, 0);
lua_setreadonly(L, -1, true);
lua_rawsetfield(L, -2, "__metatable");
// Metatables should be read-only to prevent hijacking :)
lua_setreadonly(L, -1, true);
lua_setuserdatametatable(L, tag, -1);
lua_setuserdatadtor(L, tag, classMeta._destructor); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
If I sandbox an environment with the following code,
a.b.x
is successfully incremented, and then an error is thrown at the point whena.x
would be incremented. Is this intentional on the part of the Luau team?(For my use case -- user scripting with savestates that don't include any Luau state -- I'll need to implement deep sandboxing downstream, but I could do that in my client application, or I could do it by modifying the
luaL_sandbox
functions and submitting a PR. This should be trivial to implement with a depth-first algorithm, usinggetreadonly
to prevent cycles.)(The same question applies for closures.)
Beta Was this translation helpful? Give feedback.
All reactions