brakeman-lib 5.1.2 → 5.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +21 -0
- data/lib/brakeman/checks/base_check.rb +10 -0
- data/lib/brakeman/checks/check_eol_rails.rb +23 -0
- data/lib/brakeman/checks/check_eol_ruby.rb +26 -0
- data/lib/brakeman/checks/check_sql.rb +6 -4
- data/lib/brakeman/checks/check_symbol_dos.rb +1 -1
- data/lib/brakeman/checks/check_unsafe_reflection.rb +7 -2
- data/lib/brakeman/checks/eol_check.rb +47 -0
- data/lib/brakeman/options.rb +8 -0
- data/lib/brakeman/processors/alias_processor.rb +17 -1
- data/lib/brakeman/processors/gem_processor.rb +3 -0
- data/lib/brakeman/processors/lib/rails3_route_processor.rb +2 -0
- data/lib/brakeman/scanner.rb +3 -1
- data/lib/brakeman/tracker/config.rb +8 -1
- data/lib/brakeman/version.rb +1 -1
- data/lib/brakeman/warning_codes.rb +4 -0
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45b4ed913efc8767851fa736f69591dad0bd6c26eb2b9c6f84e71acef92670ce
|
4
|
+
data.tar.gz: b40f9ee9b0dbd2187e071609193b3df891dd6e462bd3de572ce4a335db063185
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8966515fb503515fb38a7581061a72464b81a6bcf86b99c58711dbbb88b636b87b5e74a09190b53cd7c09ea1674458bfe874698416c4928dbf44eb46bc234221
|
7
|
+
data.tar.gz: ca7309e4b30e14213b1e697e33113737ee8c2da1d6997f6e28c0a68df965dcd348c9b7c7a4bbe285e7dc7356b7c6fceb2171b13aae92338d02d4e5ef4992c9a4
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
# 5.2.2 - 2022-04-06
|
2
|
+
|
3
|
+
* Update `ruby_parser` for Ruby 3.1 support (Merek Skubela)
|
4
|
+
* Handle `nil` when joining values (Dan Buettner)
|
5
|
+
* Update message for unsafe reflection (Pedro Baracho)
|
6
|
+
* Add additional String methods for SQL injection check
|
7
|
+
* Respect equality in `if` conditions
|
8
|
+
|
9
|
+
# 5.2.1 - 2022-01-30
|
10
|
+
|
11
|
+
* Add warning codes for EOL software warnings
|
12
|
+
|
13
|
+
# 5.2.0 - 2021-12-15
|
14
|
+
|
15
|
+
* Initial Rails 7 support
|
16
|
+
* Require Ruby 2.5.0+
|
17
|
+
* Fix issue with calls to `foo.root` in routes
|
18
|
+
* Ignore `I18n.locale` in SQL queries
|
19
|
+
* Do not treat `sanitize_sql_like` as safe
|
20
|
+
* Add new checks for unsupported Ruby and Rails versions
|
21
|
+
|
1
22
|
# 5.1.2 - 2021-10-28
|
2
23
|
|
3
24
|
* Handle cases where enums are not symbols
|
@@ -513,4 +513,14 @@ class Brakeman::BaseCheck < Brakeman::SexpProcessor
|
|
513
513
|
string_building? exp.target or
|
514
514
|
string_building? exp.first_arg
|
515
515
|
end
|
516
|
+
|
517
|
+
I18N_CLASS = s(:const, :I18n)
|
518
|
+
|
519
|
+
def locale_call? exp
|
520
|
+
return unless call? exp
|
521
|
+
|
522
|
+
(exp.target == I18N_CLASS and
|
523
|
+
exp.method == :locale) or
|
524
|
+
locale_call? exp.target
|
525
|
+
end
|
516
526
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'eol_check'
|
2
|
+
|
3
|
+
class Brakeman::CheckEOLRails < Brakeman::EOLCheck
|
4
|
+
Brakeman::Checks.add self
|
5
|
+
|
6
|
+
@description = "Checks for unsupported versions of Rails"
|
7
|
+
|
8
|
+
def run_check
|
9
|
+
return unless tracker.config.rails_version
|
10
|
+
|
11
|
+
check_eol_version :rails, RAILS_EOL_DATES
|
12
|
+
end
|
13
|
+
|
14
|
+
RAILS_EOL_DATES = {
|
15
|
+
['2.0.0', '2.3.99'] => Date.new(2013, 6, 25),
|
16
|
+
['3.0.0', '3.2.99'] => Date.new(2016, 6, 30),
|
17
|
+
['4.0.0', '4.2.99'] => Date.new(2017, 4, 27),
|
18
|
+
['5.0.0', '5.0.99'] => Date.new(2018, 5, 9),
|
19
|
+
['5.1.0', '5.1.99'] => Date.new(2019, 8, 25),
|
20
|
+
['5.2.0', '5.2.99'] => Date.new(2022, 6, 1),
|
21
|
+
['6.0.0', '6.0.99'] => Date.new(2023, 6, 1),
|
22
|
+
}
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'eol_check'
|
2
|
+
|
3
|
+
class Brakeman::CheckEOLRuby < Brakeman::EOLCheck
|
4
|
+
Brakeman::Checks.add self
|
5
|
+
|
6
|
+
@description = "Checks for unsupported versions of Ruby"
|
7
|
+
|
8
|
+
def run_check
|
9
|
+
return unless tracker.config.ruby_version
|
10
|
+
|
11
|
+
check_eol_version :ruby, RUBY_EOL_DATES
|
12
|
+
end
|
13
|
+
|
14
|
+
RUBY_EOL_DATES = {
|
15
|
+
['0.0.0', '1.9.3'] => Date.new(2015, 2, 23),
|
16
|
+
['2.0.0', '2.0.99'] => Date.new(2016, 2, 24),
|
17
|
+
['2.1.0', '2.1.99'] => Date.new(2017, 3, 31),
|
18
|
+
['2.2.0', '2.2.99'] => Date.new(2018, 3, 31),
|
19
|
+
['2.3.0', '2.3.99'] => Date.new(2019, 3, 31),
|
20
|
+
['2.4.0', '2.4.99'] => Date.new(2020, 3, 31),
|
21
|
+
['2.5.0', '2.5.99'] => Date.new(2021, 3, 31),
|
22
|
+
['2.6.0', '2.6.99'] => Date.new(2022, 3, 31),
|
23
|
+
['2.7.0', '2.7.99'] => Date.new(2023, 3, 31),
|
24
|
+
['3.0.0', '2.8.99'] => Date.new(2024, 3, 31),
|
25
|
+
}
|
26
|
+
end
|
@@ -405,7 +405,8 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
|
|
405
405
|
nil
|
406
406
|
end
|
407
407
|
|
408
|
-
TO_STRING_METHODS = [:chomp, :
|
408
|
+
TO_STRING_METHODS = [:chomp, :chop, :lstrip, :rstrip, :scrub, :squish, :strip,
|
409
|
+
:strip_heredoc, :to_s, :tr]
|
409
410
|
|
410
411
|
#Returns value if interpolated value is not something safe
|
411
412
|
def unsafe_string_interp? exp
|
@@ -584,7 +585,7 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
|
|
584
585
|
end
|
585
586
|
|
586
587
|
IGNORE_METHODS_IN_SQL = Set[:id, :merge_conditions, :table_name, :quoted_table_name,
|
587
|
-
:quoted_primary_key, :to_i, :to_f, :sanitize_sql, :sanitize_sql_array,
|
588
|
+
:quoted_primary_key, :to_i, :to_f, :sanitize_sql, :sanitize_sql_array,
|
588
589
|
:sanitize_sql_for_assignment, :sanitize_sql_for_conditions, :sanitize_sql_hash,
|
589
590
|
:sanitize_sql_hash_for_assignment, :sanitize_sql_hash_for_conditions,
|
590
591
|
:to_sql, :sanitize, :primary_key, :table_name_prefix, :table_name_suffix,
|
@@ -628,7 +629,8 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
|
|
628
629
|
arel? exp or
|
629
630
|
exp.method.to_s.end_with? "_id" or
|
630
631
|
number_target? exp or
|
631
|
-
date_target? exp
|
632
|
+
date_target? exp or
|
633
|
+
locale_call? exp
|
632
634
|
end
|
633
635
|
|
634
636
|
QUOTE_METHODS = [:quote, :quote_column_name, :quoted_date, :quote_string, :quote_table_name]
|
@@ -743,6 +745,6 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
|
|
743
745
|
date_target? exp.target
|
744
746
|
else
|
745
747
|
false
|
746
|
-
end
|
748
|
+
end
|
747
749
|
end
|
748
750
|
end
|
@@ -9,7 +9,7 @@ class Brakeman::CheckSymbolDoS < Brakeman::BaseCheck
|
|
9
9
|
|
10
10
|
def run_check
|
11
11
|
return if rails_version and rails_version >= "5.0.0"
|
12
|
-
return if tracker.config.ruby_version >= "2.2"
|
12
|
+
return if tracker.config.ruby_version and tracker.config.ruby_version >= "2.2"
|
13
13
|
|
14
14
|
tracker.find_call(:methods => UNSAFE_METHODS, :nested => true).each do |result|
|
15
15
|
check_unsafe_symbol_creation(result)
|
@@ -20,7 +20,7 @@ class Brakeman::CheckUnsafeReflection < Brakeman::BaseCheck
|
|
20
20
|
def check_unsafe_reflection result
|
21
21
|
return unless original? result
|
22
22
|
|
23
|
-
call = result[:call]
|
23
|
+
call = result[:call]
|
24
24
|
method = call.method
|
25
25
|
|
26
26
|
case method
|
@@ -37,7 +37,12 @@ class Brakeman::CheckUnsafeReflection < Brakeman::BaseCheck
|
|
37
37
|
end
|
38
38
|
|
39
39
|
if confidence
|
40
|
-
|
40
|
+
case method
|
41
|
+
when :constantize, :safe_constantize
|
42
|
+
message = msg("Unsafe reflection method ", msg_code(method), " called on ", msg_input(input))
|
43
|
+
else
|
44
|
+
message = msg("Unsafe reflection method ", msg_code(method), " called with ", msg_input(input))
|
45
|
+
end
|
41
46
|
|
42
47
|
warn :result => result,
|
43
48
|
:warning_type => "Remote Code Execution",
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'brakeman/checks/base_check'
|
3
|
+
|
4
|
+
# Not used directly - base check for EOLRails and EOLRuby
|
5
|
+
class Brakeman::EOLCheck < Brakeman::BaseCheck
|
6
|
+
def check_eol_version library, eol_dates
|
7
|
+
version = case library
|
8
|
+
when :rails
|
9
|
+
tracker.config.rails_version
|
10
|
+
when :ruby
|
11
|
+
tracker.config.ruby_version
|
12
|
+
else
|
13
|
+
raise 'Implement using tracker.config.gem_version'
|
14
|
+
end
|
15
|
+
|
16
|
+
eol_dates.each do |(start_version, end_version), eol_date|
|
17
|
+
if version_between? start_version, end_version, version
|
18
|
+
case
|
19
|
+
when Date.today >= eol_date
|
20
|
+
warn_about_unsupported_version library, eol_date, version
|
21
|
+
when (Date.today + 30) >= eol_date
|
22
|
+
warn_about_soon_unsupported_version library, eol_date, version, :medium
|
23
|
+
when (Date.today + 60) >= eol_date
|
24
|
+
warn_about_soon_unsupported_version library, eol_date, version, :low
|
25
|
+
end
|
26
|
+
|
27
|
+
break
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def warn_about_soon_unsupported_version library, eol_date, version, confidence
|
33
|
+
warn warning_type: 'Unmaintained Dependency',
|
34
|
+
warning_code: :"pending_eol_#{library}",
|
35
|
+
message: msg("Support for ", msg_version(version, library.capitalize), " ends on #{eol_date}"),
|
36
|
+
confidence: confidence,
|
37
|
+
gem_info: gemfile_or_environment
|
38
|
+
end
|
39
|
+
|
40
|
+
def warn_about_unsupported_version library, eol_date, version
|
41
|
+
warn warning_type: 'Unmaintained Dependency',
|
42
|
+
warning_code: :"eol_#{library}",
|
43
|
+
message: msg("Support for ", msg_version(version, library.capitalize), " ended on #{eol_date}"),
|
44
|
+
confidence: :high,
|
45
|
+
gem_info: gemfile_or_environment
|
46
|
+
end
|
47
|
+
end
|
data/lib/brakeman/options.rb
CHANGED
@@ -93,6 +93,14 @@ module Brakeman::Options
|
|
93
93
|
options[:rails6] = true
|
94
94
|
end
|
95
95
|
|
96
|
+
opts.on "-7", "--rails7", "Force Rails 7 mode" do
|
97
|
+
options[:rails3] = true
|
98
|
+
options[:rails4] = true
|
99
|
+
options[:rails5] = true
|
100
|
+
options[:rails6] = true
|
101
|
+
options[:rails7] = true
|
102
|
+
end
|
103
|
+
|
96
104
|
opts.separator ""
|
97
105
|
opts.separator "Scanning options:"
|
98
106
|
|
@@ -404,7 +404,7 @@ class Brakeman::AliasProcessor < Brakeman::SexpProcessor
|
|
404
404
|
end
|
405
405
|
|
406
406
|
def join_item item, join_value
|
407
|
-
if item.is_a?
|
407
|
+
if item.nil? || item.is_a?(String)
|
408
408
|
"#{item}#{join_value}"
|
409
409
|
elsif string? item or symbol? item or number? item
|
410
410
|
s(:str, "#{item.value}#{join_value}").line(item.line)
|
@@ -864,6 +864,9 @@ class Brakeman::AliasProcessor < Brakeman::SexpProcessor
|
|
864
864
|
elsif false? condition
|
865
865
|
no_branch = true
|
866
866
|
exps = [nil, exp.else_clause]
|
867
|
+
elsif equality_check? condition and condition.target == condition.first_arg
|
868
|
+
no_branch = true
|
869
|
+
exps = [exp.then_clause, nil]
|
867
870
|
else
|
868
871
|
no_branch = false
|
869
872
|
exps = [exp.then_clause, exp.else_clause]
|
@@ -897,6 +900,14 @@ class Brakeman::AliasProcessor < Brakeman::SexpProcessor
|
|
897
900
|
env.current[var] = safe_literal(var.line)
|
898
901
|
exp[branch_index] = process_if_branch branch
|
899
902
|
env.current[var] = previous_value
|
903
|
+
elsif i == 0 and equality_check? condition
|
904
|
+
# For conditions like a == b,
|
905
|
+
# set a to b inside the true branch
|
906
|
+
var = condition.target
|
907
|
+
previous_value = env.current[var]
|
908
|
+
env.current[var] = condition.first_arg
|
909
|
+
exp[branch_index] = process_if_branch branch
|
910
|
+
env.current[var] = previous_value
|
900
911
|
elsif i == 1 and hash_or_array_include_all_literals? condition and early_return? branch
|
901
912
|
var = condition.first_arg
|
902
913
|
env.current[var] = safe_literal(var.line)
|
@@ -931,6 +942,11 @@ class Brakeman::AliasProcessor < Brakeman::SexpProcessor
|
|
931
942
|
end
|
932
943
|
end
|
933
944
|
|
945
|
+
def equality_check? exp
|
946
|
+
call? exp and
|
947
|
+
exp.method == :==
|
948
|
+
end
|
949
|
+
|
934
950
|
def simple_when? exp
|
935
951
|
node_type? exp[1], :array and
|
936
952
|
not node_type? exp[1][1], :splat, :array and
|
@@ -6,6 +6,7 @@ class Brakeman::GemProcessor < Brakeman::BasicProcessor
|
|
6
6
|
def initialize *args
|
7
7
|
super
|
8
8
|
@gem_name_version = /^\s*([-_+.A-Za-z0-9]+) \((\w(\.\w+)*)\)/
|
9
|
+
@ruby_version = /^\s+ruby (\d\.\d.\d+)/
|
9
10
|
end
|
10
11
|
|
11
12
|
def process_gems gem_files
|
@@ -95,6 +96,8 @@ class Brakeman::GemProcessor < Brakeman::BasicProcessor
|
|
95
96
|
def set_gem_version_and_file line, file, line_num
|
96
97
|
if line =~ @gem_name_version
|
97
98
|
@tracker.config.add_gem $1, $2, file, line_num
|
99
|
+
elsif line =~ @ruby_version
|
100
|
+
@tracker.config.set_ruby_version $1
|
98
101
|
end
|
99
102
|
end
|
100
103
|
end
|
@@ -78,6 +78,8 @@ class Brakeman::Rails3RoutesProcessor < Brakeman::BasicProcessor
|
|
78
78
|
|
79
79
|
#TODO: Need test for this
|
80
80
|
def process_root exp
|
81
|
+
return exp unless hash? exp.first_arg
|
82
|
+
|
81
83
|
if value = hash_access(exp.first_arg, :to)
|
82
84
|
if string? value
|
83
85
|
add_route_from_string value
|
data/lib/brakeman/scanner.rb
CHANGED
@@ -137,7 +137,9 @@ class Brakeman::Scanner
|
|
137
137
|
end
|
138
138
|
|
139
139
|
if @app_tree.exists? ".ruby-version"
|
140
|
-
|
140
|
+
if version = @app_tree.file_path(".ruby-version").read[/(\d\.\d.\d+)/]
|
141
|
+
tracker.config.set_ruby_version version
|
142
|
+
end
|
141
143
|
end
|
142
144
|
|
143
145
|
tracker.config.load_rails_defaults
|
@@ -14,7 +14,7 @@ module Brakeman
|
|
14
14
|
@settings = {}
|
15
15
|
@escape_html = nil
|
16
16
|
@erubis = nil
|
17
|
-
@ruby_version =
|
17
|
+
@ruby_version = nil
|
18
18
|
@rails_version = nil
|
19
19
|
end
|
20
20
|
|
@@ -106,6 +106,13 @@ module Brakeman
|
|
106
106
|
tracker.options[:rails5] = true
|
107
107
|
tracker.options[:rails6] = true
|
108
108
|
Brakeman.notify "[Notice] Detected Rails 6 application"
|
109
|
+
elsif @rails_version.start_with? "7"
|
110
|
+
tracker.options[:rails3] = true
|
111
|
+
tracker.options[:rails4] = true
|
112
|
+
tracker.options[:rails5] = true
|
113
|
+
tracker.options[:rails6] = true
|
114
|
+
tracker.options[:rails7] = true
|
115
|
+
Brakeman.notify "[Notice] Detected Rails 7 application"
|
109
116
|
end
|
110
117
|
end
|
111
118
|
end
|
data/lib/brakeman/version.rb
CHANGED
@@ -121,6 +121,10 @@ module Brakeman::WarningCodes
|
|
121
121
|
:erb_template_injection => 117,
|
122
122
|
:http_verb_confusion => 118,
|
123
123
|
:unsafe_method_reflection => 119,
|
124
|
+
:eol_rails => 120,
|
125
|
+
:eol_ruby => 121,
|
126
|
+
:pending_eol_rails => 122,
|
127
|
+
:pending_eol_ruby => 123,
|
124
128
|
|
125
129
|
:custom_check => 9090,
|
126
130
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brakeman-lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Collins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '3.
|
89
|
+
version: '3.19'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '3.
|
96
|
+
version: '3.19'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: ruby_parser-legacy
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -271,6 +271,8 @@ files:
|
|
271
271
|
- lib/brakeman/checks/check_digest_dos.rb
|
272
272
|
- lib/brakeman/checks/check_divide_by_zero.rb
|
273
273
|
- lib/brakeman/checks/check_dynamic_finders.rb
|
274
|
+
- lib/brakeman/checks/check_eol_rails.rb
|
275
|
+
- lib/brakeman/checks/check_eol_ruby.rb
|
274
276
|
- lib/brakeman/checks/check_escape_function.rb
|
275
277
|
- lib/brakeman/checks/check_evaluation.rb
|
276
278
|
- lib/brakeman/checks/check_execute.rb
|
@@ -337,6 +339,7 @@ files:
|
|
337
339
|
- lib/brakeman/checks/check_without_protection.rb
|
338
340
|
- lib/brakeman/checks/check_xml_dos.rb
|
339
341
|
- lib/brakeman/checks/check_yaml_parsing.rb
|
342
|
+
- lib/brakeman/checks/eol_check.rb
|
340
343
|
- lib/brakeman/codeclimate/engine_configuration.rb
|
341
344
|
- lib/brakeman/commandline.rb
|
342
345
|
- lib/brakeman/differ.rb
|
@@ -452,7 +455,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
452
455
|
requirements:
|
453
456
|
- - ">="
|
454
457
|
- !ruby/object:Gem::Version
|
455
|
-
version: 2.
|
458
|
+
version: 2.5.0
|
456
459
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
457
460
|
requirements:
|
458
461
|
- - ">="
|