Commit e54821cc authored by James Lopez's avatar James Lopez

Merge branch 'remove-undefined-from-parser' into 'master'

Check valid confidence and severity level when parsing

See merge request gitlab-org/gitlab!33050
parents ff4425ba a2121125
...@@ -58,8 +58,8 @@ module Gitlab ...@@ -58,8 +58,8 @@ module Gitlab
name: data['message'], name: data['message'],
compare_key: data['cve'] || '', compare_key: data['cve'] || '',
location: create_location(data['location'] || {}), location: create_location(data['location'] || {}),
severity: parse_level(data['severity']), severity: parse_severity_level(data['severity']&.downcase),
confidence: parse_level(data['confidence']), confidence: parse_confidence_level(data['confidence']&.downcase),
scanner: scanner, scanner: scanner,
identifiers: identifiers, identifiers: identifiers,
raw_metadata: data.to_json, raw_metadata: data.to_json,
...@@ -99,9 +99,16 @@ module Gitlab ...@@ -99,9 +99,16 @@ module Gitlab
{ 'id' => tool, 'name' => tool.capitalize } if tool { 'id' => tool, 'name' => tool.capitalize } if tool
end end
def parse_level(input) def parse_severity_level(input)
input = input&.downcase return input if ::Vulnerabilities::Occurrence::SEVERITY_LEVELS.key?(input)
input.blank? || input == 'undefined' ? 'unknown' : input
'unknown'
end
def parse_confidence_level(input)
return input if ::Vulnerabilities::Occurrence::CONFIDENCE_LEVELS.key?(input)
'unknown'
end end
def create_location(location_data) def create_location(location_data)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment