brakeman-lib 8.0.6 → 8.1.1
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/CHANGES.md +17 -0
- data/lib/brakeman/app_tree.rb +20 -6
- data/lib/brakeman/checks/base_check.rb +1 -1
- data/lib/brakeman/checks/check_ruby2shell.rb +31 -0
- data/lib/brakeman/checks/check_unscoped_find.rb +9 -8
- data/lib/brakeman/checks/check_validation_regex.rb +3 -2
- data/lib/brakeman/options.rb +2 -2
- data/lib/brakeman/parsers/template_parser.rb +9 -2
- data/lib/brakeman/processors/haml_template_processor.rb +1 -1
- data/lib/brakeman/processors/model_processor.rb +18 -5
- data/lib/brakeman/report/report_sonar.rb +53 -19
- data/lib/brakeman/tracker/config.rb +2 -1
- data/lib/brakeman/version.rb +1 -1
- data/lib/brakeman/warning.rb +1 -2
- data/lib/brakeman/warning_codes.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b4ff198d245bd30c8124d8b854b3226040deba7678d85e677614409378875849
|
|
4
|
+
data.tar.gz: c2a23bb1cb6025654ac8c89da281ac05bb1d541c58b26570222b0eda76ab79c7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 78f5702f794e3af777b76669ce712bfec9c8371bad9161b62fc9e1106fd94c0c3c5959facc67423f33c00fcb5a2c505191f884cbafe4e1f92db397aaa2985910
|
|
7
|
+
data.tar.gz: 6faec03ff212744d9948eeb4fc51f321331b2540598e2248ae5b93614cf577e27cab5610e9b20bca2598dbad97f0e99d6fdb09cc30a024d53b8649738090d317
|
data/CHANGES.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
# 8.1.1 - 2026-11-20
|
|
2
|
+
|
|
3
|
+
* Only skip `UnscopedFind` when all `belongs_to` are optional (Artin Boghosian)
|
|
4
|
+
* Add check for Ruby2Shell/CVE-2026-132825
|
|
5
|
+
|
|
6
|
+
# 8.1.0 - 2026-09-30
|
|
7
|
+
|
|
8
|
+
* Better help and error message for `--ensure-latest`
|
|
9
|
+
* Fix frozen string error (Shai Coleman)
|
|
10
|
+
* Update Sonar report format (fangxing)
|
|
11
|
+
* Fix frozen `src` string error
|
|
12
|
+
* Recognize `Haml::AttributeBuilder.build_class` as an escaped output (Yuriy Tumanov)
|
|
13
|
+
* Include regex code in validation warnings (Eliot Sykes)
|
|
14
|
+
* Check validation regexes in non-activerecord models (Eliot Sykes)
|
|
15
|
+
* Skip top-level vendor directory before recursive globbing (Conor O'Donnell)
|
|
16
|
+
* Support Rails 7.1+ positional enum syntax in SQL injection check (Michael Vogl/Yuriy Tumanov)
|
|
17
|
+
|
|
1
18
|
# 8.0.6 - 2026-08-13
|
|
2
19
|
|
|
3
20
|
* Fix EOL date for Rails 8.0 (yeaseul-kim)
|
data/lib/brakeman/app_tree.rb
CHANGED
|
@@ -64,6 +64,8 @@ module Brakeman
|
|
|
64
64
|
@only_files = init_options[:only_files]
|
|
65
65
|
@additional_libs_path = init_options[:additional_libs_path] || []
|
|
66
66
|
@engine_paths = init_options[:engine_paths] || []
|
|
67
|
+
@additional_libs_path_pairs = @additional_libs_path.map { |p| [p, expand_path(p)] }
|
|
68
|
+
@engine_path_pairs = @engine_paths.map { |p| [p, expand_path(p)] }
|
|
67
69
|
@absolute_engine_paths = @engine_paths.select { |path| path.start_with?(File::SEPARATOR) }
|
|
68
70
|
@relative_engine_paths = @engine_paths - @absolute_engine_paths
|
|
69
71
|
@skip_vendor = init_options[:skip_vendor]
|
|
@@ -194,12 +196,15 @@ module Brakeman
|
|
|
194
196
|
files.uniq.lazy
|
|
195
197
|
else
|
|
196
198
|
if directory == '.'
|
|
197
|
-
pattern = File.join(top_directories_pattern, '**',
|
|
199
|
+
pattern = File.join(top_directories_pattern, '**', '*')
|
|
198
200
|
else
|
|
199
|
-
pattern = "#{root_search_pattern}#{directory}
|
|
201
|
+
pattern = "#{root_search_pattern}#{directory}/**/*"
|
|
200
202
|
end
|
|
201
203
|
|
|
202
|
-
Dir.glob
|
|
204
|
+
# Dir.glob walks the tree again for each alternative in braces,
|
|
205
|
+
# so walk it once and match the extensions on each file name
|
|
206
|
+
file_pattern = "#{name}#{extensions}"
|
|
207
|
+
Dir.glob(pattern).select { |path| File.fnmatch?(file_pattern, File.basename(path), File::FNM_EXTGLOB) }.lazy
|
|
203
208
|
end
|
|
204
209
|
end
|
|
205
210
|
|
|
@@ -251,7 +256,10 @@ module Brakeman
|
|
|
251
256
|
paths.reject do |path|
|
|
252
257
|
relative_path = path.relative
|
|
253
258
|
|
|
254
|
-
if @skip_vendor and
|
|
259
|
+
if @skip_vendor and
|
|
260
|
+
(relative_path == 'vendor' || relative_path.include?('vendor/')) and
|
|
261
|
+
!in_engine_paths?(path) and
|
|
262
|
+
!in_add_libs_paths?(path)
|
|
255
263
|
true
|
|
256
264
|
else
|
|
257
265
|
match_path EXCLUDED_PATHS, path
|
|
@@ -260,11 +268,17 @@ module Brakeman
|
|
|
260
268
|
end
|
|
261
269
|
|
|
262
270
|
def in_engine_paths?(path)
|
|
263
|
-
@
|
|
271
|
+
@engine_path_pairs.any? do |original, expanded|
|
|
272
|
+
path.absolute.include?(original) ||
|
|
273
|
+
expanded.start_with?("#{path.absolute}#{File::SEPARATOR}")
|
|
274
|
+
end
|
|
264
275
|
end
|
|
265
276
|
|
|
266
277
|
def in_add_libs_paths?(path)
|
|
267
|
-
@
|
|
278
|
+
@additional_libs_path_pairs.any? do |original, expanded|
|
|
279
|
+
path.absolute.include?(original) ||
|
|
280
|
+
expanded.start_with?("#{path.absolute}#{File::SEPARATOR}")
|
|
281
|
+
end
|
|
268
282
|
end
|
|
269
283
|
|
|
270
284
|
def match_path files, path
|
|
@@ -470,7 +470,7 @@ class Brakeman::BaseCheck < Brakeman::SexpProcessor
|
|
|
470
470
|
version_between? version, "2.3.18.99", tracker.config.gem_version(:'railslts-version')
|
|
471
471
|
end
|
|
472
472
|
|
|
473
|
-
def version_between? low_version, high_version, current_version =
|
|
473
|
+
def version_between? low_version, high_version, current_version = false
|
|
474
474
|
tracker.config.version_between? low_version, high_version, current_version
|
|
475
475
|
end
|
|
476
476
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'brakeman/checks/base_check'
|
|
2
|
+
|
|
3
|
+
class Brakeman::CheckRuby2Shell < Brakeman::BaseCheck
|
|
4
|
+
Brakeman::Checks.add self
|
|
5
|
+
|
|
6
|
+
@description = 'Check for versions of Ruby vulnerable to Ruby2Shell'
|
|
7
|
+
|
|
8
|
+
def run_check
|
|
9
|
+
ruby_version = tracker.config.ruby_version
|
|
10
|
+
return unless ruby_version
|
|
11
|
+
|
|
12
|
+
fix_version = case
|
|
13
|
+
when version_between?('2.4.0', '3.3.13', ruby_version)
|
|
14
|
+
'3.3.14'
|
|
15
|
+
when version_between?('3.4.0', '3.4.12', ruby_version)
|
|
16
|
+
'3.4.13'
|
|
17
|
+
when version_between?('4.0.0', '4.0.9', ruby_version)
|
|
18
|
+
'4.0.10'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
if fix_version
|
|
22
|
+
warn warning_type: 'Remote Code Execution',
|
|
23
|
+
warning_code: :ruby2shell,
|
|
24
|
+
message: msg(msg_version(ruby_version, 'Ruby'), ' has a critical remote code execution vulnerability ', msg_cve('CVE-2026-132825'), '. Upgrade to ', msg_version(fix_version, 'Ruby'), ' or later'),
|
|
25
|
+
confidence: :high,
|
|
26
|
+
gem_info: gemfile_or_environment('ruby'),
|
|
27
|
+
link: 'https://www.ruby-lang.org/en/news/2026/11/18/multiple-vulnerabilities-in-regexp-and-string/',
|
|
28
|
+
cwe_id: [122, 125, 787]
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -11,7 +11,7 @@ class Brakeman::CheckUnscopedFind < Brakeman::BaseCheck
|
|
|
11
11
|
|
|
12
12
|
associated_model_names = active_record_models.keys.select do |name|
|
|
13
13
|
if belongs_to = active_record_models[name].associations[:belongs_to]
|
|
14
|
-
not
|
|
14
|
+
not all_optional_belongs_to? belongs_to
|
|
15
15
|
else
|
|
16
16
|
false
|
|
17
17
|
end
|
|
@@ -52,15 +52,16 @@ class Brakeman::CheckUnscopedFind < Brakeman::BaseCheck
|
|
|
52
52
|
:cwe_id => [285]
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
-
def
|
|
55
|
+
def all_optional_belongs_to? exp
|
|
56
56
|
return false unless exp.is_a? Array
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return true
|
|
61
|
-
end
|
|
62
|
-
end
|
|
58
|
+
# Arguments from all belongs_to calls are in one array, so split on association names
|
|
59
|
+
associations = exp.slice_before { |e| symbol? e }.select { |args| symbol? args.first }
|
|
63
60
|
|
|
64
|
-
false
|
|
61
|
+
return false if associations.empty?
|
|
62
|
+
|
|
63
|
+
associations.all? do |args|
|
|
64
|
+
args.any? { |e| hash? e and true? hash_access(e, :optional) }
|
|
65
|
+
end
|
|
65
66
|
end
|
|
66
67
|
end
|
|
@@ -16,7 +16,7 @@ class Brakeman::CheckValidationRegex < Brakeman::BaseCheck
|
|
|
16
16
|
FORMAT = Sexp.new(:lit, :format)
|
|
17
17
|
|
|
18
18
|
def run_check
|
|
19
|
-
|
|
19
|
+
tracker.models.each do |name, model|
|
|
20
20
|
@current_model = model
|
|
21
21
|
format_validations = model.options[:validates_format_of]
|
|
22
22
|
|
|
@@ -92,7 +92,8 @@ class Brakeman::CheckValidationRegex < Brakeman::BaseCheck
|
|
|
92
92
|
:message => msg("Insufficient validation for ", msg_code(get_name validator), " using ", msg_code(regex.inspect), ". Use ", msg_code("\\A"), " and ", msg_code("\\z"), " as anchors"),
|
|
93
93
|
:line => value.line,
|
|
94
94
|
:confidence => :high,
|
|
95
|
-
:cwe_id => [777]
|
|
95
|
+
:cwe_id => [777],
|
|
96
|
+
:code => validator
|
|
96
97
|
end
|
|
97
98
|
end
|
|
98
99
|
|
data/lib/brakeman/options.rb
CHANGED
|
@@ -63,9 +63,9 @@ module Brakeman::Options
|
|
|
63
63
|
options[:exit_on_error] = exit_on_error
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
opts.on "--ensure-latest [DAYS]", Integer, "Fail when Brakeman is outdated. Optionally set minimum age in days." do |days|
|
|
66
|
+
opts.on "--ensure-latest [DAYS]", Integer, "Fail when Brakeman is outdated. Optionally set minimum age in days (1-15)." do |days|
|
|
67
67
|
if days and not (1..15).include? days
|
|
68
|
-
raise OptionParser::InvalidArgument
|
|
68
|
+
raise OptionParser::InvalidArgument, "Minimum age must be 1-15 days."
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
options[:ensure_latest] = days || true
|
|
@@ -56,8 +56,15 @@ module Brakeman
|
|
|
56
56
|
else
|
|
57
57
|
ERB.new(text, nil, '-').src
|
|
58
58
|
end
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
|
|
60
|
+
# Encoding comment at the beginning throws off line numbers
|
|
61
|
+
# but the string is frozen in ERB 6.0.2+, so we don't want to
|
|
62
|
+
# unnecessarily duplicate the string
|
|
63
|
+
if src.start_with? '#'
|
|
64
|
+
src.sub(/^#.*\n/, '')
|
|
65
|
+
else
|
|
66
|
+
src
|
|
67
|
+
end
|
|
61
68
|
end
|
|
62
69
|
end
|
|
63
70
|
|
|
@@ -171,7 +171,7 @@ class Brakeman::HamlTemplateProcessor < Brakeman::TemplateProcessor
|
|
|
171
171
|
|
|
172
172
|
def escaped_builder_method? exp
|
|
173
173
|
case exp.method
|
|
174
|
-
when :build, :build_aria, :build_boolean, :build_data, :build_id, :escape_html
|
|
174
|
+
when :build, :build_aria, :build_boolean, :build_class, :build_data, :build_id, :escape_html
|
|
175
175
|
true? exp.first_arg
|
|
176
176
|
else
|
|
177
177
|
false
|
|
@@ -91,12 +91,25 @@ class Brakeman::ModelProcessor < Brakeman::BaseProcessor
|
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
def add_enum_method call
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
if call.second_arg.nil?
|
|
95
|
+
# Rails < 7.1 syntax: enum status: { active: 0, archived: 1 }
|
|
96
|
+
arg = call.first_arg
|
|
97
|
+
return unless hash? arg
|
|
98
|
+
return unless symbol? arg[1]
|
|
99
|
+
|
|
100
|
+
enum_name = arg[1].value # first key
|
|
101
|
+
enums = arg[2] # first value
|
|
102
|
+
else
|
|
103
|
+
# Rails >= 7.1 syntax: enum :status, { active: 0, archived: 1 }
|
|
104
|
+
first_arg = call.first_arg
|
|
105
|
+
second_arg = call.second_arg
|
|
106
|
+
return unless symbol? first_arg
|
|
107
|
+
return unless hash? second_arg or array? second_arg
|
|
108
|
+
|
|
109
|
+
enum_name = first_arg.value
|
|
110
|
+
enums = second_arg
|
|
111
|
+
end
|
|
97
112
|
|
|
98
|
-
enum_name = arg[1].value # first key
|
|
99
|
-
enums = arg[2] # first value
|
|
100
113
|
enums_name = pluralize(enum_name.to_s).to_sym
|
|
101
114
|
|
|
102
115
|
call_line = call.line
|
|
@@ -1,38 +1,72 @@
|
|
|
1
1
|
class Brakeman::Report::Sonar < Brakeman::Report::Base
|
|
2
2
|
def generate_report
|
|
3
|
+
warnings = all_warnings
|
|
3
4
|
report_object = {
|
|
4
|
-
|
|
5
|
+
rules: rules_json(warnings),
|
|
6
|
+
issues: warnings.map { |warning| issue_json(warning) }
|
|
5
7
|
}
|
|
6
|
-
|
|
8
|
+
JSON.pretty_generate report_object
|
|
7
9
|
end
|
|
8
|
-
|
|
10
|
+
|
|
9
11
|
private
|
|
10
|
-
|
|
12
|
+
|
|
13
|
+
def rules_json(warnings)
|
|
14
|
+
warnings
|
|
15
|
+
.each_with_object({}) do |w, unique_warnings|
|
|
16
|
+
unique_warnings[[w.warning_code, w.confidence]] ||= w
|
|
17
|
+
end
|
|
18
|
+
.values
|
|
19
|
+
.map do |w|
|
|
20
|
+
{
|
|
21
|
+
id: rule_id(w),
|
|
22
|
+
name: w.warning_type.to_s,
|
|
23
|
+
description: w.link,
|
|
24
|
+
engineId: "Brakeman",
|
|
25
|
+
cleanCodeAttribute: "TRUSTWORTHY",
|
|
26
|
+
type: "VULNERABILITY",
|
|
27
|
+
severity: rule_severity_for(w.confidence),
|
|
28
|
+
impacts: [
|
|
29
|
+
{
|
|
30
|
+
softwareQuality: "SECURITY",
|
|
31
|
+
severity: impact_severity_for(w.confidence)
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
11
38
|
def issue_json(warning)
|
|
12
39
|
{
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type: "VULNERABILITY",
|
|
16
|
-
severity: severity_level_for(warning.confidence),
|
|
40
|
+
ruleId: rule_id(warning),
|
|
41
|
+
effortMinutes: (4 - warning.confidence) * 15,
|
|
17
42
|
primaryLocation: {
|
|
18
43
|
message: warning.message,
|
|
19
44
|
filePath: warning.file.relative,
|
|
20
45
|
textRange: {
|
|
21
|
-
|
|
22
|
-
|
|
46
|
+
startLine: warning.line || 1,
|
|
47
|
+
endLine: warning.line || 1
|
|
23
48
|
}
|
|
24
|
-
}
|
|
25
|
-
effortMinutes: (4 - warning.confidence) * 15
|
|
49
|
+
}
|
|
26
50
|
}
|
|
27
51
|
end
|
|
28
52
|
|
|
29
|
-
def
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
53
|
+
def rule_id(warning)
|
|
54
|
+
"BRAKEMAN_#{warning.warning_code}_#{rule_severity_for(warning.confidence)}"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def rule_severity_for(confidence)
|
|
58
|
+
case confidence
|
|
59
|
+
when 0 then "CRITICAL"
|
|
60
|
+
when 1 then "MAJOR"
|
|
61
|
+
else "MINOR"
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def impact_severity_for(confidence)
|
|
66
|
+
case confidence
|
|
67
|
+
when 0 then "HIGH"
|
|
68
|
+
when 1 then "MEDIUM"
|
|
69
|
+
else "LOW"
|
|
36
70
|
end
|
|
37
71
|
end
|
|
38
72
|
end
|
|
@@ -149,7 +149,8 @@ module Brakeman
|
|
|
149
149
|
#Returns true if low_version <= RAILS_VERSION <= high_version
|
|
150
150
|
#
|
|
151
151
|
#If the Rails version is unknown, returns false.
|
|
152
|
-
def version_between? low_version, high_version, current_version =
|
|
152
|
+
def version_between? low_version, high_version, current_version = false
|
|
153
|
+
return false if current_version.nil? # protect against accidents
|
|
153
154
|
current_version ||= rails_version
|
|
154
155
|
return false unless current_version
|
|
155
156
|
|
data/lib/brakeman/version.rb
CHANGED
data/lib/brakeman/warning.rb
CHANGED
|
@@ -175,7 +175,7 @@ class Brakeman::Warning
|
|
|
175
175
|
def format_with_user_input strip = true, &block
|
|
176
176
|
if self.user_input
|
|
177
177
|
formatted = Brakeman::OutputProcessor.new.format(code, self.user_input, &block)
|
|
178
|
-
formatted.gsub
|
|
178
|
+
formatted = formatted.gsub(/(\t|\r|\n)+/, " ") if strip
|
|
179
179
|
formatted
|
|
180
180
|
else
|
|
181
181
|
format_code
|
|
@@ -321,4 +321,3 @@ class Brakeman::Warning
|
|
|
321
321
|
formatted
|
|
322
322
|
end
|
|
323
323
|
end
|
|
324
|
-
|
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: 8.
|
|
4
|
+
version: 8.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Justin Collins
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|
|
@@ -340,6 +340,7 @@ files:
|
|
|
340
340
|
- lib/brakeman/checks/check_response_splitting.rb
|
|
341
341
|
- lib/brakeman/checks/check_reverse_tabnabbing.rb
|
|
342
342
|
- lib/brakeman/checks/check_route_dos.rb
|
|
343
|
+
- lib/brakeman/checks/check_ruby2shell.rb
|
|
343
344
|
- lib/brakeman/checks/check_safe_buffer_manipulation.rb
|
|
344
345
|
- lib/brakeman/checks/check_sanitize_config_cve.rb
|
|
345
346
|
- lib/brakeman/checks/check_sanitize_methods.rb
|