mruby_sandbox 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/lib/mruby_sandbox.rb +44 -53
- data/lib/mruby_sandbox/version.rb +2 -2
- data/mruby/sandbox/mrblib/sandbox.rb +20 -54
- data/mruby_sandbox.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a2f7112f407c42a5d6991e90114f42df58f06c0
|
4
|
+
data.tar.gz: 81862829d3b0771964526afedf4302c185aed23e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f55f88f1588de6dfbc388ab7c4eabeb4576241e13b556dd2fc7fb55f2f6e492ee1f989b295b800ea6fed627f5887e414c3c2af2c711ee698c9caf423dc340eb
|
7
|
+
data.tar.gz: a940f8ed2d48b70671d6df40aa329264f2d16a0bfe278052f5bf16b769b9722c0b16d645b7bb254705fc31fd631568daeb837faf8ae055ec63dbdeedfbb1fd47
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mruby_sandbox (0.
|
5
|
-
pipe_rpc (~> 0
|
4
|
+
mruby_sandbox (0.5.0)
|
5
|
+
pipe_rpc (~> 1.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
diff-lcs (1.2.5)
|
11
11
|
json (1.8.3)
|
12
|
-
pipe_rpc (0.
|
12
|
+
pipe_rpc (1.0.0)
|
13
13
|
json
|
14
14
|
rspec (3.4.0)
|
15
15
|
rspec-core (~> 3.4.0)
|
data/lib/mruby_sandbox.rb
CHANGED
@@ -1,75 +1,66 @@
|
|
1
1
|
require 'pipe_rpc'
|
2
|
-
require 'forwardable'
|
3
2
|
require 'logger'
|
3
|
+
|
4
4
|
require_relative 'mruby_sandbox/version'
|
5
5
|
require_relative 'mruby_sandbox/server'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
attr_writer :logger
|
7
|
+
module MrubySandbox
|
8
|
+
class MrubySandbox < PipeRpc::Gateway
|
9
|
+
class << self
|
10
|
+
attr_writer :logger
|
12
11
|
|
13
|
-
|
14
|
-
|
12
|
+
def logger
|
13
|
+
@logger ||= Logger.new(STDOUT)
|
14
|
+
end
|
15
15
|
end
|
16
|
-
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
def initialize
|
18
|
+
input, w = IO.pipe
|
19
|
+
r, output = IO.pipe
|
20
|
+
@pid = spawn(executable, in: r, out: w)
|
21
|
+
r.close; w.close
|
23
22
|
|
24
|
-
|
23
|
+
self.class.logger.debug "Sandbox(#{__id__}) created with process #{@pid}"
|
25
24
|
|
26
|
-
|
27
|
-
@data = {}
|
25
|
+
super(input: input, output: output)
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
rescue Errno::ENOENT => e
|
28
|
+
STDERR.puts "The mruby_sandbox executable is missing. Run `build_mruby_sandbox` first."
|
29
|
+
fail e
|
30
|
+
end
|
33
31
|
|
34
|
-
|
32
|
+
def client
|
33
|
+
clients[:default]
|
34
|
+
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
def eval(*args)
|
37
|
+
client.eval(*args)
|
38
|
+
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
def start_logging
|
41
|
+
on_sent do |message|
|
42
|
+
self.class.logger.debug "Sandbox(#{__id__}) sent: #{message}"
|
43
|
+
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
on_received do |message|
|
46
|
+
self.class.logger.debug "Sandbox(#{__id__}) received: #{message}"
|
47
|
+
end
|
48
48
|
end
|
49
|
-
end
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
def close
|
51
|
+
return unless @pid
|
52
|
+
super
|
53
|
+
Process.kill 9, @pid
|
54
|
+
Process.wait @pid
|
55
|
+
self.class.logger.debug "Sandbox(#{__id__}) teared down and process #{@pid} killed"
|
56
|
+
@pid = nil
|
57
57
|
end
|
58
|
-
end
|
59
58
|
|
60
|
-
|
61
|
-
return unless @pid
|
62
|
-
@hub.cancel
|
63
|
-
Process.kill 9, @pid
|
64
|
-
Process.wait @pid
|
65
|
-
self.class.logger.debug "Sandbox(#{__id__}) teared down and process #{@pid} killed"
|
66
|
-
@pid = nil
|
67
|
-
end
|
68
|
-
|
69
|
-
private
|
59
|
+
private
|
70
60
|
|
71
|
-
|
72
|
-
|
73
|
-
|
61
|
+
def executable
|
62
|
+
current_dir = File.expand_path(File.dirname(__FILE__))
|
63
|
+
File.join(current_dir, '../bin/mruby_sandbox')
|
64
|
+
end
|
74
65
|
end
|
75
66
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.
|
1
|
+
module MrubySandbox
|
2
|
+
VERSION = "0.5.0"
|
3
3
|
end
|
@@ -1,77 +1,43 @@
|
|
1
|
-
class Sandbox <
|
2
|
-
def initialize
|
3
|
-
@main = main
|
4
|
-
@main.sandbox = self
|
1
|
+
class Sandbox < PipeRpc::Gateway
|
2
|
+
def initialize
|
5
3
|
input = IO.new(0, 'r') #STDIN
|
6
4
|
output = IO.new(1, 'w') #STDOUT
|
7
|
-
|
8
|
-
add_server(default: Controller.new(self))
|
9
|
-
::Kernel.loop { iteration }
|
5
|
+
super(input: input, output: output)
|
10
6
|
end
|
11
7
|
|
12
|
-
def
|
13
|
-
|
14
|
-
end
|
8
|
+
def set_up(main)
|
9
|
+
servers.add(default: main)
|
15
10
|
|
16
|
-
|
17
|
-
@hub.add_server(args)
|
18
|
-
end
|
11
|
+
sandbox = self
|
19
12
|
|
20
|
-
|
21
|
-
|
22
|
-
|
13
|
+
main.define_singleton_method :add_server do |*args|
|
14
|
+
sandbox.servers.add(*args)
|
15
|
+
end
|
23
16
|
|
24
|
-
|
25
|
-
|
26
|
-
|
17
|
+
main.define_singleton_method :client_for do |server|
|
18
|
+
sandbox.clients[server]
|
19
|
+
end
|
27
20
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
@hub.handle_message # blocks every iteration
|
32
|
-
rescue ::Exception => e
|
33
|
-
# reflect ALL rescueable errors back to the managing process
|
34
|
-
backtrace = e.backtrace
|
35
|
-
@hub.send_response PipeRpc::ErrorResponse.new(error: { code: -32603, data: { message: e.message, backtrace: backtrace } })
|
36
|
-
::Kernel.raise e
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class Sandbox::Controller
|
41
|
-
def initialize(sandbox)
|
42
|
-
@sandbox = sandbox
|
43
|
-
end
|
44
|
-
|
45
|
-
def eval(code, file = '', lineno = 0)
|
46
|
-
@sandbox.eval(code, file, lineno)
|
47
|
-
end
|
48
|
-
|
49
|
-
def debug_mode(debug = true)
|
50
|
-
@sandbox.debug_mode(debug)
|
21
|
+
loop do
|
22
|
+
handle_message # blocks every iteration
|
23
|
+
end
|
51
24
|
end
|
52
25
|
end
|
53
26
|
|
54
27
|
# Interface for untrusted code to communicate with the outside
|
55
28
|
class << self
|
56
|
-
attr_writer :sandbox
|
57
|
-
|
58
29
|
def eval(code, file = '', lineno = 0)
|
59
30
|
instance_eval(code, file, lineno)
|
60
31
|
end
|
61
32
|
|
62
|
-
def
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
def client_for(server = :default)
|
67
|
-
@sandbox.client_for(server)
|
33
|
+
def client
|
34
|
+
clients[:default]
|
68
35
|
end
|
69
|
-
alias_method :client, :client_for
|
70
36
|
end
|
71
37
|
|
72
38
|
# Remove constants from global namespace so untrusted code cannot mess around with it.
|
73
|
-
|
74
|
-
|
39
|
+
Object.remove_const(:GC)
|
40
|
+
Object.remove_const(:ObjectSpace)
|
75
41
|
Sandbox::IO = Object.remove_const(:IO)
|
76
42
|
Sandbox::PipeRpc = Object.remove_const(:PipeRpc)
|
77
|
-
Object.remove_const(:Sandbox).new(self)
|
43
|
+
Object.remove_const(:Sandbox).new.set_up(self)
|
data/mruby_sandbox.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = ["build_mruby_sandbox"]
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.add_runtime_dependency "pipe_rpc", "~> 0
|
24
|
+
spec.add_runtime_dependency "pipe_rpc", "~> 1.0"
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.8"
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.4"
|
27
27
|
spec.add_development_dependency "rspec-its"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mruby_sandbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Aue
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pipe_rpc
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|