Skip to content

Commit

Permalink
issue hash: allow to skip SAST file path parts
Browse files Browse the repository at this point in the history
  • Loading branch information
LifeDJIK committed Mar 27, 2024
1 parent b512895 commit 6ec0f96
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions dusty/processors/issue_hash/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
Processor: issue_hash
"""

import os
import os.path
import re
import hashlib

Expand Down Expand Up @@ -51,9 +53,28 @@ def execute(self):
).hexdigest()
if isinstance(item, SastFinding):
title = re.sub('[^A-Za-zА-Яа-я0-9//\\\.\- _]+', '', item.title) # pylint: disable=W1401
cwe = item.get_meta("legacy.cwe", "None")
line = item.get_meta("legacy.line", "None")
file = item.get_meta("legacy.file", "")
#
if self.config.get("sast_use_cwe", True):
cwe = item.get_meta("legacy.cwe", "None")
else:
cwe = "None"
#
if self.config.get("sast_use_line", True):
line = item.get_meta("legacy.line", "None")
else:
line = "None"
#
if self.config.get("sast_use_file", True):
skip_roots = self.config.get("sast_skip_file_roots", None)
if isinstance(skip_roots, int) and skip_roots > 0:
file_data = item.get_meta("legacy.file", "")
data_parts = [part for part in file_data.split(os.sep) if part]
file = os.path.join(*data_parts[skip_roots:])
else:
file = item.get_meta("legacy.file", "")
else:
file = ""
#
issue_hash = hashlib.sha256(
f'{title}_{cwe}_{line}_{file}_'.strip().encode('utf-8')
).hexdigest()
Expand Down

0 comments on commit 6ec0f96

Please sign in to comment.