2

I am currently testing a strict custom environment in lua that takes advantage of _G and sets it to a locked metatable,I then uses the __call metamethod of that metatable to sandbox any scripts I need to. This restricts access to most functions and the entirety of the debug library. I have left rawget/rawset out for now and I am intrigued as to whether I can override the locked _G metatable using rawget/rawset. Thank you if you are able to help with my question.

-- Edit Also if you would be able to post an example of a properly sandboxed rawset/rawget that would be awesome!

Egor Skriptunoff
  • 23,359
  • 2
  • 34
  • 64
Batoda
  • 33
  • 3
  • 1
    Nobody is going to make you a complex wrapper for fun – warspyking May 08 '17 at 21:33
  • `rawget` and `rawset` can be used to read/write fields of `_G` (and hence prevent your `__index`/`__newindex` logic), but `rawget` and `rawset` cannot be used to read/write fields of protected metatable (because metatable reference is being kept secret). So, `_G()` will always invoke `__call` metamethod in your protected metatable. – Egor Skriptunoff May 08 '17 at 21:49
  • 1
    Thanks a lot for your reply! I'm glad that the referenced functions are unable to edit the metamethods as it makes sandboxing a whole lot easier. Also warspyking you aren't undersanding what I asked, if you read the first line you can clearly see that I have already made the sandbox. – Batoda May 08 '17 at 22:00

0 Answers0