Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checks to WPScan API reporting logic, ensure CVSS outputted includes precision #308

Merged
merged 3 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/unit/WpscanReportCommentFormatResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public function testReportResultPlugin(): void {
array(
'id' => '0100100 ;',
'title' => 'Security problem in My Plugin < 1.9.0',
'cvss' => array(
'score' => '7.3',
),
),
),
),
Expand Down Expand Up @@ -171,6 +174,16 @@ public function testReportResultPlugin(): void {
VIPGOCI_WPSCAN_BASE_URL . '/vulnerability/0100100%20%3B',
$report_str
);

$this->assertStringContainsString(
'Severity',
$report_str
);

$this->assertStringContainsString(
'7.3/10 (HIGH)',
$report_str
);
}

/**
Expand Down Expand Up @@ -198,6 +211,9 @@ public function testReportResultTheme(): void {
array(
'id' => '0100100',
'title' => 'Security problem in My Theme',
'cvss' => array(
'score' => '5.0',
),
),
),
),
Expand Down Expand Up @@ -309,6 +325,16 @@ public function testReportResultTheme(): void {
VIPGOCI_WPSCAN_BASE_URL . '/vulnerability/0100100',
$report_str
);

$this->assertStringContainsString(
'Severity',
$report_str
);

$this->assertStringContainsString(
'5.0/10 (MEDIUM)',
$report_str
);
}

/**
Expand Down
29 changes: 25 additions & 4 deletions wpscan-reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,20 @@ function vipgoci_wpscan_report_comment_format_result(
$res .= "\n\r";

foreach ( $issue['details']['vulnerabilities'] as $vuln_item ) {
if (
( ! isset( $vuln_item['id'] ) ) ||
gudmdharalds marked this conversation as resolved.
Show resolved Hide resolved
( ! isset( $vuln_item['title'] ) )
) {
vipgoci_log(
'Vulnerability detail item from WPScan API is invalid, missing fields',
array(
'vuln_item' => $vuln_item,
)
);

continue;
}

$res .= '### &#x1f512; Security information' . "\n"; // Header markup and lock sign.

/*
Expand All @@ -257,13 +271,20 @@ function vipgoci_wpscan_report_comment_format_result(
) . "\n";

// May not be included, enterprise only feature.
if ( isset( $vuln_item['cvss']['score'] ) ) {
// Escape severity as float.
$res .= '**Severity**: ' . ( (float) $vuln_item['cvss']['score'] ) . '/10 (';
if (
( isset( $vuln_item['cvss']['score'] ) ) &&
( is_numeric( $vuln_item['cvss']['score'] ) )
) {
// Output severity as float.
$res .= '**Severity**: ';
$res .= sprintf( '%.1f', (float) $vuln_item['cvss']['score'] );
$res .= '/10 (';

// Escape output string.
$res .= vipgoci_output_markdown_escape(
vipgoci_wpscan_report_format_cvss_score( $vuln_item['cvss']['score'] )
vipgoci_wpscan_report_format_cvss_score(
(float) $vuln_item['cvss']['score']
)
);

$res .= ')' . "\n";
Expand Down