Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pazbechor committed Jul 21, 2024
1 parent 68a6116 commit cca6fe5
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions checkov/secrets/plugins/custom_regex_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def analyze_line(
not self.multiline_regex_supported_file_types or \
not any([filename.endswith(str(file_type)) for file_type in self.multiline_regex_supported_file_types]) or \
not 0 < get_file_size_safe(filename) < CustomRegexDetector.MAX_FILE_SIZE:
file_content = read_file_safe(filename)
if not file_content:
return output
file_content = read_file_safe(filename)
if not file_content:
return output

self._find_potential_secret(
filename=filename,
Expand Down Expand Up @@ -161,10 +161,9 @@ def _find_potential_secret(
if not file_content:
return
multiline_regex = self.multiline_pattern_by_prerun_compiled.get(regex.pattern)
is_multiline = True
multiline_matches = multiline_regex.findall(file_content)
for mm in multiline_matches:
mm = f"'{mm}'" if is_multiline else mm
mm = f"'{mm}'"
ps = PotentialSecret(
type=regex_data["Name"],
filename=filename,
Expand All @@ -173,20 +172,12 @@ def _find_potential_secret(
is_verified=is_verified,
is_added=is_added,
is_removed=is_removed,
is_multiline=is_multiline,
is_multiline=True,
)
ps.check_id = regex_data["Check_ID"]
if is_multiline:
output.add(ps)
elif len(cast(str, ps.secret_value)) in range(MIN_CHARACTERS, MAX_CHARACTERS) or not regex_data[
'isCustom']:
output.add(ps)
else:
logging.info(
f'Finding for check {ps.check_id} are not 5-100 characters in length, was ignored')
output.add(ps)
return


# Wrap multiline match with fstring + ''
match = f"'{match}'" if is_multiline else match
ps = PotentialSecret(
Expand Down

0 comments on commit cca6fe5

Please sign in to comment.