Skip to content
Snippets Groups Projects

Store DAST scan results into the database

Merged Tetiana Chupryna requested to merge 7062-format-dast-output into master
1 unresolved thread
2 files
+ 38
32
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -5,32 +5,19 @@ module Ci
@@ -5,32 +5,19 @@ module Ci
module Parsers
module Parsers
module Security
module Security
class Dast < Common
class Dast < Common
extend ::Gitlab::Utils::Override
DEPRECATED_REPORT_VERSION = "1.3".freeze
override :parse_report
def parse_report(json_data)
report = super
if report.is_a?(Array)
report = {
"version" => DEPRECATED_REPORT_VERSION,
"vulnerabilities" => report
}
end
report
end
 
# FIXME: find real value
 
DEPRECATED_REPORT_VERSION = "1.0".freeze
def parse!(json_data, report)
def parse!(json_data, report)
vulnerabilities = format_report(JSON.parse!(json_data))
vulnerabilities = format_report(JSON.parse!(json_data))
vulnerabilities.each do |vulnerability|
vulnerabilities.each do |vulnerability|
create_vulnerability(report, vulnerability, DEPRECATED_REPORT_VERSION)
create_vulnerability(report, vulnerability, DEPRECATED_REPORT_VERSION)
end
end
# rescue JSON::ParserError
rescue JSON::ParserError
# raise SecurityReportParserError, 'JSON parsing failed'
raise SecurityReportParserError, 'JSON parsing failed'
# rescue
rescue
# raise SecurityReportParserError, "#{report.type} security report parsing failed"
raise SecurityReportParserError, "#{report.type} security report parsing failed"
end
end
private
private
@@ -52,9 +39,9 @@ def format_vulnerability(vulnerability)
@@ -52,9 +39,9 @@ def format_vulnerability(vulnerability)
'message' => vulnerability['name'],
'message' => vulnerability['name'],
'description' => vulnerability['desc'],
'description' => vulnerability['desc'],
'cve' => 'unknown',
'cve' => 'unknown',
'severity' => vulnerability['riskdesc'].match(/(.*) \(/)[0],
'severity' => severity(vulnerability['riskdesc']),
'solution' => vulnerability['solution'],
'solution' => vulnerability['solution'],
'confidence' => vulnerability['riskdesc'].match(/\((.*)\)/)[0],
'confidence' => confidence(vulnerability['riskdesc']),
'scanner' => { 'id' => 'zaproxy', 'name' => 'ZAProxy' },
'scanner' => { 'id' => 'zaproxy', 'name' => 'ZAProxy' },
'identifiers' => [
'identifiers' => [
{
{
@@ -65,7 +52,7 @@ def format_vulnerability(vulnerability)
@@ -65,7 +52,7 @@ def format_vulnerability(vulnerability)
}
}
],
],
'links' => [{ 'url' => vulnerability['instances'].first['uri'] }],
'links' => [{ 'url' => vulnerability['instances'].first['uri'] }],
'priority' => 'Unknown',
'priority' => 'unknown',
# 'url' => vulnerability['link'],
# 'url' => vulnerability['link'],
'tool' => 'zaproxy'
'tool' => 'zaproxy'
}
}
@@ -74,6 +61,16 @@ def format_vulnerability(vulnerability)
@@ -74,6 +61,16 @@ def format_vulnerability(vulnerability)
def generate_location_fingerprint(location)
def generate_location_fingerprint(location)
'aaa_test'
'aaa_test'
end
end
 
 
def severity(risk)
 
parsed_risk = risk.match(/(.*) \((.*)\)/)
 
parsed_risk ? parsed_risk[1].downcase : 'unknown'
 
end
 
 
def confidence(risk)
 
parsed_risk = risk.match(/(.*) \((.*)\)/)
 
parsed_risk ? parsed_risk[2].downcase : 'unknown'
 
end
end
end
end
end
end
end
Loading