ruby_cop 1.0.1 → 1.0.2
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.
- data/README.md +0 -1
- data/lib/ruby_cop/analyzer.rb +6 -0
- data/lib/ruby_cop/policy.rb +2 -0
- data/lib/ruby_cop/version.rb +1 -1
- data/ruby_cop.gemspec +1 -1
- data/spec/analyzer/policy_spec.rb +4 -0
- data/spec/policy_spec.rb +408 -0
- metadata +12 -10
- data/lib/ruby_cop/ruby/version.rb +0 -3
data/README.md
CHANGED
data/lib/ruby_cop/policy.rb
CHANGED
data/lib/ruby_cop/version.rb
CHANGED
data/ruby_cop.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Dray Lacy", "Eric Allam"]
|
10
10
|
s.email = ["dray@envylabs.com", "eric@envylabs.com"]
|
11
|
-
s.homepage = ""
|
11
|
+
s.homepage = "https://github.com/envylabs/RubyCop"
|
12
12
|
s.summary = %q{Statically analyze Ruby and neutralize nefarious code}
|
13
13
|
s.description = %q{Statically analyze Ruby and neutralize nefarious code}
|
14
14
|
|
@@ -57,6 +57,8 @@ describe RubyCop::Policy do
|
|
57
57
|
it { should_not allow('`ls` rescue 1') }
|
58
58
|
it { should_not allow('x rescue `ls`') }
|
59
59
|
it { should_not allow('begin; x; rescue (`ls`; RuntimeError) => err; end') }
|
60
|
+
it { should_not allow(%{begin ; begin ; ":D" ; rescue ; retry ; ensure ; raise ":D" ; end ; rescue ; retry ; end})}
|
61
|
+
it { should_not allow(%{begin ; while(true) ; 'x' ; end ; rescue Exception ; retry ; end}) }
|
60
62
|
end
|
61
63
|
|
62
64
|
context "blocks" do
|
@@ -74,6 +76,7 @@ describe RubyCop::Policy do
|
|
74
76
|
# This is a tricky case where we want to allow methods like
|
75
77
|
# Enumerable#select, but not Kernel#select / IO#select.
|
76
78
|
it { should allow('[1, 2, 3].select { |x| x.odd? }') }
|
79
|
+
it { should_not allow('select([$stdin], nil, nil, 1.5)') }
|
77
80
|
it { pending('Kernel#select') { should_not allow('select([$stdin], nil, nil, 1.5)') } }
|
78
81
|
|
79
82
|
# TODO: these are a possible concern because symbols are not GC'ed and
|
@@ -136,6 +139,7 @@ describe RubyCop::Policy do
|
|
136
139
|
it { should_not allow('trap("EXIT") { }') }
|
137
140
|
it { should_not allow('undef :raise') }
|
138
141
|
it { should_not allow('undef raise') }
|
142
|
+
it { should_not allow(%{''.dup}) }
|
139
143
|
end
|
140
144
|
end
|
141
145
|
|
data/spec/policy_spec.rb
ADDED
@@ -0,0 +1,408 @@
|
|
1
|
+
require 'ruby_cop'
|
2
|
+
|
3
|
+
describe RubyCop::Policy do
|
4
|
+
let(:policy) { described_class.new }
|
5
|
+
subject { policy }
|
6
|
+
|
7
|
+
RSpec::Matchers.define(:allow) do |ruby|
|
8
|
+
match { |policy| RubyCop::NodeBuilder.build(ruby).accept(policy) }
|
9
|
+
end
|
10
|
+
|
11
|
+
context "assignment" do
|
12
|
+
context "class variables" do
|
13
|
+
it { should_not allow('@@x = 1') }
|
14
|
+
it { should_not allow('@@x ||= 1') }
|
15
|
+
it { should_not allow('@@x += 1') }
|
16
|
+
end
|
17
|
+
|
18
|
+
context "constants" do
|
19
|
+
it { should allow('Foo = 1') }
|
20
|
+
it { should allow('Foo::Bar = 1') }
|
21
|
+
it { should allow('::Bar = 1') }
|
22
|
+
|
23
|
+
it { should_not allow('Foo = Kernel') }
|
24
|
+
it { should_not allow('Foo = ::Kernel') }
|
25
|
+
it { should_not allow('Foo = Object::Kernel') }
|
26
|
+
end
|
27
|
+
|
28
|
+
context "globals" do
|
29
|
+
it { should_not allow('$x = 1') }
|
30
|
+
it { should_not allow('$x ||= 1') }
|
31
|
+
it { should_not allow('$x += 1') }
|
32
|
+
end
|
33
|
+
|
34
|
+
context "instance variables" do
|
35
|
+
it { should allow('@x = 1') }
|
36
|
+
it { should allow('@x += 1') }
|
37
|
+
it { should_not allow('@x = $x') }
|
38
|
+
it { should_not allow('@x = @@x') }
|
39
|
+
end
|
40
|
+
|
41
|
+
context "locals" do
|
42
|
+
it { should allow('x = 1') }
|
43
|
+
it { should allow('x ||= 1') }
|
44
|
+
it { should allow('x += 1') }
|
45
|
+
it { should_not allow('x = $x') }
|
46
|
+
it { should_not allow('x = @@x') }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "begin/rescue/ensure" do
|
51
|
+
it { should allow('begin; x; rescue; end') }
|
52
|
+
it { should allow('x rescue 1') }
|
53
|
+
|
54
|
+
it { should_not allow('begin; `ls`; rescue; x; end') }
|
55
|
+
it { should_not allow('begin; x; rescue; `ls`; end') }
|
56
|
+
it { should_not allow('begin; x; rescue; 1; ensure `ls`; end') }
|
57
|
+
it { should_not allow('`ls` rescue 1') }
|
58
|
+
it { should_not allow('x rescue `ls`') }
|
59
|
+
it { should_not allow('begin; x; rescue (`ls`; RuntimeError) => err; end') }
|
60
|
+
it { should_not allow(%{begin ; begin ; ":D" ; rescue ; retry ; ensure ; raise ":D" ; end ; rescue ; retry ; end})}
|
61
|
+
it { should_not allow(%{begin ; while(true) ; 'x' ; end ; rescue Exception ; retry ; end}) }
|
62
|
+
end
|
63
|
+
|
64
|
+
context "blocks" do
|
65
|
+
it { should_not allow('->(a = $x) { }') }
|
66
|
+
it { should_not allow('->(a) { $x }') }
|
67
|
+
it { should_not allow('lambda { $x }') }
|
68
|
+
it { should_not allow('proc { $x }') }
|
69
|
+
end
|
70
|
+
|
71
|
+
context "calls" do
|
72
|
+
it { should allow('foo { 1 }') }
|
73
|
+
it { should_not allow('foo { $x }') }
|
74
|
+
|
75
|
+
context "blacklist" do
|
76
|
+
# This is a tricky case where we want to allow methods like
|
77
|
+
# Enumerable#select, but not Kernel#select / IO#select.
|
78
|
+
it { should allow('[1, 2, 3].select { |x| x.odd? }') }
|
79
|
+
it { should_not allow('select([$stdin], nil, nil, 1.5)') }
|
80
|
+
|
81
|
+
# TODO: these are a possible concern because symbols are not GC'ed and
|
82
|
+
# an attacker could create a large number of them to eat up memory. If
|
83
|
+
# these methods are blacklisted, then dyna-symbols (:"foo#{x}") need to
|
84
|
+
# be restricted as well.
|
85
|
+
it { should allow('"abc".intern') }
|
86
|
+
it { should allow('"abc".to_sym') }
|
87
|
+
|
88
|
+
it { should_not allow('abort("fail")') }
|
89
|
+
it { should_not allow('alias :foo :bar') }
|
90
|
+
it { should_not allow('alias foo bar') }
|
91
|
+
it { should_not allow('alias_method(:foo, :bar)') }
|
92
|
+
it { should_not allow('at_exit { puts "Bye!" }')}
|
93
|
+
it { should_not allow('autoload(:Foo, "foo")') }
|
94
|
+
it { should_not allow('binding') }
|
95
|
+
it { should_not allow('binding()') }
|
96
|
+
it { should_not allow('callcc { |cont| }') }
|
97
|
+
it { should_not allow('caller') }
|
98
|
+
it { should_not allow('caller()') }
|
99
|
+
it { should_not allow('caller(1)') }
|
100
|
+
it { should_not allow('class_eval("$x = 1")') }
|
101
|
+
it { should_not allow('const_get(:Kernel)') }
|
102
|
+
it { should_not allow('const_set(:Foo, ::Kernel)') }
|
103
|
+
it { should_not allow('eval("`ls`")') }
|
104
|
+
it { should_not allow('exec("ls")') }
|
105
|
+
it { should_not allow('exit') }
|
106
|
+
it { should_not allow('exit()') }
|
107
|
+
it { should_not allow('fail') }
|
108
|
+
it { should_not allow('fail("failed")') }
|
109
|
+
it { should_not allow('fail()') }
|
110
|
+
it { should_not allow('fork { }') }
|
111
|
+
it { should_not allow('fork') }
|
112
|
+
it { should_not allow('fork()') }
|
113
|
+
it { should_not allow('gets') }
|
114
|
+
it { should_not allow('gets()') }
|
115
|
+
it { should_not allow('global_variables') }
|
116
|
+
it { should_not allow('global_variables()') }
|
117
|
+
it { should_not allow('load("foo")') }
|
118
|
+
it { should_not allow('loop { }') }
|
119
|
+
it { should_not allow('method(:eval)') }
|
120
|
+
it { should_not allow('module_eval("`ls`")') }
|
121
|
+
it { should_not allow('open("/etc/passwd")') }
|
122
|
+
it { should_not allow('readline') }
|
123
|
+
it { should_not allow('readline()') }
|
124
|
+
it { should_not allow('readlines') }
|
125
|
+
it { should_not allow('readlines()') }
|
126
|
+
it { should_not allow('redo') }
|
127
|
+
it { should_not allow('remove_const(:Kernel)') }
|
128
|
+
it { should_not allow('require("digest/md5")') }
|
129
|
+
it { should_not allow('send(:eval, "`ls`")') }
|
130
|
+
it { should_not allow('set_trace_func(proc { |event,file,line,id,binding,classname| })') }
|
131
|
+
it { should_not allow('sleep(100**100)') }
|
132
|
+
it { should_not allow('spawn("ls", :chdir => "/")') }
|
133
|
+
it { should_not allow('srand') }
|
134
|
+
it { should_not allow('srand()') }
|
135
|
+
it { should_not allow('srand(1)') }
|
136
|
+
it { should_not allow('syscall(4, 1, "hello\n", 6)') }
|
137
|
+
it { should_not allow('system("ls")') }
|
138
|
+
it { should_not allow('trap("EXIT") { }') }
|
139
|
+
it { should_not allow('undef :raise') }
|
140
|
+
it { should_not allow('undef raise') }
|
141
|
+
it { should_not allow(%{''.dup})}
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context "case" do
|
146
|
+
it { should allow('case x; when 1; 2; end') }
|
147
|
+
|
148
|
+
it { should_not allow('case $x; when 1; 2; end') }
|
149
|
+
it { should_not allow('case $x = 1; when 1; 2; end') }
|
150
|
+
it { should_not allow('case x; when $x; 2; end') }
|
151
|
+
it { should_not allow('case x; when 1; $x; end') }
|
152
|
+
end
|
153
|
+
|
154
|
+
context "class / module definition" do
|
155
|
+
it { should allow("class Foo\nend") }
|
156
|
+
it { should allow("class Foo::Bar\nend") }
|
157
|
+
|
158
|
+
it { should allow("module Foo\nend") }
|
159
|
+
it { should allow("module Foo::Bar\nend") }
|
160
|
+
it { should_not allow("module Kernel\nend") }
|
161
|
+
it { should_not allow("module ::Kernel\nend") }
|
162
|
+
end
|
163
|
+
|
164
|
+
context "defined?" do
|
165
|
+
it { should_not allow('defined?(Kernel)') }
|
166
|
+
end
|
167
|
+
|
168
|
+
context "dynamic strings" do
|
169
|
+
it { should_not allow('"abc#{`ls`}"') }
|
170
|
+
it { should_not allow('"#{`ls`}abc"') }
|
171
|
+
it { should_not allow('"#$0"') }
|
172
|
+
end
|
173
|
+
|
174
|
+
context "dynamic symbols" do
|
175
|
+
it { should_not allow(':"abc#{`ls`}"') }
|
176
|
+
it { should_not allow(':"#{`ls`}abc"') }
|
177
|
+
end
|
178
|
+
|
179
|
+
context "for" do
|
180
|
+
it { should_not allow('for i in ENV; puts i; end') }
|
181
|
+
it { should_not allow('for $x in [1, 2, 3]; puts $x; end') }
|
182
|
+
end
|
183
|
+
|
184
|
+
context "if/elsif/else" do
|
185
|
+
it { should allow('x if true') }
|
186
|
+
|
187
|
+
it { should_not allow('$x ? 1 : 2') }
|
188
|
+
it { should_not allow('true ? $x : 2') }
|
189
|
+
it { should_not allow('true ? 1 : $x') }
|
190
|
+
it { should_not allow('if $x; 1; end') }
|
191
|
+
it { should_not allow('if true; $x; end') }
|
192
|
+
it { should_not allow('$x if true') }
|
193
|
+
it { should_not allow('true if $x') }
|
194
|
+
it { should_not allow('if $x; 1; else 2; end') }
|
195
|
+
it { should_not allow('if 1; $x; else 2; end') }
|
196
|
+
it { should_not allow('if 1; 1; else $x; end') }
|
197
|
+
it { should_not allow('if 1; 1; elsif 2; 2; else $x; end') }
|
198
|
+
end
|
199
|
+
|
200
|
+
context "literals" do
|
201
|
+
it { should allow('"abc"') }
|
202
|
+
it { should allow('/abc/') }
|
203
|
+
it { should allow('1') }
|
204
|
+
it { should allow('1..2') }
|
205
|
+
it { should allow('1.2') }
|
206
|
+
it { should allow('false') }
|
207
|
+
it { should allow('nil') }
|
208
|
+
it { should allow('true') }
|
209
|
+
it { should allow('[]') }
|
210
|
+
it { should allow('[1,2,3]') }
|
211
|
+
it { should allow('{}') }
|
212
|
+
it { should allow('{1 => 2}') }
|
213
|
+
end
|
214
|
+
|
215
|
+
context "magic variables" do
|
216
|
+
it { should_not allow('__callee__') }
|
217
|
+
it { should_not allow('__FILE__') }
|
218
|
+
it { should_not allow('__method__') }
|
219
|
+
end
|
220
|
+
|
221
|
+
context "methods" do
|
222
|
+
it { should allow('def initialize(attributes={}); end') }
|
223
|
+
end
|
224
|
+
|
225
|
+
context "singleton class" do
|
226
|
+
it { should_not allow('class << Kernel; end') }
|
227
|
+
it { should_not allow('class << Kernel; `ls`; end') }
|
228
|
+
end
|
229
|
+
|
230
|
+
context "super" do
|
231
|
+
it { should allow('super') }
|
232
|
+
it { should allow('super()') }
|
233
|
+
it { should allow('super(1)') }
|
234
|
+
it { should_not allow('super($x)') }
|
235
|
+
end
|
236
|
+
|
237
|
+
context "system" do
|
238
|
+
it { should_not allow('`ls`') }
|
239
|
+
it { should_not allow('%x[ls]') }
|
240
|
+
it { should_not allow('system("ls")') }
|
241
|
+
end
|
242
|
+
|
243
|
+
context "unless" do
|
244
|
+
it { should_not allow('unless $x; 1; end') }
|
245
|
+
it { should_not allow('unless true; $x; end') }
|
246
|
+
it { should_not allow('$x unless true') }
|
247
|
+
it { should_not allow('true unless $x') }
|
248
|
+
it { should_not allow('unless $x; 1; else 2; end') }
|
249
|
+
it { should_not allow('unless 1; $x; else 2; end') }
|
250
|
+
it { should_not allow('unless 1; 1; else $x; end') }
|
251
|
+
end
|
252
|
+
|
253
|
+
context "until" do
|
254
|
+
it { should_not allow('true until false') }
|
255
|
+
end
|
256
|
+
|
257
|
+
context "while" do
|
258
|
+
it { should_not allow('true while true') }
|
259
|
+
end
|
260
|
+
|
261
|
+
context "yield" do
|
262
|
+
it { should allow('def foo; yield; end') }
|
263
|
+
end
|
264
|
+
|
265
|
+
context "Rails for Zombies" do
|
266
|
+
before(:each) do
|
267
|
+
policy.whitelist_const('GenericController')
|
268
|
+
policy.whitelist_const('Tweet')
|
269
|
+
policy.whitelist_const('Weapon')
|
270
|
+
policy.whitelist_const('Zombie')
|
271
|
+
policy.whitelist_const('ZombiesController')
|
272
|
+
end
|
273
|
+
|
274
|
+
[
|
275
|
+
"1 = Ash\nAsh = Glen Haven Memorial Cemetary",
|
276
|
+
"<% zombies = Zombie.all %>\n\n<ul>\n <% zombies.each do |zombie| %>\n <li>\n <%= zombie.name %>\n <% if zombie.Tweet >= 1 %>\n <p><%= SMART ZOMBIE =%></p>\n <% end %>\n </li>\n <% end %>\n</ul>\n",
|
277
|
+
"class HelloRils",
|
278
|
+
"Class NAme\n\nend",
|
279
|
+
"class tweet < ActiveRecord::Base\n belongs_to :zombie \n z = zombie.find(2)\nend",
|
280
|
+
"class zombie < ActiveRecord :: Base\n\nend\n",
|
281
|
+
"Class Zombie < ActiveRecord::Base\n validates_presence_of :name\nend",
|
282
|
+
"Class Zombie < ActiveRecord::Base\nend",
|
283
|
+
"Class Zombie < ActiveRecord::Base\nvalidates_presence_of :status\nvalidates_presence_of :ww\nend",
|
284
|
+
"Class Zombie < ActiveRecord::Base{\ndef name\ndef graveyard\n\n}\n",
|
285
|
+
"class zombie < ActiveRecord\nend class",
|
286
|
+
"Class Zombie <ActiveRecord :: Base\n\nend\n\n\n",
|
287
|
+
"Class Zombie <ActiveRecord::Base>\nvalidates_presence_of\nend",
|
288
|
+
"class.load(Zombie)",
|
289
|
+
"Poop = Zombie.find(:id=1)",
|
290
|
+
"SELECT * WHERE ID = 1;",
|
291
|
+
"String myNewZombie = select name from Zombies where id=1",
|
292
|
+
"w = Weapon.find(1)\nZombie.create( :Weapon => \"Hammer\", Zombie => 1)\nend\n",
|
293
|
+
"Zodfsdsfdsdfsz=Zombies.find()1\n"
|
294
|
+
].each do |error|
|
295
|
+
it "raises SyntaxError on #{error.inspect}" do
|
296
|
+
expect { RubyCop::NodeBuilder.build(error) }.to raise_error(SyntaxError)
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
[
|
301
|
+
"1\nZombie = 1\n",
|
302
|
+
"A = t.find(1)\n\n\n\n",
|
303
|
+
"Ash = 1\n",
|
304
|
+
"Ash = 1\n\n",
|
305
|
+
"Ash = Weapons.find.zombie_id(1)",
|
306
|
+
"Ash = Zombie.find(1)\nAsh.weapons.count",
|
307
|
+
"class Com\n\nhasmany dog\n\nend",
|
308
|
+
"class Finder < Tweet\n z = Tweet.find(1)\nend",
|
309
|
+
"class Post < ActiveRecord::Base\nend",
|
310
|
+
"class Weapons < ActiveRecord::Base\n belongs_to :Zombies\nend\n\nclass Zombies < ActiveRecord::Base\n has_many :Weapons\nend",
|
311
|
+
"Class Zombie < ActiveRecord::Base\n\nEnd",
|
312
|
+
"class Zombie < Rails::ActiveModel\n \nend",
|
313
|
+
"Class Zombie {\n validates :name, :presence => true\n}",
|
314
|
+
"Class Zombies < ActiveRecord::Base\nEnd",
|
315
|
+
"class ZombiesController < ApplicationController\n before_filter :find_zombie, :only => [:show]\n\n def show\n render :action => :show\n end\n\n def find_zombie\n @zombie = Zombie.find params[:id]\n @numTweets = Tweet.where(:zombie_id => @zombie).count\n if @numTweets < 1 \n redirect_to(zombies_path)\n end\n end\nend\n",
|
316
|
+
"class Zomvie <ActiveRecord::Base\nhas_many:Zombies\nend\n",
|
317
|
+
"class Zoombie < ActiveRecord::Base\nend\nz = Zoombie.last",
|
318
|
+
"class Zoombie\nend\nZoombie.create(:name => \"Jim\", :graveyard=> \"My Fathers Basement\")",
|
319
|
+
"cuntZombie=Zombies[1];",
|
320
|
+
"def create\n @newZombie = Zombie.create( :name => params[:name], :graveyard => params[:graveyard] )\n \n render action => :create\nend\n",
|
321
|
+
"Destroy Zombie where ID = 3",
|
322
|
+
"Find.Tweet.id = (1)\nZombie = Tweet.id",
|
323
|
+
"firstZombie = Zombies[id '1']\n",
|
324
|
+
"First_user = initialuser\n",
|
325
|
+
"Hash tag + lik",
|
326
|
+
"Hold = Tweets.find 1",
|
327
|
+
"jh = new Zombie()\njh.name = \"JHDI\"\njh.graveYard = \"JHDI cemetary\"\njh.save",
|
328
|
+
"Location = puts graveyard.Ash",
|
329
|
+
"newZombie = Zombie.new\nnewZombie.name = \"Craig\"\nnewZombie.graveyard = \"my cube\"\nnewZombie.save",
|
330
|
+
"newZombie = Zombie.new\nnewZombie['name'] = \"Renan\"\nnewZombie['graveyard'] = \"Lavras Cemetary\"\nnewZombie.save\n",
|
331
|
+
"newZombie = Zombies.new\nnewZombie.id = 4\nnewZombie.name = \"Arek\"\nnewZombie.graveyard = \"Centralny cmentarz komunalny\"\nnewZombie.save",
|
332
|
+
"newZombie=Zombie.new {}\nnewZombie.name = \"Manish\"\nnewZombie.graveyard = \"Shillong Bastards Cemetary\"",
|
333
|
+
"numeroUno = Zombie(1).name;\n",
|
334
|
+
"splatid = id.find(1)\nsplatName = splatid[:name]",
|
335
|
+
"t = new Tweet();\nminTweet == t.find(3);",
|
336
|
+
"t = Tweet.find(1)\nZombie = t.id",
|
337
|
+
"T = Zombie.find(3)\nT.graveyard = 'Benny Hills Memorial'\nT.save",
|
338
|
+
"t = Zombie.find(3)\nt.Zombie = \"Benny Hills Memorial\"\nt.save\n",
|
339
|
+
"T = Zombie.where(1)\nputs t.name\n",
|
340
|
+
"t= \nt.Name=\"Hello\"\nt.Graveyard=\"yes\"\nt.save",
|
341
|
+
"t=Zombie.find(3)\nt.Zombie = \"pucho\"",
|
342
|
+
"T=Zombie[1]\n",
|
343
|
+
"Ticket = Tweet.find(1)",
|
344
|
+
"Tweet = new Tweet;\na = Tweet.find(1);\n",
|
345
|
+
"Tweet = new Tweet\nt = Tweet.where(:id => 1)\n",
|
346
|
+
"Tweet = t\nt.zombie = 1",
|
347
|
+
"Tweet.find(1)\nZombie1 = tweet(1)",
|
348
|
+
"Tweet=id1\n",
|
349
|
+
"UPDATE Zombies\nSET name='vijay',graveyard='Ahmedabad'\nWhere Id='2';\n",
|
350
|
+
"w = Weapon.create(:name => \"Punto\", :Zombie => z)\nash = Zombie.find(1)",
|
351
|
+
"z = ID=1",
|
352
|
+
"Z = Zombie.find(1)\n",
|
353
|
+
"z = Zombie.find(1)\nWeapon.where( :Zombie => z )",
|
354
|
+
"z = Zombie.find(1)\nZombie1 = z.name",
|
355
|
+
"Z = Zombie.find(1)\n\n\n\n\n",
|
356
|
+
"Z = Zombie.find(3)",
|
357
|
+
"Z = zombie.id(1)",
|
358
|
+
"z = Zombie.new\nz.name = \"Charly\"\nz.Graveyard = \"EL carlos\"",
|
359
|
+
"Z=Zombie.new\nz.find(1)",
|
360
|
+
"Zombie = new Zombie",
|
361
|
+
"Zombie = Tweet.find(1)",
|
362
|
+
"Zombie = Zombie.find(Weapons.find(:zombie_id))",
|
363
|
+
"Zombie = Zombie.find[1]",
|
364
|
+
"Zombie = Zombies.find(1)",
|
365
|
+
"Zombie3=Zombie.find(3)\nZombie3.graveyard = \"Benny Hills Memorial\"\nZombie3.save",
|
366
|
+
"Zombies = '123456'",
|
367
|
+
"Zombies = id \nZombies.create( :name=>\"roger\" )",
|
368
|
+
"Zombies = Zombies.find(1)\nput Zombies",
|
369
|
+
"Zombies = {:Ash => \"Glen Haven mernorial Cemetary\"}\nvar = Zombies.find(1)\nvar.save\n\n",
|
370
|
+
"Zombies = {:name => [\"Ash\", \"Bob\", \"Jim\"], :graveyard => [\"Glen Haven Memorial Cemetary\",\"Chapel Hill Cemetary\",\"My Fathers Basement\"] }\na = z.find(1)",
|
371
|
+
"Zombies = {\n :id => 1 }\nt = zombie.find(1)",
|
372
|
+
"Zombies.find(1)\nputs Zombies.find(1)\nZ=Zombies.find(1)\nZ.lat=[:id]\nz.save\nz\n",
|
373
|
+
"zoombieID = table.find(1)\n",
|
374
|
+
'class << Zombie; self; end',
|
375
|
+
'myZombie = Tweet.find(1)',
|
376
|
+
'Zombie.create(:name => "Whoa. A Green String")',
|
377
|
+
'Zombie.create(name: "Fal", graveyard: "fail")',
|
378
|
+
].each do |good|
|
379
|
+
it "allows #{good.inspect}" do
|
380
|
+
should allow(good)
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
[
|
385
|
+
"Class",
|
386
|
+
"def show\n @zombie = Zombie.find(params[:id])\n\n respond_to do |format|\n `ls`\n end\nend\n",
|
387
|
+
"Module.delete(3)",
|
388
|
+
"Module.find(\"Ash\")",
|
389
|
+
"require 'tweet'\nt = Tweet.find(1)",
|
390
|
+
"require 'Tweet'\nTweet.find(2).name\n",
|
391
|
+
"require \"tempfile\"\nt = Zombies.new('Zombies')\nZombies.where(:id => 1)\nt.save",
|
392
|
+
"system('ls')",
|
393
|
+
"t = Zombies.open()",
|
394
|
+
"Tweet.find(1)\nDim var as String\nvar=Tweet.name",
|
395
|
+
"Zombie.load(1)\n\n",
|
396
|
+
"`echo 1`",
|
397
|
+
"`ls -l`",
|
398
|
+
"`ps ax`\n",
|
399
|
+
"`uname -a`",
|
400
|
+
'const_get',
|
401
|
+
'const_get()'
|
402
|
+
].each do |bad|
|
403
|
+
it "does not allow #{bad.inspect}" do
|
404
|
+
should_not allow(bad)
|
405
|
+
end
|
406
|
+
end
|
407
|
+
end
|
408
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_cop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2012-02-20 00:00:00.000000000Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: geminabox
|
17
|
-
requirement: &
|
17
|
+
requirement: &70301443701120 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70301443701120
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rspec
|
28
|
-
requirement: &
|
28
|
+
requirement: &70301443700620 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 2.3.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70301443700620
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: yard
|
39
|
-
requirement: &
|
39
|
+
requirement: &70301443700200 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70301443700200
|
48
48
|
description: Statically analyze Ruby and neutralize nefarious code
|
49
49
|
email:
|
50
50
|
- dray@envylabs.com
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- README.md
|
59
59
|
- Rakefile
|
60
60
|
- lib/ruby_cop.rb
|
61
|
+
- lib/ruby_cop/analyzer.rb
|
61
62
|
- lib/ruby_cop/gray_list.rb
|
62
63
|
- lib/ruby_cop/node_builder.rb
|
63
64
|
- lib/ruby_cop/policy.rb
|
@@ -84,16 +85,16 @@ files:
|
|
84
85
|
- lib/ruby_cop/ruby/string.rb
|
85
86
|
- lib/ruby_cop/ruby/tokens.rb
|
86
87
|
- lib/ruby_cop/ruby/variables.rb
|
87
|
-
- lib/ruby_cop/ruby/version.rb
|
88
88
|
- lib/ruby_cop/ruby/while.rb
|
89
89
|
- lib/ruby_cop/version.rb
|
90
90
|
- ruby_cop.gemspec
|
91
91
|
- spec/analyzer/node_builder_spec.rb
|
92
92
|
- spec/analyzer/policy_spec.rb
|
93
|
+
- spec/policy_spec.rb
|
93
94
|
- spec/spec_helper.rb
|
94
95
|
- tasks/rspec.rake
|
95
96
|
- tasks/yard.rake
|
96
|
-
homepage:
|
97
|
+
homepage: https://github.com/envylabs/RubyCop
|
97
98
|
licenses: []
|
98
99
|
post_install_message:
|
99
100
|
rdoc_options: []
|
@@ -113,11 +114,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
114
|
version: '0'
|
114
115
|
requirements: []
|
115
116
|
rubyforge_project: ruby_cop
|
116
|
-
rubygems_version: 1.8.
|
117
|
+
rubygems_version: 1.8.17
|
117
118
|
signing_key:
|
118
119
|
specification_version: 3
|
119
120
|
summary: Statically analyze Ruby and neutralize nefarious code
|
120
121
|
test_files:
|
121
122
|
- spec/analyzer/node_builder_spec.rb
|
122
123
|
- spec/analyzer/policy_spec.rb
|
124
|
+
- spec/policy_spec.rb
|
123
125
|
- spec/spec_helper.rb
|