-
-
Save tario/cab801a8a9fd6cfb0f6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "rubygems" | |
require "shikashi" | |
include Shikashi | |
s = Sandbox.new | |
priv = Privileges.new | |
# allow execution of foo, print, puts in this object | |
#priv.object(self).allow :foo, :print, :puts, :new | |
priv.methods_of(Kernel).allow :puts | |
priv.methods_of(Class).allow :new | |
priv.methods_of(Fixnum).allow :+ | |
#inside the sandbox, only can use method foo on main and method times on instances of Fixnum | |
code = <<-EOS | |
# class MP | |
class MP | |
def calc(a,b) | |
a + b | |
end | |
def test(a) | |
c = calc(10,20) | |
puts c | |
puts "inside test \#{c}" | |
if (a) | |
system('ls -l') # denied | |
end | |
end | |
end | |
#include AtlasMP | |
#test | |
MP.new.test(false) | |
EOS | |
s.run(code, priv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment