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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
|
package CSAF::Validator::InformativeTests;
use 5.010001;
use strict;
use warnings;
use utf8;
use version;
use List::Util qw(first);
use CSAF::Util qw(uniq);
use Moo;
extends 'CSAF::Validator::Base';
use constant DEBUG => $ENV{CSAF_DEBUG};
has tests => (
is => 'ro',
default =>
sub { ['6.3.1', '6.3.2', '6.3.3', '6.3.4', '6.3.5', '6.3.6', '6.3.7', '6.3.8', '6.3.9', '6.3.10', '6.3.11'] }
);
my $VERS_REGEXP = qr{^vers:[a-z\\.\\-\\+][a-z0-9\\.\\-\\+]*/.+};
# 6.3.1 Use of CVSS v2 as the only Scoring System
sub TEST_6_3_1 {
my $self = shift;
$self->csaf->vulnerabilities->each(sub {
my ($vulnerability, $vuln_idx) = @_;
$vulnerability->scores->each(sub {
my ($score, $score_idx) = @_;
if ($score->cvss_v2 && !$score->cvss_v3) {
$self->add_message(
type => 'info',
category => 'informative',
path => "/vulnerabilities/$vuln_idx/scores/$score_idx",
code => '6.3.1',
message => 'Use of CVSS v2 as the only Scoring System'
);
}
});
});
}
# 6.3.2 Use of CVSS v3.0
sub TEST_6_3_2 {
my $self = shift;
$self->csaf->vulnerabilities->each(sub {
my ($vulnerability, $vuln_idx) = @_;
$vulnerability->scores->each(sub {
my ($score, $score_idx) = @_;
if ($score->cvss_v3 && $score->cvss_v3->version eq '3.0') {
$self->add_message(
type => 'info',
category => 'informative',
path => "/vulnerabilities/$vuln_idx/scores/$score_idx/cvss_v3/version",
code => '6.3.2',
message => 'Use of CVSS v3.0'
);
}
if ($score->cvss_v3 && $score->cvss_v3->vectorString =~ /^CVSS\:3.0/) {
$self->add_message(
type => 'info',
category => 'informative',
path => "/vulnerabilities/$vuln_idx/scores/$score_idx/cvss_v3/vectorString",
code => '6.3.2',
message => 'Use of CVSS v3.0'
);
}
});
});
}
# 6.3.3 Missing CVE
sub TEST_6_3_3 {
my $self = shift;
$self->csaf->vulnerabilities->each(sub {
my ($vulnerability, $vuln_idx) = @_;
if (!$vulnerability->cve) {
$self->add_message(
type => 'info',
category => 'informative',
path => "/vulnerabilities/$vuln_idx/cve",
code => '6.3.3',
message => 'Missing CVE'
);
}
});
}
# 6.3.4 Missing CWE
sub TEST_6_3_4 {
my $self = shift;
$self->csaf->vulnerabilities->each(sub {
my ($vulnerability, $vuln_idx) = @_;
if (!$vulnerability->cwe->id) {
$self->add_message(
type => 'info',
category => 'informative',
path => "/vulnerabilities/$vuln_idx/cwe",
code => '6.3.4',
message => 'Missing CWE'
);
}
});
}
# 6.3.5 Use of Short Hash
sub TEST_6_3_5 {
my $self = shift;
# /product_tree/branches[](/branches[])*/product/product_identification_helper/hashes[]/file_hashes[]/value
$self->_TEST_6_3_5_branches($self->csaf->product_tree->branches, "/product_tree/branches");
# /product_tree/full_product_names[]/product_identification_helper/hashes[]/file_hashes[]/value
$self->csaf->product_tree->full_product_names->each(sub {
my ($full_product_name, $full_product_name_idx) = @_;
return unless $full_product_name->product_identification_helper;
$self->_TEST_6_3_5_product_identification_helper(
$full_product_name->product_identification_helper,
"/product_tree/full_product_names/$full_product_name_idx"
);
});
# /product_tree/relationships[]/full_product_name/product_identification_helper/hashes[]/file_hashes[]/value
$self->csaf->product_tree->relationships->each(sub {
my ($relationship, $rel_idx) = @_;
return unless $relationship->full_product_name;
return unless $relationship->full_product_name->product_identification_helper;
$self->_TEST_6_3_5_product_identification_helper(
$relationship->full_product_name->product_identification_helper,
"/product_tree/relationships/$rel_idx");
});
}
# 6.3.6 Use of non-self referencing URLs Failing to Resolve
sub TEST_6_3_6 { }
# 6.3.7 Use of self referencing URLs Failing to Resolve
sub TEST_6_3_7 { }
# 6.3.8 Spell check
sub TEST_6_3_8 { }
# 6.3.9 Branch Categories
sub TEST_6_3_9 {
my $self = shift;
return if (not $self->csaf->product_tree);
$self->_TEST_6_3_9_branches($self->csaf->product_tree->branches, "/product_tree/branches", []);
}
# 6.3.10 Usage of Product Version Range
sub TEST_6_3_10 {
my $self = shift;
return if (not $self->csaf->product_tree);
$self->_TEST_6_3_10_branches($self->csaf->product_tree->branches, "/product_tree/branches");
}
# 6.3.11 Usage of V as Version Indicator
sub TEST_6_3_11 {
my $self = shift;
return if (not $self->csaf->product_tree);
$self->_TEST_6_3_11_branches($self->csaf->product_tree->branches, "/product_tree/branches");
}
sub _TEST_6_3_5_branches {
my ($self, $branches, $path) = @_;
$branches->each(sub {
my ($branch, $branch_idx) = @_;
$self->_TEST_6_3_5_branches($branch->branches, "$path/$branch_idx/branches");
return unless $branch->product;
return unless $branch->product->product_identification_helper;
$self->_TEST_6_3_5_product_identification_helper($branch->product->product_identification_helper,
"$path/branch/$branch_idx/product");
});
}
sub _TEST_6_3_5_product_identification_helper {
my ($self, $product_identification_helper, $path) = @_;
$product_identification_helper->hashes->each(sub {
my ($hash, $hash_idx) = @_;
$hash->file_hashes->each(sub {
my ($file_hash, $file_hash_idx) = @_;
if (length($file_hash) < 64) {
$self->add_message(
type => 'info',
category => 'informative',
path => "$path/product_identification_helper/hashes/$hash_idx/file_hashes/$file_hash_idx/value",
code => '6.3.5',
message => 'Use of Short Hash'
);
}
});
});
}
sub _TEST_6_3_9_branches {
my ($self, $branches, $path, $categories) = @_;
my @sorted_categories = qw[vendor product_name product_version];
$branches->each(sub {
my ($branch, $idx) = @_;
push @{$categories}, $branch->category if $branch->category eq 'vendor';
push @{$categories}, $branch->category if $branch->category eq 'product_name';
push @{$categories}, $branch->category if $branch->category eq 'product_version';
$self->_TEST_6_3_9_branches($branch->branches, "$path/$idx/branches", $categories);
my $is_invalid = undef;
my @uniq_categories = uniq(@{$categories});
for my $category (@sorted_categories) {
$is_invalid = 1 if (!first { $_ eq $category } @{$categories});
}
for (my $i = 0; $i < @uniq_categories; $i++) {
$is_invalid = 1 if ($uniq_categories[$i] ne $sorted_categories[$i]);
}
if ($is_invalid) {
$self->add_message(
type => 'info',
category => 'informative',
path => "$path/category",
code => '6.3.9',
message => 'Branch Categories'
);
}
});
}
sub _TEST_6_3_10_branches {
my ($self, $branches, $path) = @_;
$branches->each(sub {
my ($branch, $idx) = @_;
$self->_TEST_6_3_10_branches($branch->branches, "$path/$idx/branches");
if ($branch->category eq 'product_version_range') {
$self->add_message(
type => 'info',
category => 'informative',
path => "$path/category",
code => '6.3.10',
message => 'Usage of Product Version Range'
);
}
});
}
sub _TEST_6_3_11_branches {
my ($self, $branches, $path) = @_;
$branches->each(sub {
my ($branch, $idx) = @_;
$self->_TEST_6_3_11_branches($branch->branches, "$path/$idx/branches");
if ($branch->category eq 'product_version') {
if ($branch->name =~ /^[vV][0-9].*$/) {
$self->add_message(
type => 'info',
category => 'informative',
path => "$path/name",
code => '6.3.11',
message => 'Usage of V as Version Indicator'
);
}
}
});
}
1;
__END__
=encoding utf-8
=head1 NAME
CSAF::Validator::InformativeTests
=head1 SYNOPSIS
use CSAF::Validator::InformativeTests;
my $v = CSAF::Validator::InformativeTests->new( csaf => $csaf );
$v->exec_test('6.3.11');
$v->TEST_6_3_11;
=head1 DESCRIPTION
Informative tests provide insights in common mistakes and bad practices.
They MAY fail at a valid L<CSAF> document. It is up to the issuing party to decide
whether this was an intended behavior and can be ignore or should be treated.
6.3.1 Use of CVSS v2 as the only Scoring System
6.3.2 Use of CVSS v3.0
6.3.3 Missing CVE
6.3.4 Missing CWE
6.3.5 Use of Short Hash
6.3.6 Use of non-self referencing URLs Failing to Resolve (*)
6.3.7 Use of self referencing URLs Failing to Resolve (*)
6.3.8 Spell check (*)
6.3.9 Branch Categories
6.3.10 Usage of Product Version Range
6.3.11 Usage of V as Version Indicator
(*) actually not tested in this L<CSAF> distribution.
=head2 METHODS
L<CSAF::Validator::InformativeTests> inherits all methods from L<CSAF::Validator::Base> and implements the following new ones.
=over
=item TEST_6_3_1
Use of CVSS v2 as the only Scoring System
=item TEST_6_3_2
Use of CVSS v3_0
=item TEST_6_3_3
Missing CVE
=item TEST_6_3_4
Missing CWE
=item TEST_6_3_5
Use of Short Hash
=item TEST_6_3_6
Use of non-self referencing URLs Failing to Resolve
=item TEST_6_3_7
Use of self referencing URLs Failing to Resolve
=item TEST_6_3_8
Spell check (*)
=item TEST_6_3_9
Branch Categories
=item TEST_6_3_10
Usage of Product Version Range
=item TEST_6_3_11
Usage of V as Version Indicator
=back
=head1 SUPPORT
=head2 Bugs / Feature Requests
Please report any bugs or feature requests through the issue tracker
at L<https://github.com/giterlizzi/perl-CSAF/issues>.
You will be notified automatically of any progress on your issue.
=head2 Source Code
This is open source software. The code repository is available for
public review and contribution under the terms of the license.
L<https://github.com/giterlizzi/perl-CSAF>
git clone https://github.com/giterlizzi/perl-CSAF.git
=head1 AUTHOR
=over 4
=item * Giuseppe Di Terlizzi <gdt@cpan.org>
=back
=head1 LICENSE AND COPYRIGHT
This software is copyright (c) 2023-2025 by Giuseppe Di Terlizzi.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|