spektr 0.3.4 → 0.4.0

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: 2cdf9a898d4a20fa90d72e813ccc4436cd4d3c38c5fd1e56c87114f1bf54947e
4
- data.tar.gz: b9fd5966623eca1f37bb8d7bec7a4611a2fcc83e8df8c8a8ef8824cda07a8093
3
+ metadata.gz: 36b0bd72a136d6af28c36ef6c14943fadeb061271abfc152d442754ad2356d0e
4
+ data.tar.gz: a85bb727b8457e55338b842b483cbddd18fe2596412168d7aa9eeef788c403a1
5
5
  SHA512:
6
- metadata.gz: d482d3aa9da794f3fb46705c80773965c996aa740e694ae1e99304bd71cf0627d63962241da296b2473b28a1a43405725ee112433e084703fa1fd2e07914cac9
7
- data.tar.gz: b2732871040b9abc246991e58684b0c09e6228637ee1671d81e90e2db14ce74112ea08945a2215557645060cee0f6aa52cfb33360abef0a99a9411ed2bf3111a
6
+ metadata.gz: 2d8342a2567d22c458cb9316fa6643de595422ae7e3a30d002181de2f2436a8d08c493dedb783aa1d3b8df93d3ab555b7797e427b067c00fcb38191562f62662
7
+ data.tar.gz: 8fc8196c6cf809b44691b88ab7a1b856102d7cba7062b97474beaf97c465d02134721478484127f0b260a1fe1b1bdbaf7497cb29227211974af9a1ecff5cab2d
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.4.0
6
+
7
+ * make XSS check work without a Rails version
8
+ * change parent class extraction to support Structs
9
+ * fix parsing errors
10
+
5
11
  ## 0.3.4
6
12
 
7
13
  * Relax dependencies, to help with using spektr as a gem
@@ -88,7 +88,7 @@ module Spektr
88
88
  next unless child.is_a?(Parser::AST::Node)
89
89
  return true if user_input?(child.type, child.children.last, child)
90
90
  end
91
- when :block, :pair, :hash, :if
91
+ when :block, :pair, :hash, :array, :if, :or
92
92
  ast.children.each do |child|
93
93
  next unless child.is_a?(Parser::AST::Node)
94
94
  return true if user_input?(child.type, child.children.last, child)
@@ -125,7 +125,7 @@ module Spektr
125
125
  return true if _send.receiver && model_names.include?(_send.receiver.name)
126
126
  when :const
127
127
  return true if model_names.include? item.name
128
- when :block, :pair, :hash, :if
128
+ when :block, :pair, :hash, :array, :if, :or
129
129
  item.children.each do |child|
130
130
  next unless child.is_a?(Parser::AST::Node)
131
131
  return true if model_attribute?(child)
@@ -23,6 +23,7 @@ module Spektr
23
23
 
24
24
  def run
25
25
  return unless super
26
+ return unless @app.rails_version
26
27
  calls = @target.find_calls(:content_tag)
27
28
  # https://groups.google.com/d/msg/ruby-security-ann/8B2iV2tPRSE/JkjCJkSoCgAJ
28
29
  cve_2016_6316_check(calls)
@@ -16,13 +16,25 @@ module Spektr::Processors
16
16
  end
17
17
 
18
18
  def parent_name
19
- @parent_parts.shift if @parent_parts.first.to_s == name
20
- @parent_parts.join('::')
19
+ parent_parts.join('::')
20
+ end
21
+
22
+ def parent_parts
23
+ result = @parent_parts.dup
24
+ result.pop if part_matches_self?(result.last.to_s)
25
+ result
26
+ end
27
+
28
+ def part_matches_self?(part)
29
+ (part == name || part_with_module(part) == name)
30
+ end
31
+
32
+ def part_with_module(part)
33
+ (@parent_modules | [part]).join('::')
21
34
  end
22
35
 
23
36
  def parent_name_with_modules
24
- parts = @parent_modules | @parent_parts
25
- parts.shift if parts.first.to_s == name
37
+ parts = @parent_modules | parent_parts
26
38
  parts.join('::')
27
39
  end
28
40
 
@@ -39,17 +51,12 @@ module Spektr::Processors
39
51
  end
40
52
 
41
53
  def extract_parent_parts(node)
42
- if node.children[1] && node.children[1].is_a?(Parser::AST::Node)
43
- node.children[1].children.each do |child|
44
- if child.is_a?(Parser::AST::Node)
45
- extract_parent_parts(child)
46
- @parent_parts << child.children.last
47
- elsif child.is_a? Symbol
48
- @parent_parts << child.to_s
49
- end
54
+ return unless node.is_a?(Parser::AST::Node) && %i[ module class const send].include?(node.type)
55
+ @parent_parts.prepend(node.children.last) if node.type == :const
56
+ if node.children.any?
57
+ node.children.each do |child|
58
+ extract_parent_parts(child)
50
59
  end
51
- elsif node&.children&.first&.children&.last
52
- @parent_parts << node.children.first.children.last
53
60
  end
54
61
  end
55
62
 
@@ -100,9 +100,9 @@ module Spektr
100
100
  Exp::Send.new(ast)
101
101
  when :def
102
102
  Exp::Definition.new(ast)
103
- when :ivasgn
103
+ when :ivasgn, :ivar
104
104
  Exp::Ivasgin.new(ast)
105
- when :lvasign
105
+ when :lvasign, :lvar
106
106
  Exp::Lvasign.new(ast)
107
107
  when :const
108
108
  Exp::Const.new(ast)
@@ -1,3 +1,3 @@
1
1
  module Spektr
2
- VERSION = '0.3.4'
2
+ VERSION = '0.4.0'
3
3
  end
data/lib/spektr.rb CHANGED
@@ -21,7 +21,7 @@ module Spektr
21
21
  pastel = Pastel.new
22
22
  @output_format = output_format
23
23
  start_spinner('Initializing')
24
- if debug
24
+ @log_level = if debug
25
25
  Logger::DEBUG
26
26
  elsif terminal?
27
27
  Logger::ERROR
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spektr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Molnar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-10 00:00:00.000000000 Z
11
+ date: 2023-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubi