| 1 | package App::WebPerimeterScan::Findings; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 28 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 28 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 28 | ▶ | use autodie qw(:all); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 28 | ▶ | use Params::Get qw(get_params); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 28 | ▶ | use Params::Validate::Strict qw(validate_strict); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 28 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 28 | ▶ | use Scalar::Util qw(refaddr); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 28 | ▶ | use Sub::Private { mode => 'enforce' }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 28 | ▶ | use App::WebPerimeterScan::I18N (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 28 | ▶ | use parent -norequire, 'App::WebPerimeterScan::I18N'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 28 | our $VERSION = '0.001.0'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # Worst first. Exported by name because the report formats walk it. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 28 | Readonly::Array our @SEVERITIES => qw(critical high medium low info); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # Every field a finding carries, in report order. The JSON report uses the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # same list, so the two can never disagree about what a finding is. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 28 | Readonly::Array our @FIELDS => qw(id severity host url title detail evidence fix reference file source); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # Numeric rank of each severity, for sorting and thresholds. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 28 | Readonly::Hash my %RANK => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | critical => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | high => 4, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | medium => 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | low => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | info => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # What an unknown or missing severity becomes, and the id of a finding that | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # was added without one. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 28 | Readonly::Scalar my $DEFAULT_SEVERITY => 'info'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 28 | Readonly::Scalar my $DEFAULT_ID => 'finding'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # Fields annotate() may change after a finding is recorded: the source-aware | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # pass fills them in once the whole scan is known. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 28 | Readonly::Hash my %ANNOTATABLE => (file => 1, source => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # Joins the parts of a de-duplication key. NUL cannot occur in any of them. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 28 | Readonly::Scalar my $KEY_SEPARATOR => "\0"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # Input schema for add(); report() accepts the same keys minus the text. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 28 | Readonly::Hash my %ADD_SCHEMA => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | id => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | severity => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | host => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | url => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | key => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | title => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | detail => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | evidence => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | fix => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | reference => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | file => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | source => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | App::WebPerimeterScan::Findings - collect and order scan results | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | Version 0.001.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | Record a finding whose text comes from the message catalogue. This is what | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | the scanner's own rules do: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | use App::WebPerimeterScan::Findings; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | my $findings = App::WebPerimeterScan::Findings->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | $findings->report('csp-missing', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | severity => 'medium', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | host => 'example.com', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | vars => { url => 'https://example.com/' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | Record a finding with your own text, for example from a site-specific | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | check that has no catalogue entry: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | $findings->add( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | id => 'staging-banner', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | severity => 'low', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | host => 'example.com', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | title => 'The staging banner is visible in production', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | fix => 'Remove the banner from the production template.', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | Print a summary, worst finding first: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | printf "%d finding(s), %d medium\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | $findings->count, $findings->counts->{medium}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | for my $finding (@{ $findings->sorted }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | print "$finding->{severity} $finding->{title}\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | Use the findings as a gate in a deployment script: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | my $serious = $findings->at_or_above('high'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | if(@{$serious}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | print STDERR scalar(@{$serious}), " serious finding(s); stopping\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | exit 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | This module holds the results of a scan. Each result is called a | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | I<finding>: one problem, on one host, with a severity, a title and advice | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | on how to fix it. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | The collection does two jobs: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | =item * It removes duplicates. Two findings are the same when they have | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | the same rule id, host, URL and C<key>. The second one is ignored. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | =item * It sorts. The worst severity comes first. Findings with the same | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | severity are sorted by host, then by title, then by URL. The order is | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | always the same, so the reports from two runs can be compared line by line. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | Each finding is a hash reference. It has every field named in | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | C<@App::WebPerimeterScan::Findings::FIELDS>, and every field is a string. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | A field that does not apply is the empty string, never C<undef>, so code | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | that reads a finding never has to test for C<undef>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | The severities, from worst to least, are C<critical>, C<high>, C<medium>, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | C<low> and C<info>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | =head1 SUBROUTINES/METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | Purpose: create an empty collection. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | Args: none. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | Returns: the new object. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | Side Effects: none. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | Usage: C<< my $findings = App::WebPerimeterScan::Findings->new; >> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | my $findings = App::WebPerimeterScan::Findings->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | print $findings->count, "\n"; # 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | {} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | { type => 'object', isa => 'App::WebPerimeterScan::Findings' } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | Message Meaning / resolution | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | ------------------------------- ----------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | Unknown parameter 'X' new() takes no arguments. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 64 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 64 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # No arguments are accepted; an unknown one croaks. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 64 | ▶ | validate_strict(schema => {}, input => get_params(undef, \@_) // {}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
get_params(undef, \@_) // {}
MC/DC100%1/1
get_params(undef, \@_) // {}
get_params(undef, \@_)
Truth table100%2/2
A
A= get_params(undef, \@_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 63 | return bless { items => [], seen => {} }, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | =head2 add | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | Purpose: record one finding with its text already rendered. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | Args: named: C<id>, C<severity> (one of C<@SEVERITIES>), C<host>, C<url>, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | C<key> (an extra de-duplication component, not stored), C<title>, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | C<detail>, C<evidence>, C<fix>, C<reference>, C<file>, C<source>. All are | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | optional strings. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | Returns: 1 if the finding was recorded, 0 if it duplicated one already held. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | Side Effects: appends to the collection. An unknown severity is recorded as | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | C<info> with a warning, so a typo cannot silently hide a finding below the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | C<--fail-on> threshold without anyone noticing. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | Usage: C<< $findings->add(id => 'x', severity => 'low', title => 'X') >> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | my $added = $findings->add( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | id => 'trace-enabled', severity => 'medium', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | host => 'example.com', url => 'https://example.com/', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | title => 'HTTP TRACE is enabled', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # A second identical call returns 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | id => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | severity => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | host => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | url => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | key => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | title => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | detail => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | evidence => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | fix => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | reference => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | file => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | source => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | { type => 'integer', memberof => [ 0, 1 ] } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | Message Meaning / resolution | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | ----------------------------------------- ------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | Unknown severity 'S' for finding 'I'; The severity is not one of | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | recorded as info (warning) critical/high/medium/low/info. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | Unknown parameter 'X' (fatal) A misspelt argument name. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | =head3 PSEUDOCODE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | validate the arguments | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | default the id; warn and default an unknown severity to info | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | build the de-duplication key from id, host, url and key | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | return 0 if the key has been seen | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | store every field, empty string where not given | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | return 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | sub add | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 294 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=9 SCAR=22.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 294 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 294 | ▶ | my $args = validate_strict(schema => \%ADD_SCHEMA, input => get_params(undef, \@_) // {}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
get_params(undef, \@_) // {}
MC/DC0%0/1
get_params(undef, \@_) // {}
get_params(undef, \@_)
Truth table50%1/2
A
A= get_params(undef, \@_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 294 | ▶ | my $id = $args->{id} // $DEFAULT_ID; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args->{"id"} // $DEFAULT_ID
MC/DC0%0/2
$args->{"id"} // $DEFAULT_ID
$args->{"id"}
$DEFAULT_ID
Truth table33%1/3
A // B
A= $args->{"id"}B= $DEFAULT_ID
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 294 | ▶ | my $severity = $args->{severity} // $DEFAULT_SEVERITY; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args->{"severity"} // $DEFAULT_SEVERITY
MC/DC0%0/2
$args->{"severity"} // $DEFAULT_SEVERITY
$args->{"severity"}
$DEFAULT_SEVERITY
Truth table33%1/3
A // B
A= $args->{"severity"}B= $DEFAULT_SEVERITY
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 294 | ▶ | unless(exists $RANK{$severity}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | $self->_warn('findings.unknown_severity', { severity => $severity, id => $id }); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | $severity = $DEFAULT_SEVERITY; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # The same id on the same host/url/key is one finding, however many | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # pages or probes produced it. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 294 | ▶ | my $dedupe = join $KEY_SEPARATOR, $id, map { $args->{$_} // '' } qw(host url key); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{$_} // ""
MC/DC100%1/1
$args->{$_} // ""
$args->{$_}
Truth table100%2/2
A
A= $args->{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 294 | ▶ | return 0 if $self->{seen}{$dedupe}++; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # Every field is present and a string, so the report formats never | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # have to test for undef. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 287 | ▶ | my %finding = map { $_ => $args->{$_} // '' } @FIELDS; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{$_} // ""
MC/DC100%1/1
$args->{$_} // ""
$args->{$_}
Truth table100%2/2
A
A= $args->{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 287 | @finding{qw(id severity)} = ($id, $severity); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 287 | ▶ | $finding{title} = $id unless length $finding{title}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 287 | push @{ $self->{items} }, \%finding; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 287 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | =head2 report | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | Purpose: record a finding whose text comes from the message catalogue, so a | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | rule only states its id, severity and the values that vary. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | Args: C<$id> (the rule id), then named: C<severity>, C<host>, C<url>, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | C<key>, C<reference>, C<vars> (hashref of placeholder values), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | C<evidence> (raw evidence; overrides the C<.evidence> template), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | C<message> (the catalogue base key, when it differs from C<$id> - for | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | example C<port-open> for C<port-open-3306>) and C<rule> (a hash reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | with default C<severity> and C<reference>, overridden by those arguments). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | Returns: as C<add>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | Side Effects: as C<add>. C<confess>es if the catalogue has no C<.title> or | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | C<.detail> for the rule. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | Usage: C<< $findings->report('tls-expired', severity => 'high', host => $h, vars => { days => 3 }) >> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | $findings->report('port-open-3306', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | message => 'port-open', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | severity => 'high', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | host => 'db.example.com', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | vars => { port => 3306, has_banner => 'no' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | id => { type => 'string', min => 1, position => 0 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | severity => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | host => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | url => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | key => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | reference => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | evidence => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | message => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | vars => { type => 'hashref', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | rule => { type => 'hashref', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | { type => 'integer', memberof => [ 0, 1 ] } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | Message Meaning / resolution | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | ----------------------------------- ----------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | No message is defined for "K" The rule has no catalogue text; add | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | (fatal, with stack trace) K to App::WebPerimeterScan::Messages. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | sub report | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 289 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
report: called CC=9 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 289 | my ($self, $id, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 289 | ▶ | my $args = validate_strict( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
get_params(undef, \@rest) // {}
MC/DC0%0/1
get_params(undef, \@rest) // {}
get_params(undef, \@rest)
Truth table50%1/2
A
A= get_params(undef, \@rest)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | schema => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | severity => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | host => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | url => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | key => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | reference => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | evidence => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | message => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | vars => { type => 'hashref', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | rule => { type => 'hashref', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | input => get_params(undef, \@rest) // {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 289 | ▶ | my $base = $args->{message} // $id; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args->{"message"} // $id
MC/DC0%0/2
$args->{"message"} // $id
$args->{"message"}
$id
Truth table66%2/3
A // B
A= $args->{"message"}B= $id
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 289 | ▶ | my $vars = $args->{vars} // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{"vars"} // {}
MC/DC100%1/1
$args->{"vars"} // {}
$args->{"vars"}
Truth table100%2/2
A
A= $args->{"vars"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # A rule table supplies the usual severity and reference; an explicit | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | # argument wins, for rules whose severity depends on what was found. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 289 | ▶ | my $rule = $args->{rule} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{'rule'} || {}
MC/DC100%1/1
$args->{'rule'} || {}
$args->{'rule'}
Truth table100%2/2
A
A= $args->{'rule'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 289 | ▶ | $args->{$_} //= $rule->{$_} for qw(severity reference); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$args->{$_} //= $rule->{$_}
MC/DC100%2/2
$args->{$_} //= $rule->{$_}
$args->{$_}
$rule->{$_}
Truth table100%3/3
A //= B
A= $args->{$_}B= $rule->{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | # Evidence that was captured (a banner, a body excerpt) is data and is | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | # passed raw; evidence that is a sentence comes from the catalogue. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 289 | ▶ | my $evidence = $args->{evidence} // $self->_optional_text("$base.evidence", $vars); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args->{"evidence"} // $self->_optional_text("$base.evidence", $vars)
MC/DC0%0/2
$args->{"evidence"} // $self->_optional_text("$base.evidence", $vars)
$args->{"evidence"}
$self->_optional_text("$base.evidence", $vars)
Truth table66%2/3
A // B
A= $args->{"evidence"}B= $self->_optional_text("$base.evidence", $vars)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | return $self->add( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 289 | ▶ | (map { defined $args->{$_} ? ($_ => $args->{$_}) : () } qw(severity host url key reference)), | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | id => $id, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | title => $self->i18n("$base.title", $vars), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | detail => $self->i18n("$base.detail", $vars), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | fix => $self->_optional_text("$base.fix", $vars), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | evidence => $evidence, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | =head2 annotate | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | Purpose: attach the file on disk or the line of source behind a finding, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | once the scan is complete. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | Args: C<$finding> (a hash reference from C<all> or C<sorted>), then named | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | C<file> and/or C<source> (strings). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | Returns: C<$self>, for chaining. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | Side Effects: changes the finding in place. Only C<file> and C<source> can | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | be changed; the identifying fields are fixed once recorded. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | Usage: C<< $findings->annotate($finding, file => '/srv/www/.env') >> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | for my $finding (@{ $findings->all }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | $findings->annotate($finding, source => 'lib/App.pm:42') | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | if $finding->{url} =~ m{/api/}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | finding => { type => 'hashref', position => 0 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | file => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | source => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | { type => 'object', isa => 'App::WebPerimeterScan::Findings' } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | Message Meaning / resolution | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | ---------------------------------------- ------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | annotate() was given a finding that this Pass a finding obtained from this | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | collection did not record (fatal) object's all() or sorted(). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | sub annotate | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 7 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
annotate: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 7 | my ($self, $finding, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | my $args = validate_strict( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 7 | ▶ | schema => { map { $_ => { type => 'string', optional => 1 } } keys %ANNOTATABLE }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
get_params(undef, \@rest) // {}
MC/DC100%1/1
get_params(undef, \@rest) // {}
get_params(undef, \@rest)
Truth table100%2/2
A
A= get_params(undef, \@rest)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | input => get_params(undef, \@rest) // {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # Identity, not equality: a copy of a finding must not be annotated as | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | # though it were the original. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 6 | ▶ | my $address = ref $finding eq 'HASH' ? refaddr($finding) : -1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | $self->_throw('findings.foreign') | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 6 | ▶ | unless grep { refaddr($_) == $address } @{ $self->{items} }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 5 | $finding->{$_} = $args->{$_} for grep { defined $args->{$_} } keys %ANNOTATABLE; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 5 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | =head2 all | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | Purpose: the findings in the order they were recorded. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | Args: none. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | Returns: an array reference (a new array; the findings inside are shared). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | Side Effects: none. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | Usage: C<< for my $f (@{ $findings->all }) { ... } >> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | my @hosts = map { $_->{host} } @{ $findings->all }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | {} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | { type => 'arrayref', element_type => 'hashref' } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | None. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | sub all | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 60 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 60 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 60 | return [ @{ $self->{items} } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | =head2 count | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | Purpose: the number of findings held. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | Args: none. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | Returns: a non-negative integer. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | Side Effects: none. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | Usage: C<< print $findings->count >> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | printf "%d finding(s)\n", $findings->count; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | {} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | { type => 'integer', min => 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | None. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | sub count | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
count: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 5 | return scalar @{ $self->{items} }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | =head2 sorted | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | Purpose: the findings worst first, then by host, title and URL, so the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | output of two runs can be diffed. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | Args: none. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | Returns: an array reference. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | Side Effects: none. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | Usage: C<< for my $f (@{ $findings->sorted }) { ... } >> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | my $worst = $findings->sorted->[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | print "Worst: $worst->{title}\n" if $worst; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | {} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | { type => 'arrayref', element_type => 'hashref' } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | None. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | sub sorted | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 16 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sorted: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 16 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | return [ sort { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | $RANK{ $b->{severity} } <=> $RANK{ $a->{severity} } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | || $a->{host} cmp $b->{host} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | || $a->{title} cmp $b->{title} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | || $a->{url} cmp $b->{url} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 16 | ▶ | } @{ $self->{items} } ]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition55%5/9
$RANK{$App::WebPerimeterScan::Findings::b->{'severity'}} <=> $RANK{$App::WebPerimeterScan::Findings::a->{'severity'}} || $App::WebPerimeterScan::Findings::a->{'host'} cmp $App::WebPerimeterScan::Findings::b->{'host'} || $App::WebPerimeterScan::Findings::a->{'title'} cmp $App::WebPerimeterScan::Findings::b->{'title'} || $App::WebPerimeterScan::Findings::a->{'url'} cmp $App::WebPerimeterScan::Findings::b->{'url'}
$RANK{$App::WebPerimeterScan::Findings::b->{"severity"}} <=> $RANK{$App::WebPerimeterScan::Findings::a->{"severity"}} or $App::WebPerimeterScan::Findings::a->{"host"} cmp $App::WebPerimeterScan::Findings::b->{"host"} or $App::WebPerimeterScan::Findings::a->{"title"} cmp $App::WebPerimeterScan::Findings::b->{"title"}
$RANK{$App::WebPerimeterScan::Findings::b->{"severity"}} <=> $RANK{$App::WebPerimeterScan::Findings::a->{"severity"}} or $App::WebPerimeterScan::Findings::a->{"host"} cmp $App::WebPerimeterScan::Findings::b->{"host"}
MC/DC0%0/4
$RANK{$App::WebPerimeterScan::Findings::b->{'severity'}} <=> $RANK{$App::WebPerimeterScan::Findings::a->{'severity'}} || $App::WebPerimeterScan::Findings::a->{'host'} cmp $App::WebPerimeterScan::Findings::b->{'host'} || $App::WebPerimeterScan::Findings::a->{'title'} cmp $App::WebPerimeterScan::Findings::b->{'title'} || $App::WebPerimeterScan::Findings::a->{'url'} cmp $App::WebPerimeterScan::Findings::b->{'url'}
$RANK{$App::WebPerimeterScan::Findings::b->{"severity"}} <=> $RANK{$App::WebPerimeterScan::Findings::a->{"severity"}}
$App::WebPerimeterScan::Findings::a->{"host"} cmp $App::WebPerimeterScan::Findings::b->{"host"}
$App::WebPerimeterScan::Findings::a->{"title"} cmp $App::WebPerimeterScan::Findings::b->{"title"}
$App::WebPerimeterScan::Findings::a->{'url'} cmp $App::WebPerimeterScan::Findings::b->{'url'}
Truth table40%2/5
A or B or C || D
A= $RANK{$App::WebPerimeterScan::Findings::b->{"severity"}} <=> $RANK{$App::WebPerimeterScan::Findings::a->{"severity"}}B= $App::WebPerimeterScan::Findings::a->{"host"} cmp $App::WebPerimeterScan::Findings::b->{"host"}C= $App::WebPerimeterScan::Findings::a->{"title"} cmp $App::WebPerimeterScan::Findings::b->{"title"}D= $App::WebPerimeterScan::Findings::a->{'url'} cmp $App::WebPerimeterScan::Findings::b->{'url'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | =head2 counts | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | Purpose: how many findings there are at each severity. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | Args: none. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | Returns: a hash reference with every severity as a key, zero where none. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | Side Effects: none. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | Usage: C<< my $high = $findings->counts->{high}; >> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | my $counts = $findings->counts; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | print "$counts->{critical} critical\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | {} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | { type => 'hashref' } # keys: critical high medium low info | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | None. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | sub counts | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 15 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
counts: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 15 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 15 | my %counts = map { $_ => 0 } @SEVERITIES; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 15 | $counts{ $_->{severity} }++ for @{ $self->{items} }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 15 | return \%counts; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | =head2 rank | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | Purpose: the numeric rank of a severity name, higher is worse. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | Args: C<$severity> (string). A function, not a method. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | Returns: 5 for C<critical> down to 1 for C<info>; 0 for anything else. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | Side Effects: none. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | Usage: C<< App::WebPerimeterScan::Findings::rank('high') >> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | my @worst_first = sort { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | App::WebPerimeterScan::Findings::rank($b) <=> App::WebPerimeterScan::Findings::rank($a) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | } qw(low critical medium); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | { severity => { type => 'string', optional => 1, position => 0 } } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | { type => 'integer', min => 0, max => 5 } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | None. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | sub rank | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rank: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 8 | my ($severity) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 8 | ▶ | return defined $severity ? ($RANK{$severity} // 0) : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$RANK{$severity} // 0
MC/DC100%1/1
$RANK{$severity} // 0
$RANK{$severity}
Truth table100%2/2
A
A= $RANK{$severity}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | =head2 at_or_above | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | Purpose: the findings at or above a severity, which is what decides the exit | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | status of the command-line tool. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | Args: C<$threshold>, a severity name. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | Returns: an array reference; empty for an unknown threshold. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | Side Effects: none. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | Usage: C<< exit 1 if @{ $findings->at_or_above('high') }; >> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | my $failing = $findings->at_or_above('medium'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | printf "%d finding(s) at medium or worse\n", scalar @{$failing}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | { threshold => { type => 'string', position => 0 } } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | { type => 'arrayref', element_type => 'hashref' } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | None. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | sub at_or_above | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
at_or_above: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 5 | my ($self, $threshold) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | # An unknown threshold matches nothing rather than everything. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 5 | my $limit = rank($threshold); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 5 | ▶ | return $limit ? [ grep { $RANK{ $_->{severity} } >= $limit } @{ $self->{items} } ] : []; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | # _optional_text | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | # Purpose: render a catalogue key that a rule may leave out (.fix, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | # .evidence). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | # Entry: $key is a full key; $vars a hashref. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | # Exit: the rendered text, or '' when the key does not exist. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | # Side effects: none. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 562 | ▶ | sub _optional_text :Private | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_optional_text: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 562 | my ($self, $key, $vars) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 562 | ▶ | return $self->has_message($key) ? $self->i18n($key, $vars) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 28 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 28 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||