safe_ruby 1.0.2 → 1.0.5
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 +5 -5
- data/.gitignore +2 -1
- data/.gitlab-ci.yml +42 -0
- data/Gemfile +28 -1
- data/Gemfile.lock +76 -29
- data/README.md +2 -2
- data/Rakefile +15 -6
- data/config/rspec +4 -0
- data/config/rubocop.yml +76 -0
- data/lib/constant_allowlist.rb +124 -0
- data/lib/make_safe_code.rb +48 -43
- data/lib/method_allowlist.rb +272 -0
- data/lib/safe_ruby/runner.rb +45 -26
- data/lib/safe_ruby/version.rb +10 -1
- data/lib/safe_ruby.rb +3 -6
- data/safe_ruby.gemspec +18 -16
- data/spec/safe_ruby_spec.rb +52 -44
- data/spec/spec_helper.rb +5 -2
- data/tasks/console.rake +8 -0
- data/tasks/package.rake +4 -0
- data/tasks/smelling_code.rake +23 -0
- data/tasks/test.rake +19 -0
- metadata +27 -63
- data/lib/constant_whitelist.rb +0 -13
- data/lib/method_whitelist.rb +0 -271
metadata
CHANGED
|
@@ -1,101 +1,68 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: safe_ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
+
- Jérôme Arbez-Gindre
|
|
7
8
|
- Uku Taht
|
|
8
|
-
autorequire:
|
|
9
|
+
autorequire:
|
|
9
10
|
bindir: bin
|
|
10
11
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
+
date: 2024-10-04 00:00:00.000000000 Z
|
|
12
13
|
dependencies:
|
|
13
14
|
- !ruby/object:Gem::Dependency
|
|
14
15
|
name: childprocess
|
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
|
16
17
|
requirements:
|
|
17
|
-
- - "
|
|
18
|
+
- - "~>"
|
|
18
19
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
20
|
+
version: '5'
|
|
20
21
|
type: :runtime
|
|
21
22
|
prerelease: false
|
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
24
|
requirements:
|
|
24
|
-
- - "
|
|
25
|
+
- - "~>"
|
|
25
26
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: pry
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - ">="
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - ">="
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0'
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: rake
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - ">="
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '0'
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - ">="
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '0'
|
|
55
|
-
- !ruby/object:Gem::Dependency
|
|
56
|
-
name: rspec
|
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
|
58
|
-
requirements:
|
|
59
|
-
- - ">="
|
|
60
|
-
- !ruby/object:Gem::Version
|
|
61
|
-
version: '0'
|
|
62
|
-
type: :development
|
|
63
|
-
prerelease: false
|
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
-
requirements:
|
|
66
|
-
- - ">="
|
|
67
|
-
- !ruby/object:Gem::Version
|
|
68
|
-
version: '0'
|
|
27
|
+
version: '5'
|
|
69
28
|
description: Evaluates ruby code by writing it to a tempfile and spawning a child
|
|
70
|
-
process. Uses a
|
|
29
|
+
process. Uses a allowlist of methods and constants to keep, for example one cannot
|
|
71
30
|
run system commands in the environment created by this gem. The environment created
|
|
72
31
|
by the untrusted code does not leak out into the parent process.
|
|
73
|
-
email:
|
|
32
|
+
email: jeromearbezgindre@gmail.com
|
|
74
33
|
executables: []
|
|
75
34
|
extensions: []
|
|
76
35
|
extra_rdoc_files: []
|
|
77
36
|
files:
|
|
78
37
|
- ".gitignore"
|
|
38
|
+
- ".gitlab-ci.yml"
|
|
79
39
|
- ".rspec"
|
|
80
40
|
- Gemfile
|
|
81
41
|
- Gemfile.lock
|
|
82
42
|
- LICENSE.txt
|
|
83
43
|
- README.md
|
|
84
44
|
- Rakefile
|
|
85
|
-
-
|
|
45
|
+
- config/rspec
|
|
46
|
+
- config/rubocop.yml
|
|
47
|
+
- lib/constant_allowlist.rb
|
|
86
48
|
- lib/make_safe_code.rb
|
|
87
|
-
- lib/
|
|
49
|
+
- lib/method_allowlist.rb
|
|
88
50
|
- lib/safe_ruby.rb
|
|
89
51
|
- lib/safe_ruby/runner.rb
|
|
90
52
|
- lib/safe_ruby/version.rb
|
|
91
53
|
- safe_ruby.gemspec
|
|
92
54
|
- spec/safe_ruby_spec.rb
|
|
93
55
|
- spec/spec_helper.rb
|
|
94
|
-
|
|
56
|
+
- tasks/console.rake
|
|
57
|
+
- tasks/package.rake
|
|
58
|
+
- tasks/smelling_code.rake
|
|
59
|
+
- tasks/test.rake
|
|
60
|
+
homepage: https://gitlab.com/defmastership/safe_ruby/
|
|
95
61
|
licenses:
|
|
96
62
|
- MIT
|
|
97
|
-
metadata:
|
|
98
|
-
|
|
63
|
+
metadata:
|
|
64
|
+
rubygems_mfa_required: 'true'
|
|
65
|
+
post_install_message:
|
|
99
66
|
rdoc_options: []
|
|
100
67
|
require_paths:
|
|
101
68
|
- lib
|
|
@@ -103,18 +70,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
103
70
|
requirements:
|
|
104
71
|
- - ">="
|
|
105
72
|
- !ruby/object:Gem::Version
|
|
106
|
-
version: '
|
|
73
|
+
version: '2.7'
|
|
107
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
75
|
requirements:
|
|
109
76
|
- - ">="
|
|
110
77
|
- !ruby/object:Gem::Version
|
|
111
78
|
version: '0'
|
|
112
79
|
requirements: []
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
signing_key:
|
|
80
|
+
rubygems_version: 3.5.16
|
|
81
|
+
signing_key:
|
|
116
82
|
specification_version: 4
|
|
117
83
|
summary: Run untrusted ruby code in a safe environment
|
|
118
|
-
test_files:
|
|
119
|
-
- spec/safe_ruby_spec.rb
|
|
120
|
-
- spec/spec_helper.rb
|
|
84
|
+
test_files: []
|
data/lib/constant_whitelist.rb
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
ALLOWED_CONSTANTS= [
|
|
2
|
-
:Object, :Module, :Class, :BasicObject, :Kernel, :NilClass, :NIL, :Data, :TrueClass, :TRUE, :FalseClass, :FALSE, :Encoding,
|
|
3
|
-
:Comparable, :Enumerable, :String, :Symbol, :Exception, :SystemExit, :SignalException, :Interrupt, :StandardError, :TypeError,
|
|
4
|
-
:ArgumentError, :IndexError, :KeyError, :RangeError, :ScriptError, :SyntaxError, :LoadError, :NotImplementedError, :NameError,
|
|
5
|
-
:NoMethodError, :RuntimeError, :SecurityError, :NoMemoryError, :EncodingError, :SystemCallError, :Errno, :ZeroDivisionError,
|
|
6
|
-
:FloatDomainError, :Numeric, :Integer, :Fixnum, :Float, :Bignum, :Array, :Hash, :Struct, :RegexpError, :Regexp,
|
|
7
|
-
:MatchData, :Marshal, :Range, :IOError, :EOFError, :IO, :STDIN, :STDOUT, :STDERR, :Time, :Random,
|
|
8
|
-
:Signal, :Proc, :LocalJumpError, :SystemStackError, :Method, :UnboundMethod, :Binding, :Math, :Enumerator,
|
|
9
|
-
:StopIteration, :RubyVM, :Thread, :TOPLEVEL_BINDING, :ThreadGroup, :Mutex, :ThreadError, :Fiber, :FiberError, :Rational, :Complex,
|
|
10
|
-
:RUBY_VERSION, :RUBY_RELEASE_DATE, :RUBY_PLATFORM, :RUBY_PATCHLEVEL, :RUBY_REVISION, :RUBY_DESCRIPTION, :RUBY_COPYRIGHT, :RUBY_ENGINE,
|
|
11
|
-
:TracePoint, :ARGV, :Gem, :RbConfig, :Config, :CROSS_COMPILING, :Date, :ConditionVariable, :Queue, :SizedQueue, :MonitorMixin, :Monitor,
|
|
12
|
-
:Exception2MessageMapper, :IRB, :RubyToken, :RubyLex, :Readline, :RUBYGEMS_ACTIVATION_MONITOR
|
|
13
|
-
]
|
data/lib/method_whitelist.rb
DELETED
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
IO_S_METHODS = %w[
|
|
2
|
-
new
|
|
3
|
-
foreach
|
|
4
|
-
open
|
|
5
|
-
]
|
|
6
|
-
|
|
7
|
-
KERNEL_S_METHODS = %w[
|
|
8
|
-
Array
|
|
9
|
-
binding
|
|
10
|
-
block_given?
|
|
11
|
-
catch
|
|
12
|
-
chomp
|
|
13
|
-
chomp!
|
|
14
|
-
chop
|
|
15
|
-
chop!
|
|
16
|
-
eval
|
|
17
|
-
fail
|
|
18
|
-
Float
|
|
19
|
-
format
|
|
20
|
-
global_variables
|
|
21
|
-
gsub
|
|
22
|
-
gsub!
|
|
23
|
-
Integer
|
|
24
|
-
iterator?
|
|
25
|
-
lambda
|
|
26
|
-
local_variables
|
|
27
|
-
loop
|
|
28
|
-
method_missing
|
|
29
|
-
proc
|
|
30
|
-
raise
|
|
31
|
-
scan
|
|
32
|
-
split
|
|
33
|
-
sprintf
|
|
34
|
-
String
|
|
35
|
-
sub
|
|
36
|
-
sub!
|
|
37
|
-
throw
|
|
38
|
-
].freeze
|
|
39
|
-
|
|
40
|
-
SYMBOL_S_METHODS = %w[
|
|
41
|
-
all_symbols
|
|
42
|
-
].freeze
|
|
43
|
-
|
|
44
|
-
STRING_S_METHODS = %w[
|
|
45
|
-
new
|
|
46
|
-
].freeze
|
|
47
|
-
|
|
48
|
-
KERNEL_METHODS = %w[
|
|
49
|
-
==
|
|
50
|
-
|
|
51
|
-
ray
|
|
52
|
-
nding
|
|
53
|
-
ock_given?
|
|
54
|
-
tch
|
|
55
|
-
omp
|
|
56
|
-
omp!
|
|
57
|
-
op
|
|
58
|
-
op!
|
|
59
|
-
ass
|
|
60
|
-
clone
|
|
61
|
-
dup
|
|
62
|
-
eql?
|
|
63
|
-
equal?
|
|
64
|
-
eval
|
|
65
|
-
fail
|
|
66
|
-
Float
|
|
67
|
-
format
|
|
68
|
-
freeze
|
|
69
|
-
frozen?
|
|
70
|
-
global_variables
|
|
71
|
-
gsub
|
|
72
|
-
gsub!
|
|
73
|
-
hash
|
|
74
|
-
id
|
|
75
|
-
initialize_copy
|
|
76
|
-
inspect
|
|
77
|
-
instance_eval
|
|
78
|
-
instance_of?
|
|
79
|
-
instance_variables
|
|
80
|
-
instance_variable_get
|
|
81
|
-
instance_variable_set
|
|
82
|
-
instance_variable_defined?
|
|
83
|
-
Integer
|
|
84
|
-
is_a?
|
|
85
|
-
iterator?
|
|
86
|
-
kind_of?
|
|
87
|
-
lambda
|
|
88
|
-
local_variables
|
|
89
|
-
loop
|
|
90
|
-
methods
|
|
91
|
-
method_missing
|
|
92
|
-
nil?
|
|
93
|
-
private_methods
|
|
94
|
-
print
|
|
95
|
-
proc
|
|
96
|
-
protected_methods
|
|
97
|
-
public_methods
|
|
98
|
-
raise
|
|
99
|
-
remove_instance_variable
|
|
100
|
-
respond_to?
|
|
101
|
-
respond_to_missing?
|
|
102
|
-
scan
|
|
103
|
-
send
|
|
104
|
-
singleton_methods
|
|
105
|
-
singleton_method_added
|
|
106
|
-
singleton_method_removed
|
|
107
|
-
singleton_method_undefined
|
|
108
|
-
split
|
|
109
|
-
sprintf
|
|
110
|
-
String
|
|
111
|
-
sub
|
|
112
|
-
sub!
|
|
113
|
-
taint
|
|
114
|
-
tainted?
|
|
115
|
-
throw
|
|
116
|
-
to_a
|
|
117
|
-
to_s
|
|
118
|
-
type
|
|
119
|
-
untaint
|
|
120
|
-
__send__
|
|
121
|
-
].freeze
|
|
122
|
-
|
|
123
|
-
NILCLASS_METHODS = %w[
|
|
124
|
-
&
|
|
125
|
-
inspect
|
|
126
|
-
nil?
|
|
127
|
-
to_a
|
|
128
|
-
to_f
|
|
129
|
-
to_i
|
|
130
|
-
to_s
|
|
131
|
-
^
|
|
132
|
-
|
|
|
133
|
-
].freeze
|
|
134
|
-
|
|
135
|
-
SYMBOL_METHODS = %w[
|
|
136
|
-
===
|
|
137
|
-
id2name
|
|
138
|
-
inspect
|
|
139
|
-
to_i
|
|
140
|
-
to_int
|
|
141
|
-
to_s
|
|
142
|
-
to_sym
|
|
143
|
-
].freeze
|
|
144
|
-
|
|
145
|
-
TRUECLASS_METHODS = %w[
|
|
146
|
-
&
|
|
147
|
-
to_s
|
|
148
|
-
^
|
|
149
|
-
|
|
|
150
|
-
].freeze
|
|
151
|
-
|
|
152
|
-
FALSECLASS_METHODS = %w[
|
|
153
|
-
&
|
|
154
|
-
to_s
|
|
155
|
-
^
|
|
156
|
-
|
|
|
157
|
-
].freeze
|
|
158
|
-
|
|
159
|
-
ENUMERABLE_METHODS = %w[
|
|
160
|
-
all?
|
|
161
|
-
any?
|
|
162
|
-
collect
|
|
163
|
-
detect
|
|
164
|
-
each_with_index
|
|
165
|
-
entries
|
|
166
|
-
find
|
|
167
|
-
find_all
|
|
168
|
-
grep
|
|
169
|
-
include?
|
|
170
|
-
inject
|
|
171
|
-
map
|
|
172
|
-
max
|
|
173
|
-
member?
|
|
174
|
-
min
|
|
175
|
-
partition
|
|
176
|
-
reject
|
|
177
|
-
select
|
|
178
|
-
sort
|
|
179
|
-
sort_by
|
|
180
|
-
to_a
|
|
181
|
-
zip
|
|
182
|
-
].freeze
|
|
183
|
-
|
|
184
|
-
STRING_METHODS = %w[
|
|
185
|
-
%
|
|
186
|
-
*
|
|
187
|
-
+
|
|
188
|
-
<<
|
|
189
|
-
<=>
|
|
190
|
-
==
|
|
191
|
-
=~
|
|
192
|
-
capitalize
|
|
193
|
-
capitalize!
|
|
194
|
-
casecmp
|
|
195
|
-
center
|
|
196
|
-
chomp
|
|
197
|
-
chomp!
|
|
198
|
-
chop
|
|
199
|
-
chop!
|
|
200
|
-
concat
|
|
201
|
-
count
|
|
202
|
-
crypt
|
|
203
|
-
delete
|
|
204
|
-
delete!
|
|
205
|
-
downcase
|
|
206
|
-
downcase!
|
|
207
|
-
dump
|
|
208
|
-
each
|
|
209
|
-
each_byte
|
|
210
|
-
each_line
|
|
211
|
-
empty?
|
|
212
|
-
eql?
|
|
213
|
-
gsub
|
|
214
|
-
gsub!
|
|
215
|
-
hash
|
|
216
|
-
hex
|
|
217
|
-
include?
|
|
218
|
-
index
|
|
219
|
-
initialize
|
|
220
|
-
initialize_copy
|
|
221
|
-
insert
|
|
222
|
-
inspect
|
|
223
|
-
intern
|
|
224
|
-
length
|
|
225
|
-
ljust
|
|
226
|
-
lines
|
|
227
|
-
lstrip
|
|
228
|
-
lstrip!
|
|
229
|
-
match
|
|
230
|
-
next
|
|
231
|
-
next!
|
|
232
|
-
oct
|
|
233
|
-
replace
|
|
234
|
-
reverse
|
|
235
|
-
reverse!
|
|
236
|
-
rindex
|
|
237
|
-
rjust
|
|
238
|
-
rstrip
|
|
239
|
-
rstrip!
|
|
240
|
-
scan
|
|
241
|
-
size
|
|
242
|
-
slice
|
|
243
|
-
slice!
|
|
244
|
-
split
|
|
245
|
-
squeeze
|
|
246
|
-
squeeze!
|
|
247
|
-
strip
|
|
248
|
-
strip!
|
|
249
|
-
start_with?
|
|
250
|
-
sub
|
|
251
|
-
sub!
|
|
252
|
-
succ
|
|
253
|
-
succ!
|
|
254
|
-
sum
|
|
255
|
-
swapcase
|
|
256
|
-
swapcase!
|
|
257
|
-
to_f
|
|
258
|
-
to_i
|
|
259
|
-
to_s
|
|
260
|
-
to_str
|
|
261
|
-
to_sym
|
|
262
|
-
tr
|
|
263
|
-
tr!
|
|
264
|
-
tr_s
|
|
265
|
-
tr_s!
|
|
266
|
-
upcase
|
|
267
|
-
upcase!
|
|
268
|
-
upto
|
|
269
|
-
[]
|
|
270
|
-
[]=
|
|
271
|
-
].freeze
|