brakeman-lib 5.2.0 → 5.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf18736db7a992849a30cccc66f741442e05b695f9ad1bd27fe06f6bc25db849
4
- data.tar.gz: a884f20cc12305c0856bcc296ddae3aea746b024c232bf11d7988d4e37bd96a3
3
+ metadata.gz: 9aadbbfe9251a955f84f5c7d5e317f66386533b90f314e34555a80501a3df153
4
+ data.tar.gz: 4576fc34cceb9269e2daee88b940305590410791a4fc6be2bdc8401f3ae99554
5
5
  SHA512:
6
- metadata.gz: be93f9f9ba9d808989cbed1bfd450b29c272e806d84707ab0420a8a86b8c797f88d4338f22a1124a462be43ac7bfea605566779321a72d772e9c39d216ded8c3
7
- data.tar.gz: cf9aa7f34fa5cc737b2e7bbecf625025b50f72f1b3c43ab8f346832145e3cab2245d2af79fd021584ab0aa5fdbb2f854dd41fee8f5a5c891197f1f1e8a570a65
6
+ metadata.gz: 661e96a6fcc739bc93ef8c605e2fb8dea9ee895fb9121860d225e91717a5ea4108e7d0c57163fb8fe4e119e5f11c75022301293524c3808a323a10e55c087bc7
7
+ data.tar.gz: '0842840bd4735a2411d66ce708876cce60e1bc47cf153affe92bdbcd1f9fd92cf7919c9bd510f78900ce8d994cd9b3b06eaf571f8905c2eb8b60692f0ec529af'
data/CHANGES.md CHANGED
@@ -1,3 +1,20 @@
1
+ # 5.2.3 - 2022-05-01
2
+
3
+ * Fix error with hash shorthand syntax
4
+ * Match order of interactive options with help message (Rory O'Kane)
5
+
6
+ # 5.2.2 - 2022-04-06
7
+
8
+ * Update `ruby_parser` for Ruby 3.1 support (Merek Skubela)
9
+ * Handle `nil` when joining values (Dan Buettner)
10
+ * Update message for unsafe reflection (Pedro Baracho)
11
+ * Add additional String methods for SQL injection check
12
+ * Respect equality in `if` conditions
13
+
14
+ # 5.2.1 - 2022-01-30
15
+
16
+ * Add warning codes for EOL software warnings
17
+
1
18
  # 5.2.0 - 2021-12-15
2
19
 
3
20
  * Initial Rails 7 support
@@ -405,7 +405,8 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
405
405
  nil
406
406
  end
407
407
 
408
- TO_STRING_METHODS = [:chomp, :to_s, :squish, :strip, :strip_heredoc]
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
@@ -744,6 +745,6 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
744
745
  date_target? exp.target
745
746
  else
746
747
  false
747
- end
748
+ end
748
749
  end
749
750
  end
@@ -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
- message = msg("Unsafe reflection method ", msg_code(method), " called with ", msg_input(input))
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",
@@ -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? String
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)
@@ -703,7 +703,30 @@ class Brakeman::AliasProcessor < Brakeman::SexpProcessor
703
703
  end
704
704
  end
705
705
 
706
- exp
706
+ # Return early unless there might be short-hand syntax,
707
+ # since handling it is kind of expensive.
708
+ return exp unless exp.any? { |e| e.nil? }
709
+
710
+ # Need to handle short-hand hash syntax
711
+ new_hash = [:hash]
712
+ hash_iterate(exp) do |key, value|
713
+ # e.g. { a: }
714
+ if value.nil? and symbol? key
715
+ # Only handling local variables for now, not calls
716
+ lvar = s(:lvar, key.value)
717
+ if var_value = env[lvar]
718
+ new_hash << key << var_value.deep_clone(key.line || 0)
719
+ else
720
+ # If the value is unknown, assume it was a call
721
+ # and set the value to a call
722
+ new_hash.concat << key << s(:call, nil, key.value).line(key.line || 0)
723
+ end
724
+ else
725
+ new_hash.concat << key << value
726
+ end
727
+ end
728
+
729
+ Sexp.from_array(new_hash).line(exp.line || 0)
707
730
  end
708
731
 
709
732
  #Merge values into hash when processing
@@ -864,6 +887,9 @@ class Brakeman::AliasProcessor < Brakeman::SexpProcessor
864
887
  elsif false? condition
865
888
  no_branch = true
866
889
  exps = [nil, exp.else_clause]
890
+ elsif equality_check? condition and condition.target == condition.first_arg
891
+ no_branch = true
892
+ exps = [exp.then_clause, nil]
867
893
  else
868
894
  no_branch = false
869
895
  exps = [exp.then_clause, exp.else_clause]
@@ -897,6 +923,14 @@ class Brakeman::AliasProcessor < Brakeman::SexpProcessor
897
923
  env.current[var] = safe_literal(var.line)
898
924
  exp[branch_index] = process_if_branch branch
899
925
  env.current[var] = previous_value
926
+ elsif i == 0 and equality_check? condition
927
+ # For conditions like a == b,
928
+ # set a to b inside the true branch
929
+ var = condition.target
930
+ previous_value = env.current[var]
931
+ env.current[var] = condition.first_arg
932
+ exp[branch_index] = process_if_branch branch
933
+ env.current[var] = previous_value
900
934
  elsif i == 1 and hash_or_array_include_all_literals? condition and early_return? branch
901
935
  var = condition.first_arg
902
936
  env.current[var] = safe_literal(var.line)
@@ -931,6 +965,11 @@ class Brakeman::AliasProcessor < Brakeman::SexpProcessor
931
965
  end
932
966
  end
933
967
 
968
+ def equality_check? exp
969
+ call? exp and
970
+ exp.method == :==
971
+ end
972
+
934
973
  def simple_when? exp
935
974
  node_type? exp[1], :array and
936
975
  not node_type? exp[1][1], :splat, :array and
@@ -88,10 +88,10 @@ module Brakeman
88
88
 
89
89
  m.choice "i"
90
90
  m.choice "n"
91
- m.choice "k"
91
+ m.choice "s"
92
92
  m.choice "u"
93
93
  m.choice "a"
94
- m.choice "s"
94
+ m.choice "k"
95
95
  m.choice "q"
96
96
  m.choice "?" do
97
97
  show_help
@@ -1,3 +1,3 @@
1
1
  module Brakeman
2
- Version = "5.2.0"
2
+ Version = "5.2.3"
3
3
  end
@@ -123,6 +123,8 @@ module Brakeman::WarningCodes
123
123
  :unsafe_method_reflection => 119,
124
124
  :eol_rails => 120,
125
125
  :eol_ruby => 121,
126
+ :pending_eol_rails => 122,
127
+ :pending_eol_ruby => 123,
126
128
 
127
129
  :custom_check => 9090,
128
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.2.0
4
+ version: 5.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Collins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-16 00:00:00.000000000 Z
11
+ date: 2022-05-01 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.18'
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.18'
96
+ version: '3.19'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: ruby_parser-legacy
99
99
  requirement: !ruby/object:Gem::Requirement