diff options
Diffstat (limited to 'app/models/concerns/vulnerability_finding_helpers.rb')
-rw-r--r-- | app/models/concerns/vulnerability_finding_helpers.rb | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/app/models/concerns/vulnerability_finding_helpers.rb b/app/models/concerns/vulnerability_finding_helpers.rb index f0e5e010e70..a656856487d 100644 --- a/app/models/concerns/vulnerability_finding_helpers.rb +++ b/app/models/concerns/vulnerability_finding_helpers.rb @@ -2,6 +2,35 @@ module VulnerabilityFindingHelpers extend ActiveSupport::Concern -end + def matches_signatures(other_signatures, other_uuid) + other_signature_types = other_signatures.index_by(&:algorithm_type) + + # highest first + match_result = nil + signatures.sort_by(&:priority).reverse_each do |signature| + matching_other_signature = other_signature_types[signature.algorithm_type] + next if matching_other_signature.nil? + + match_result = matching_other_signature == signature + break + end -VulnerabilityFindingHelpers.prepend_mod_with('VulnerabilityFindingHelpers') + if match_result.nil? + [uuid, *signature_uuids].include?(other_uuid) + else + match_result + end + end + + def signature_uuids + signatures.map do |signature| + hex_sha = signature.signature_hex + ::Security::VulnerabilityUUID.generate( + report_type: report_type, + location_fingerprint: hex_sha, + primary_identifier_fingerprint: primary_identifier&.fingerprint, + project_id: project_id + ) + end + end +end |