Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sandboxing from Lua #77

Closed
bopjesvla opened this issue May 4, 2017 · 6 comments
Closed

Sandboxing from Lua #77

bopjesvla opened this issue May 4, 2017 · 6 comments

Comments

@bopjesvla
Copy link

Is this a safe way to sandbox luerl?

-- called with luerl:do

whitelist = {
  _G = _G,
  ipairs = ipairs,
  next = next,
  pairs = pairs,
  pcall = pcall,
  tonumber = tonumber,
  tostring = tostring,
  type = type,
  unpack = unpack,
  string = { byte = string.byte, char = string.char, find = string.find, 
      format = string.format, gmatch = string.gmatch, gsub = string.gsub, 
      len = string.len, lower = string.lower, match = string.match, 
      rep = string.rep, reverse = string.reverse, sub = string.sub, 
      upper = string.upper },
  table = { insert = table.insert, maxn = table.maxn, remove = table.remove, 
      sort = table.sort }
}

for i in pairs(_G) do
  if not whitelist[i] then
    _G[i] = "prohibited in sandbox"
  else
    _G[i] = whitelist[i]
  end
end
@bopjesvla
Copy link
Author

bopjesvla commented May 4, 2017

The code is based on http://stackoverflow.com/a/6982080/678335, by the way. I'm somewhat confident there is no way around this, but I'd rather be safe than sorry.

@rvirding
Copy link
Owner

rvirding commented May 7, 2017

That would work. It also depends on how you start luerl. Another way could be start doing the same thing from within the luerl module after you have created the initial state but before you start running luerl. That would be guaranteed safer as it is done before any lua code is run. You would basically do it the same way.

@bopjesvla
Copy link
Author

That's good to know!

@tisba
Copy link

tisba commented Jan 10, 2018

Would it make sense to add this to the README, wiki or maybe even offer an API to initialise an environment based on that out of the box?

@lastcanal
Copy link
Contributor

Hi @tisba, sandbox functionality is available through the luerl_sandbox module that is included along with luerl. Take a look at these examples to see it in action. The actual implementation does something similar to the Lua script above, but in Erlang; essentially what Robert describes in his comment. It also includes a reduction counting 'runner' to prevent 'fork bomb' style scripts from crashing the VM.

Take a look at PR #85 for more info.

@tisba
Copy link

tisba commented Jan 10, 2018

Damn, I totally overlooked this. Sorry for the noise, and thanks! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants