spektr 1.0.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ddcc5f8096643294db83930d7df5cace71619eca037464d68e109ff6f3c9f190
4
- data.tar.gz: d2a32908dbe7f10b1ee680a62c3442f44e0529b6ea50e3c352451086c5eb7a97
3
+ metadata.gz: 8a830f6b6b9be5ac380e1cbf4a755b9171b77f9835d9e3f62c5f62c411ba529e
4
+ data.tar.gz: 97a48a8cdaf9d5ab568dcc7d201daf1433b07c1a6043901c300147185ef99dec
5
5
  SHA512:
6
- metadata.gz: f0d7a1db5105c0abc1413b81098cb76895b20bf42e94b33087e9c7a87860cbebaa78efd31fa2e569dacbe3c6df71007cc59dfbae7aa755c4ea049a1ce8890bed
7
- data.tar.gz: d93c5cf94158219882efd1f6c9c756b2324e87d42a4dbd768479ea0ad1580e70a36e9fc74a249cab34e8cf06e20588cf7f4516a605192ec3da7a52dc25994add
6
+ metadata.gz: 162e450e6584062cf616d010401090d8e367041042aca79b3b1a6268948e3a99185bbe08ee4fa1928a13a3a45b9cdd5a05f165a282c4abec47f52e23c059b363
7
+ data.tar.gz: d61db3f6438d1ddcd64564815096beb67007539a543c90a0768423d41ede3bf571ea8acd7d167339ee4dde5074677d49719d0fb14fcebabe9fe9d22bc30b2ac9
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 1.0.1
6
+
7
+ * various nil handling fixes
8
+
5
9
  ## 1.0.0
6
10
 
7
11
  * Add support for ignoring findings from specific checks with a `# spektr:ignore CHECK_NAME` source comment
data/CODE_OF_CONDUCT.md CHANGED
@@ -1,3 +1,3 @@
1
- # Contributor Covenant Code of Conduct
1
+ # Code of Conduct
2
2
 
3
3
  Same as Ruby: [https://www.ruby-lang.org/en/conduct/](https://www.ruby-lang.org/en/conduct/)
@@ -65,7 +65,7 @@ module Spektr
65
65
  end
66
66
  when :keyword_hash_node, :hash_node
67
67
  node.elements.each do |element|
68
- return true if user_input?(element.key)
68
+ return true if element.respond_to?(:key) && user_input?(element.key)
69
69
  return true if user_input?(element.value)
70
70
  end
71
71
  when :array_node
@@ -85,7 +85,7 @@ module Spektr
85
85
  actions.each do |action|
86
86
  next unless action.body
87
87
  action.body.each do |exp|
88
- return true if exp.name == node.name && user_input?(exp)
88
+ return true if exp.respond_to?(:name) && exp.name == node.name && user_input?(exp)
89
89
  end
90
90
  end
91
91
  when :local_variable_read_node
@@ -137,7 +137,7 @@ module Spektr
137
137
  end
138
138
  when :keyword_hash_node, :hash_node
139
139
  node.elements.each do |element|
140
- return true if model_attribute?(element.key)
140
+ return true if element.respond_to?(:key) && model_attribute?(element.key)
141
141
  return true if model_attribute?(element.value)
142
142
  end
143
143
  when :array_node
@@ -176,8 +176,9 @@ module Spektr
176
176
  }
177
177
  end
178
178
  actions.each do |action|
179
+ next unless action.body
179
180
  action.body.each do |exp|
180
- next unless node.respond_to?(:name)
181
+ next unless exp.respond_to?(:name) && node.respond_to?(:name)
181
182
  return model_attribute?(exp.value) if exp.is_a?(Prism::InstanceVariableWriteNode) && exp.name == node.name
182
183
  end
183
184
  end
@@ -34,11 +34,7 @@ module Spektr
34
34
  # TODO: might need to exclude tempfile and ActiveStorage::Filename
35
35
  return if calls.empty?
36
36
  calls.each do |call|
37
- if call.arguments.is_a?(Prism::ArgumentsNode)
38
- argument = call.arguments.arguments.first
39
- else
40
- argument = call.arguments.first
41
- end
37
+ argument = call.arguments.arguments.first if call.arguments.is_a?(Prism::ArgumentsNode)
42
38
  next unless argument
43
39
  if user_input?(argument) || model_attribute?(argument)
44
40
  warn! @target, self, call.location, "Command injection in #{call.name}"
@@ -36,7 +36,7 @@ module Spektr
36
36
  end
37
37
  if argument.is_a?(Prism::KeywordHashNode)
38
38
  argument.elements.each do |element|
39
- if user_input?(element.key)
39
+ if element.respond_to?(:key) && user_input?(element.key)
40
40
  warn! @target, self, call.location, "Unescaped parameter in content_tag at #{element.key.name}"
41
41
  end
42
42
  end
@@ -12,6 +12,7 @@ module Spektr
12
12
  return unless super
13
13
  [:eval, :instance_eval, :class_eval, :module_eval].each do |name|
14
14
  @target.find_calls(name).each do |call|
15
+ next unless call.arguments
15
16
  call.arguments.arguments.each do |argument|
16
17
  if user_input?(argument)
17
18
  warn! @target, self, call.location, "User input in eval"
@@ -11,6 +11,7 @@ module Spektr
11
11
  @ast = Prism.parse(content)
12
12
  @path = path
13
13
  return unless @ast
14
+ @name = ""
14
15
  @parent = ""
15
16
  @parent_modules = []
16
17
  @methods = []
@@ -89,12 +90,12 @@ module Spektr
89
90
  @parent = node.superclass.receiver.name.to_s
90
91
  when Prism::ConstantPathNode, Prism::ConstantReadNode
91
92
  @parent = node.superclass.name.to_s
92
- @parent.prepend("#{node.superclass.parent.name}::") if node.superclass.respond_to?(:parent)
93
- if node.superclass.respond_to?(:parent) && node.superclass.parent.respond_to?(:parent)
93
+ @parent.prepend("#{node.superclass.parent.name}::") if node.superclass.respond_to?(:parent) && node.superclass.parent
94
+ if node.superclass.respond_to?(:parent) && node.superclass.parent.respond_to?(:parent) && node.superclass.parent&.parent
94
95
  @parent.prepend("#{node.superclass.parent.parent.name}::")
95
96
  end
96
97
  end
97
- if node.is_a?(Prism::ClassNode) && node.constant_path && node.constant_path.respond_to?(:parent)
98
+ if node.is_a?(Prism::ClassNode) && node.constant_path && node.constant_path.respond_to?(:parent) && node.constant_path.parent
98
99
  @parent = node.constant_path.parent.name.to_s
99
100
  end
100
101
  @parent = @parent.prepend("#{@parent_modules.map(&:name).join('::')}::") if @parent_modules.any?
@@ -102,7 +103,7 @@ module Spektr
102
103
  end
103
104
 
104
105
  def visit_module_node(node)
105
- @parent_modules << node.constant_path.parent.name if node.constant_path && node.constant_path.respond_to?(:parent)
106
+ @parent_modules << node.constant_path.parent.name if node.constant_path && node.constant_path.respond_to?(:parent) && node.constant_path.parent
106
107
  @parent_modules << node
107
108
  super
108
109
  end
@@ -1,3 +1,3 @@
1
1
  module Spektr
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spektr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Molnar