Skip to content

fix(secrets): report all multiline regex matches per file, not just first occurrence#7483

Merged
eshmayovitz merged 14 commits intomainfrom
feature/XSUP-65967-multiline-fix-lines
Apr 13, 2026
Merged

fix(secrets): report all multiline regex matches per file, not just first occurrence#7483
eshmayovitz merged 14 commits intomainfrom
feature/XSUP-65967-multiline-fix-lines

Conversation

@eshmayovitz
Copy link
Copy Markdown
Contributor

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

New/Edited policies (Delete if not relevant)

Description

Include a description of what makes it a violation and any relevant external links.

Fix

How does someone fix the issue in code and/or in runtime?

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my feature, policy, or fix is effective and works
  • New and existing tests pass locally with my changes

for mm in multiline_matches:
mm = self._extract_real_regex_match(mm)
for match_obj in multiline_regex.finditer(file_content):
mm = self._extract_real_regex_match(cast(Tuple[str], match_obj.groups()) or match_obj.group(0))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to a more readable var name ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the old name I changed it.

# which is the most meaningful trigger line (e.g. "BEGIN PRIVATE KEY").
if '\n' not in mm:
inner_offset = match_obj.group(0).find(mm)
mm_offset = match_obj.start() + (inner_offset if inner_offset >= 0 else 0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case of mm_offset equals zero shouldn't we just skip this iteration?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inner_offset == 0 is ok it means the secret was found at the first character of the match.
I added a safety continue for inner_offset < 0 (not found at all),

lines = sorted(c.file_line_range[0] for c in interesting_failed_checks)
# The committed fix reports the prerun match line (BEGIN_SECRET) for multiline captured values.
# First secret: BEGIN_SECRET is on line 1, second: BEGIN_SECRET is on line 8.
# On main (before fix), both fall back to line 1 (the first prerun match line).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove "On main" and just leave "before fix"?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

runner = Runner()
report = runner.run(root_folder=valid_dir_path,
report = runner.run(root_folder=None,
files=[valid_dir_path + "/Dockerfile.mine"],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's /Dockerfile.mine?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the original file name of the test. I explicitly specified it here because I added another file, and before the change it scanned the entire folder.

where the captured group spans multiple real lines, both must be detected with
correct and distinct line numbers.

On main (before fix), find_line_number() cannot find a multiline substring in any
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here remove "On main"

@eshmayovitz eshmayovitz merged commit fa12dd6 into main Apr 13, 2026
43 checks passed
@eshmayovitz eshmayovitz deleted the feature/XSUP-65967-multiline-fix-lines branch April 13, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants