-
-
Notifications
You must be signed in to change notification settings - Fork 226
/
text.rb
116 lines (97 loc) · 3.18 KB
/
text.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#
# Copyright (c) 2013-2020 Hal Brodigan (postmodern.mod3 at gmail.com)
#
# bundler-audit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# bundler-audit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with bundler-audit. If not, see <http://www.gnu.org/licenses/>.
#
require 'thor'
module Bundler
module Audit
class CLI < ::Thor
module Formats
module Text
#
# Prints any findings as plain-text.
#
# @param [Report] report
# The results from the {Scanner}.
#
# @param [IO, File] output
# Optional output stream.
#
def print_report(report,output=$stdout)
original_stdout = $stdout
$stdout = output
report.each do |result|
case result
when Results::InsecureSource
print_warning "Insecure Source URI found: #{result.source}"
when Results::UnpatchedGem
print_advisory result.gem, result.advisory
end
end
if report.vulnerable?
say "Vulnerabilities found!", :red
else
say("No vulnerabilities found", :green) unless options.quiet?
end
$stdout = original_stdout
end
private
def print_warning(message)
say message, :yellow
end
def print_advisory(gem, advisory)
say "Name: ", :red
say gem.name
say "Version: ", :red
say gem.version
say "Advisory: ", :red
if advisory.cve
say "CVE-#{advisory.cve}"
elsif advisory.osvdb
say advisory.osvdb
end
say "Criticality: ", :red
case advisory.criticality
when :low then say "Low"
when :medium then say "Medium", :yellow
when :high then say "High", [:red, :bold]
else say "Unknown"
end
say "URL: ", :red
say advisory.url
if options.verbose?
say "Description:", :red
say
print_wrapped advisory.description, :indent => 2
say
else
say "Title: ", :red
say advisory.title
end
unless advisory.patched_versions.empty?
say "Solution: upgrade to ", :red
say advisory.patched_versions.join(', ')
else
say "Solution: ", :red
say "remove or disable this gem until a patch is available!", [:red, :bold]
end
say
end
end
Formats.register :text, Text
end
end
end
end