spektr 0.5.6 → 1.0.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +14 -1
- data/lib/spektr/checks/base.rb +1 -0
- data/lib/spektr/checks/file_access.rb +1 -1
- data/lib/spektr/targets/base.rb +13 -0
- data/lib/spektr/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ddcc5f8096643294db83930d7df5cace71619eca037464d68e109ff6f3c9f190
|
|
4
|
+
data.tar.gz: d2a32908dbe7f10b1ee680a62c3442f44e0529b6ea50e3c352451086c5eb7a97
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f0d7a1db5105c0abc1413b81098cb76895b20bf42e94b33087e9c7a87860cbebaa78efd31fa2e569dacbe3c6df71007cc59dfbae7aa755c4ea049a1ce8890bed
|
|
7
|
+
data.tar.gz: d93c5cf94158219882efd1f6c9c756b2324e87d42a4dbd768479ea0ad1580e70a36e9fc74a249cab34e8cf06e20588cf7f4516a605192ec3da7a52dc25994add
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -36,8 +36,21 @@ spektr path/to/app
|
|
|
36
36
|
|
|
37
37
|
To see the available options, you can run `spektr --help`.
|
|
38
38
|
|
|
39
|
-
To ignore
|
|
39
|
+
To ignore findings from the command line, use the `--ignore` flag with a comma-separated list of fingerprints from the report.
|
|
40
40
|
|
|
41
|
+
Findings can also be ignored in source code by placing `# spektr:ignore`, followed by one or more comma-separated check names, on the line immediately above them:
|
|
42
|
+
|
|
43
|
+
Use the check names shown in the report:
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
# spektr:ignore Arbitrary code execution -- input is validated before this method is called
|
|
47
|
+
eval(params[:code])
|
|
48
|
+
|
|
49
|
+
# spektr:ignore Arbitrary code execution, Dangerous send -- both uses are safe
|
|
50
|
+
eval(send(params[:method]))
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The directive only applies to the named checks on the next line; a directive without a check name has no effect. Keeping a reason after `--` is recommended.
|
|
41
54
|
|
|
42
55
|
### Railsgoat Example output
|
|
43
56
|
|
data/lib/spektr/checks/base.rb
CHANGED
|
@@ -28,6 +28,7 @@ module Spektr
|
|
|
28
28
|
def warn!(target, check, location, message, confidence = :high)
|
|
29
29
|
full_path = target.is_a?(String) ? target : target.path
|
|
30
30
|
path = full_path.gsub(@app.root, "")
|
|
31
|
+
return if target.respond_to?(:ignored_at?) && target.ignored_at?(location&.start_line, check)
|
|
31
32
|
return if dupe?(path, location, message)
|
|
32
33
|
|
|
33
34
|
@app.warnings << Warning.new(path, full_path, check, location, message, confidence)
|
|
@@ -16,7 +16,7 @@ module Spektr
|
|
|
16
16
|
def run
|
|
17
17
|
return unless super
|
|
18
18
|
targets = ["Dir", "File", "IO", "Kernel", "Net::FTP", "Net::HTTP", "PStore", "Pathname", "Shell"]
|
|
19
|
-
methods = [:[], :chdir, :chroot, :delete, :entries, :foreach, :glob, :install, :lchmod, :lchown, :link, :load, :load_file, :makedirs, :move, :new, :open, :read, :readlines, :rename, :rmdir, :safe_unlink, :symlink, :syscopy, :sysopen, :truncate, :unlink]
|
|
19
|
+
methods = [:[], :binread, :chdir, :chroot, :delete, :entries, :foreach, :glob, :install, :lchmod, :lchown, :link, :load, :load_file, :makedirs, :move, :new, :open, :read, :readlines, :rename, :rmdir, :safe_unlink, :symlink, :syscopy, :sysopen, :truncate, :unlink]
|
|
20
20
|
targets.each do |target|
|
|
21
21
|
methods.each do |method|
|
|
22
22
|
check_calls_for_user_input(@target.find_calls(method, target.to_sym))
|
data/lib/spektr/targets/base.rb
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
module Spektr
|
|
2
2
|
module Targets
|
|
3
3
|
class Base < Prism::Visitor
|
|
4
|
+
IGNORE_DIRECTIVE = /^\s*#\s*spektr:ignore\s+(.+)$/i
|
|
5
|
+
|
|
4
6
|
attr_accessor :path, :name, :options, :ast, :parent, :parent_modules, :methods, :calls, :interpolated_xstrings, :lvars
|
|
5
7
|
|
|
6
8
|
def initialize(path, content)
|
|
7
9
|
Spektr.logger.debug "loading #{path}"
|
|
10
|
+
@source_lines = content.lines
|
|
8
11
|
@ast = Prism.parse(content)
|
|
9
12
|
@path = path
|
|
10
13
|
return unless @ast
|
|
@@ -20,6 +23,16 @@ module Spektr
|
|
|
20
23
|
@name = @name.prepend("#{@parent_modules.map(&:name).join('::')}::") if @name && @parent_modules.any?
|
|
21
24
|
end
|
|
22
25
|
|
|
26
|
+
def ignored_at?(line_number, check)
|
|
27
|
+
return false unless line_number && line_number > 1
|
|
28
|
+
|
|
29
|
+
directive = @source_lines[line_number - 2]&.match(IGNORE_DIRECTIVE)
|
|
30
|
+
return false unless directive
|
|
31
|
+
|
|
32
|
+
ignored_checks = directive[1].split(/\s+--\s+/, 2).first.split(',').map(&:strip)
|
|
33
|
+
ignored_checks.include?(check.name)
|
|
34
|
+
end
|
|
35
|
+
|
|
23
36
|
def method_definitions
|
|
24
37
|
@method_definitions ||= find_methods(node: @ast)
|
|
25
38
|
end
|
data/lib/spektr/version.rb
CHANGED
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: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Greg Molnar
|
|
@@ -334,7 +334,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
334
334
|
- !ruby/object:Gem::Version
|
|
335
335
|
version: '0'
|
|
336
336
|
requirements: []
|
|
337
|
-
rubygems_version:
|
|
337
|
+
rubygems_version: 4.0.3
|
|
338
338
|
specification_version: 4
|
|
339
339
|
summary: Rails static code analyzer for security issues
|
|
340
340
|
test_files: []
|