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: Matching logic for product_name and title #23

Merged
merged 2 commits into from
Nov 21, 2024

Conversation

fernandogoncalves-me
Copy link
Contributor

@fernandogoncalves-me fernandogoncalves-me commented Nov 18, 2024

This PR updates the matching logic for rules based only on product_name and title so that both attributes need to match at the same time.

The goal is to prevent the following scenario:

  • rule matches on product_name
  • rule doesn't match on title (line 370)
  • rule doesn't contain any tags or resource_id_regexps
  • is_matching_rule wrongly returns True based on the condition in line 374

This would lead to a match based only on product_name, resulting on wrong suppressions.

Testing suppressions

In my opinion, the current organization of that test cases makes it challenging to understand the flows been tested.

To try and (hopefully) make things easier to understand, I've refactored the existing tests.

  • All test suppression rules can be found in fixtures/suppression.yaml.
  • Findings that should be matched against the suppression rules are consolidated in fixtures/matching_findings.json.
  • Findings that should NOT be matched with any suppression rule are consolidated in fixtures/non_matching_findings.json.
  • The expected match result between findings and rules can be found in fixtures/expected_matched_findings.json.
  • The expected suppression requests sent to Security Hub can be found in fixtures/expected_batch_update_findings.json.

This has reduced the amount of fixture files and made the tests more readable.

I've added this same information about the tests to this readme file.

@fernandogoncalves-me fernandogoncalves-me marked this pull request as ready for review November 18, 2024 19:07
@@ -43,6 +44,19 @@
__email__ = '''<[email protected]>'''
__status__ = '''Development''' # "Prototype", "Development", "Production".

with open('tests/fixtures/matching_findings.json', encoding='utf-8') as matching_findings_file:
findings_fixture = json.load(matching_findings_file)
with open('tests/fixtures/non_matching_findings.json', encoding='utf-8') as non_matching_findings_file:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is non-matching-findings loaded twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea is that findings_fixture has both matching and non-matching findings.

So when we apply the suppression rules, we are sure that the non-matching findings are ignored.

The other part where we load only non-matching findings was to test that, if there are no matching findings, an empty list is returned.

@fernandogoncalves-me fernandogoncalves-me merged commit 4813b79 into main Nov 21, 2024
2 checks passed
@fernandogoncalves-me fernandogoncalves-me deleted the fix_matching_logic branch November 21, 2024 10:14
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.

2 participants