Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(secrets): fix secrets prerun bug #6594

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions checkov/secrets/plugins/custom_regex_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,18 @@ def _find_potential_secret(
# We want to run multiline policy once per file (if prerun was found)
if regex_data.get("prerun"):
if filename in self._analyzed_files_by_check[regex_data['Check_ID']]:
return
continue
self._analyzed_files_by_check[regex_data['Check_ID']].add(filename)

# We are going to scan the whole file with the multiline regex
if not 0 < get_file_size_safe(filename) < CustomRegexDetector.MAX_FILE_SIZE:
return
continue
file_content = read_file_safe(filename)
if not file_content:
return
continue
multiline_regex = self.multiline_pattern_by_prerun_compiled.get(regex.pattern)
if multiline_regex is None:
return
continue
multiline_matches = multiline_regex.findall(file_content)
for mm in multiline_matches:
mm = f"'{mm}'"
Expand All @@ -182,7 +182,7 @@ def _find_potential_secret(
)
ps.check_id = regex_data["Check_ID"]
output.add(ps)
return
continue

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