jruby_sandbox 0.2.2-java → 0.2.3-java
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/.gitignore +2 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +5 -0
- data/README.md +37 -26
- data/ext/java/sandbox/BoxedClass.java +10 -0
- data/ext/java/sandbox/SandboxFull.java +16 -11
- data/ext/java/sandbox/SandboxModule.java +23 -0
- data/ext/java/sandbox/SandboxService.java +1 -17
- data/jruby_sandbox.gemspec +18 -17
- data/lib/sandbox.rb +4 -397
- data/lib/sandbox/safe.rb +399 -0
- data/lib/sandbox/version.rb +1 -1
- data/spec/exploits_spec.rb +56 -49
- data/spec/sandbox_spec.rb +75 -75
- metadata +6 -4
- data/.rvmrc +0 -47
- data/Gemfile.lock +0 -40
data/spec/sandbox_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "rspec"
|
2
|
+
require "sandbox"
|
3
|
+
require "timeout"
|
4
4
|
|
5
5
|
describe Sandbox do
|
6
6
|
after(:each) do
|
@@ -19,42 +19,42 @@ describe Sandbox do
|
|
19
19
|
|
20
20
|
it { should be_an_instance_of(Sandbox::Safe) }
|
21
21
|
|
22
|
-
it
|
23
|
-
subject.eval(
|
22
|
+
it "should not lock down until calling activate!" do
|
23
|
+
subject.eval(%|`echo hello`|).should == "hello\n"
|
24
24
|
|
25
25
|
subject.activate!
|
26
26
|
|
27
27
|
expect {
|
28
|
-
subject.eval(
|
28
|
+
subject.eval(%|`echo hello`|)
|
29
29
|
}.to raise_error(Sandbox::SandboxException)
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
it "should activate FakeFS inside the sandbox (and not allow it to be deactivated)" do
|
33
|
-
subject.eval(
|
34
|
-
|
33
|
+
subject.eval(%|File|).should == ::File
|
34
|
+
|
35
35
|
subject.activate!
|
36
|
-
|
37
|
-
foo = File.join(File.dirname(__FILE__),
|
36
|
+
|
37
|
+
foo = File.join(File.dirname(__FILE__), "support", "foo.txt")
|
38
38
|
|
39
39
|
expect {
|
40
|
-
subject.eval(%{File.read(
|
40
|
+
subject.eval(%{File.read("#{foo}")})
|
41
41
|
}.to raise_error(Sandbox::SandboxException, /Errno::ENOENT: No such file or directory/)
|
42
|
-
|
43
|
-
subject.eval(
|
44
|
-
subject.eval(
|
45
|
-
subject.eval(
|
46
|
-
subject.eval(
|
47
|
-
|
42
|
+
|
43
|
+
subject.eval(%|File|).should == FakeFS::File
|
44
|
+
subject.eval(%|Dir|).should == FakeFS::Dir
|
45
|
+
subject.eval(%|FileUtils|).should == FakeFS::FileUtils
|
46
|
+
subject.eval(%|FileTest|).should == FakeFS::FileTest
|
47
|
+
|
48
48
|
subject.eval(%{FakeFS.deactivate!})
|
49
|
-
|
49
|
+
|
50
50
|
expect {
|
51
|
-
subject.eval(%{File.read(
|
51
|
+
subject.eval(%{File.read("#{foo}")})
|
52
52
|
}.to raise_error(Sandbox::SandboxException, /Errno::ENOENT: No such file or directory/)
|
53
|
-
|
54
|
-
subject.eval(%{File.open(
|
55
|
-
|
53
|
+
|
54
|
+
subject.eval(%{File.open("/bar.txt", "w") {|file| file << "bar" }})
|
55
|
+
|
56
56
|
expect {
|
57
|
-
subject.eval(%{FileUtils.cp(
|
57
|
+
subject.eval(%{FileUtils.cp("/bar.txt", "/baz.txt")})
|
58
58
|
}.to_not raise_error(Sandbox::SandboxException, /NoMethodError/)
|
59
59
|
end
|
60
60
|
end
|
@@ -68,14 +68,14 @@ describe Sandbox do
|
|
68
68
|
pending do
|
69
69
|
sandbox = Sandbox.new
|
70
70
|
sandbox.ref(Sandbox)
|
71
|
-
sandbox.eval(
|
71
|
+
sandbox.eval(%|Sandbox.current|).should == sandbox
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
describe "#eval with timeout" do
|
77
77
|
subject { Sandbox.safe }
|
78
|
-
|
78
|
+
|
79
79
|
context "before it's been activated" do
|
80
80
|
it "should protect against long running code" do
|
81
81
|
long_code = <<-RUBY
|
@@ -86,21 +86,21 @@ describe Sandbox do
|
|
86
86
|
subject.eval(long_code, timeout: 1)
|
87
87
|
}.to raise_error(Sandbox::TimeoutError)
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
it "should not raise a timeout error if the code runs in under the passed in time" do
|
91
91
|
short_code = <<-RUBY
|
92
92
|
1+1
|
93
93
|
RUBY
|
94
|
-
|
94
|
+
|
95
95
|
expect {
|
96
96
|
subject.eval(short_code, timeout: 1)
|
97
97
|
}.to_not raise_error(Sandbox::TimeoutError)
|
98
98
|
end
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
context "after it's been activated" do
|
102
102
|
before(:each) { subject.activate! }
|
103
|
-
|
103
|
+
|
104
104
|
it "should protect against long running code" do
|
105
105
|
long_code = <<-RUBY
|
106
106
|
while true; end
|
@@ -110,12 +110,12 @@ describe Sandbox do
|
|
110
110
|
subject.eval(long_code, timeout: 1)
|
111
111
|
}.to raise_error(Sandbox::TimeoutError)
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
it "should persist state between evaluations" do
|
115
|
-
subject.eval(
|
116
|
-
|
115
|
+
subject.eval(%|o = Object.new|, timeout: 1)
|
116
|
+
|
117
117
|
expect {
|
118
|
-
subject.eval(
|
118
|
+
subject.eval(%|o|, timeout: 1)
|
119
119
|
}.to_not raise_error(Sandbox::SandboxException)
|
120
120
|
end
|
121
121
|
end
|
@@ -127,50 +127,50 @@ describe Sandbox do
|
|
127
127
|
it "should allow a range of common operations" do
|
128
128
|
operations = <<-OPS
|
129
129
|
1 + 1
|
130
|
-
|
131
|
-
|
130
|
+
"foo".chomp
|
131
|
+
"foo"
|
132
132
|
OPS
|
133
|
-
subject.eval(operations).should ==
|
133
|
+
subject.eval(operations).should == "foo"
|
134
134
|
end
|
135
|
-
|
135
|
+
|
136
136
|
it "should have an empty ENV" do
|
137
137
|
pending do
|
138
|
-
subject.eval(%{ENV.to_a}).should be_empty
|
138
|
+
subject.eval(%{ENV.to_a}).should be_empty
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
142
|
it "should persist state between evaluations" do
|
143
|
-
subject.eval(
|
144
|
-
subject.eval(
|
143
|
+
subject.eval(%|o = Object.new|)
|
144
|
+
subject.eval(%|o|).should_not be_nil
|
145
145
|
end
|
146
146
|
|
147
147
|
it "should be able to define a new class in the sandbox" do
|
148
|
-
result = subject.eval(
|
149
|
-
result.should ==
|
148
|
+
result = subject.eval(%|Foo = Struct.new(:foo); struct = Foo.new("baz"); struct.foo|)
|
149
|
+
result.should == "baz"
|
150
150
|
end
|
151
151
|
|
152
152
|
it "should be able to use a class across invocations" do
|
153
153
|
# Return nil, because the environment doesn't know "Foo"
|
154
|
-
subject.eval(
|
155
|
-
subject.eval(
|
156
|
-
subject.eval(
|
154
|
+
subject.eval(%|Foo = Struct.new(:foo); nil|)
|
155
|
+
subject.eval(%|struct = Foo.new("baz"); nil|)
|
156
|
+
subject.eval(%|struct.foo|).should == "baz"
|
157
157
|
end
|
158
158
|
|
159
159
|
describe "communication between sandbox and environment" do
|
160
160
|
it "should be possible to pass data from the box to the environment" do
|
161
161
|
Foo = Struct.new(:foo)
|
162
162
|
subject.ref(Foo)
|
163
|
-
struct = subject.eval(
|
164
|
-
subject.eval(
|
165
|
-
struct.foo.should ==
|
163
|
+
struct = subject.eval(%|struct = Foo.new|)
|
164
|
+
subject.eval(%|struct.foo = "baz"|)
|
165
|
+
struct.foo.should == "baz"
|
166
166
|
end
|
167
167
|
|
168
168
|
it "should be possible to pass data from the environment to the box" do
|
169
169
|
Foo = Struct.new(:foo)
|
170
170
|
subject.ref(Foo)
|
171
|
-
struct = subject.eval(
|
172
|
-
struct.foo =
|
173
|
-
subject.eval(
|
171
|
+
struct = subject.eval(%|struct = Foo.new|)
|
172
|
+
struct.foo = "baz"
|
173
|
+
subject.eval(%|struct.foo|).should == "baz"
|
174
174
|
end
|
175
175
|
|
176
176
|
it "should be able to pass large object data from the box to the environment" do
|
@@ -181,49 +181,49 @@ describe Sandbox do
|
|
181
181
|
}.to_not raise_error(Sandbox::SandboxException)
|
182
182
|
|
183
183
|
expect {
|
184
|
-
subject.eval %{
|
184
|
+
subject.eval %{"RUBY"*100}
|
185
185
|
}.to_not raise_error(Sandbox::SandboxException)
|
186
186
|
end
|
187
187
|
end
|
188
188
|
end
|
189
|
-
|
189
|
+
|
190
190
|
describe "#import" do
|
191
191
|
subject { Sandbox.new }
|
192
|
-
|
192
|
+
|
193
193
|
it "should be able to call a referenced namespaced module method" do
|
194
194
|
Foo = Class.new
|
195
195
|
Foo::Bar = Module.new do
|
196
196
|
def baz
|
197
|
-
|
197
|
+
"baz"
|
198
198
|
end
|
199
199
|
module_function :baz
|
200
200
|
end
|
201
201
|
|
202
202
|
subject.import(Foo::Bar)
|
203
|
-
subject.eval(
|
203
|
+
subject.eval(%|Foo::Bar.baz|).should == "baz"
|
204
204
|
end
|
205
205
|
|
206
206
|
it "should be able to include a module from the environment" do
|
207
207
|
Foo = Module.new do
|
208
208
|
def baz
|
209
|
-
|
209
|
+
"baz"
|
210
210
|
end
|
211
211
|
end
|
212
212
|
|
213
213
|
subject.import(Foo)
|
214
|
-
subject.eval(
|
215
|
-
subject.eval(
|
214
|
+
subject.eval(%|class Bar; include Foo; end; nil|)
|
215
|
+
subject.eval(%|Bar.new.baz|).should == "baz"
|
216
216
|
end
|
217
|
-
|
217
|
+
|
218
218
|
it "should be able to copy instance methods from a module that uses module_function" do
|
219
|
-
Foo = Module.new do
|
220
|
-
def baz;
|
221
|
-
|
219
|
+
Foo = Module.new do
|
220
|
+
def baz; "baz"; end
|
221
|
+
|
222
222
|
module_function :baz
|
223
223
|
end
|
224
|
-
|
224
|
+
|
225
225
|
subject.import Foo
|
226
|
-
subject.eval(
|
226
|
+
subject.eval(%|Foo.baz|).should == "baz"
|
227
227
|
end
|
228
228
|
end
|
229
229
|
|
@@ -233,28 +233,28 @@ describe Sandbox do
|
|
233
233
|
it "should be possible to reference a class defined outside the box" do
|
234
234
|
Foo = Class.new
|
235
235
|
subject.ref(Foo)
|
236
|
-
subject.eval(
|
236
|
+
subject.eval(%|Foo.new|).should be_an_instance_of(Foo)
|
237
237
|
end
|
238
238
|
|
239
239
|
it "should be possible to change the class after the ref" do
|
240
240
|
Foo = Class.new
|
241
241
|
subject.ref(Foo)
|
242
|
-
def Foo.foo;
|
243
|
-
subject.eval(
|
242
|
+
def Foo.foo; "baz"; end
|
243
|
+
subject.eval(%|Foo.foo|).should == "baz"
|
244
244
|
end
|
245
245
|
|
246
246
|
it "should be possible to dynamically add a class method after the ref" do
|
247
247
|
Foo = Class.new
|
248
248
|
subject.ref(Foo)
|
249
|
-
Foo.class_eval(
|
250
|
-
subject.eval(
|
249
|
+
Foo.class_eval(%|def Foo.foo; "baz"; end|)
|
250
|
+
subject.eval(%|Foo.foo|).should == "baz"
|
251
251
|
end
|
252
252
|
|
253
253
|
it "should be possible to dynamically add a class method after the ref" do
|
254
254
|
Foo = Class.new
|
255
255
|
subject.ref(Foo)
|
256
|
-
Foo.instance_eval(
|
257
|
-
subject.eval(
|
256
|
+
Foo.instance_eval(%|def Foo.foo; "baz"; end|)
|
257
|
+
subject.eval(%|Foo.foo|).should == "baz"
|
258
258
|
end
|
259
259
|
|
260
260
|
it "should be possible to call a method on the class that receives a block" do
|
@@ -264,7 +264,7 @@ describe Sandbox do
|
|
264
264
|
end
|
265
265
|
end
|
266
266
|
subject.ref(Foo)
|
267
|
-
subject.eval(
|
267
|
+
subject.eval(%|Foo.bar { "baz" }|).should == "baz"
|
268
268
|
end
|
269
269
|
end
|
270
270
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jruby_sandbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Dray Lacy
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-04-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fakefs
|
@@ -91,9 +91,9 @@ extra_rdoc_files: []
|
|
91
91
|
files:
|
92
92
|
- .gitignore
|
93
93
|
- .ruby-version
|
94
|
-
- .
|
94
|
+
- .travis.yml
|
95
|
+
- CHANGELOG.md
|
95
96
|
- Gemfile
|
96
|
-
- Gemfile.lock
|
97
97
|
- LICENSE
|
98
98
|
- README.md
|
99
99
|
- Rakefile
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- jruby_sandbox.gemspec
|
106
106
|
- lib/sandbox.rb
|
107
107
|
- lib/sandbox/prelude.rb
|
108
|
+
- lib/sandbox/safe.rb
|
108
109
|
- lib/sandbox/version.rb
|
109
110
|
- spec/exploits_spec.rb
|
110
111
|
- spec/sandbox_spec.rb
|
@@ -137,3 +138,4 @@ test_files:
|
|
137
138
|
- spec/exploits_spec.rb
|
138
139
|
- spec/sandbox_spec.rb
|
139
140
|
- spec/support/foo.txt
|
141
|
+
has_rdoc:
|
data/.rvmrc
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
|
3
|
-
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
-
# development environment upon cd'ing into the directory
|
5
|
-
|
6
|
-
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
-
environment_id="jruby-1.6.3@jruby_sandbox"
|
8
|
-
|
9
|
-
#
|
10
|
-
# Uncomment following line if you want options to be set only for given project.
|
11
|
-
#
|
12
|
-
PROJECT_JRUBY_OPTS=( --1.9 )
|
13
|
-
|
14
|
-
#
|
15
|
-
# First we attempt to load the desired environment directly from the environment
|
16
|
-
# file. This is very fast and efficient compared to running through the entire
|
17
|
-
# CLI and selector. If you want feedback on which environment was used then
|
18
|
-
# insert the word 'use' after --create as this triggers verbose mode.
|
19
|
-
#
|
20
|
-
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
21
|
-
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
22
|
-
then
|
23
|
-
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
24
|
-
|
25
|
-
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
|
26
|
-
then
|
27
|
-
. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
|
28
|
-
fi
|
29
|
-
else
|
30
|
-
# If the environment file has not yet been created, use the RVM CLI to select.
|
31
|
-
if ! rvm --create "$environment_id"
|
32
|
-
then
|
33
|
-
echo "Failed to create RVM environment '${environment_id}'."
|
34
|
-
exit 1
|
35
|
-
fi
|
36
|
-
fi
|
37
|
-
|
38
|
-
#
|
39
|
-
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
40
|
-
# it be automatically loaded. Uncomment the following and adjust the filename if
|
41
|
-
# necessary.
|
42
|
-
#
|
43
|
-
# filename=".gems"
|
44
|
-
# if [[ -s "$filename" ]] ; then
|
45
|
-
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
46
|
-
# fi
|
47
|
-
|
data/Gemfile.lock
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
GIT
|
2
|
-
remote: git://github.com/codeschool/fakefs.git
|
3
|
-
revision: 6ae3212e3dab013b4b5e290d1aceba6466b30dec
|
4
|
-
ref: 6ae3212e3dab013b4b5e290d1aceba6466b30dec
|
5
|
-
specs:
|
6
|
-
fakefs (0.4.0)
|
7
|
-
|
8
|
-
PATH
|
9
|
-
remote: .
|
10
|
-
specs:
|
11
|
-
jruby_sandbox (0.2.2-java)
|
12
|
-
fakefs
|
13
|
-
|
14
|
-
GEM
|
15
|
-
remote: http://rubygems.org/
|
16
|
-
specs:
|
17
|
-
diff-lcs (1.1.2)
|
18
|
-
rake (0.9.2)
|
19
|
-
rake-compiler (0.7.9)
|
20
|
-
rake
|
21
|
-
rspec (2.6.0)
|
22
|
-
rspec-core (~> 2.6.0)
|
23
|
-
rspec-expectations (~> 2.6.0)
|
24
|
-
rspec-mocks (~> 2.6.0)
|
25
|
-
rspec-core (2.6.4)
|
26
|
-
rspec-expectations (2.6.0)
|
27
|
-
diff-lcs (~> 1.1.2)
|
28
|
-
rspec-mocks (2.6.0)
|
29
|
-
yard (0.7.2)
|
30
|
-
|
31
|
-
PLATFORMS
|
32
|
-
java
|
33
|
-
|
34
|
-
DEPENDENCIES
|
35
|
-
fakefs!
|
36
|
-
jruby_sandbox!
|
37
|
-
rake
|
38
|
-
rake-compiler
|
39
|
-
rspec
|
40
|
-
yard
|