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

Make Ahocorasick matching case insensitive #1547

Merged
merged 1 commit into from
Jul 25, 2023

Conversation

zricethezav
Copy link
Collaborator

@zricethezav zricethezav commented Jul 25, 2023

This PR fixes a bug that prevents secrets from being detected if the keyword or chunk data case varies.

strings.ToLower doesn't seem to have a huge effect on performance either.

Benchmark git scan on the rails/rails repo

### NEW
real 27.18s
user 58.14s 
sys  5.47s 
memory:753328KB 
cpu 234%
      62

### OLD
real 27.45s
user 56.43s 
sys  5.50s 
memory:750160KB 
cpu 225%
      62

To demonstrate this bug fix, try finding a private key

@zricethezav zricethezav requested a review from a team as a code owner July 25, 2023 21:41
Copy link
Collaborator

@mcastorina mcastorina left a comment

Choose a reason for hiding this comment

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

I'm not sure we have any non-lowercase keywords, but good to have this in place.

@zricethezav
Copy link
Collaborator Author

zricethezav commented Jul 25, 2023

@mcastorina I didn't see any, but I agree. Currently, some secrets like private keys are being detected because https://github.com/BobuSumisu/aho-corasick does not have a case insensitive option like https://github.com/petar-dambovaliev/aho-corasick and therefore when BEING PRIVATE KEY is scanned it fails to match on private key (pkey detector keyword).

Note that the performance hit in the test is a tradeoff for correctness.

Perhaps we can follow up with an option in the library to support case insensitive scanning

@zricethezav zricethezav merged commit 1a1977f into main Jul 25, 2023
8 of 9 checks passed
@zricethezav zricethezav deleted the matcher-case-insensitive branch July 25, 2023 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants