-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Remove if len(match) != 2
check in detectors
#2746
base: main
Are you sure you want to change the base?
Conversation
Even I was curious as to know when and how many times does this I have only seen this message for |
The JIRA email is slightly different because it's checking the length of the split and not the match groups. I don't really understand it's purpose, though. trufflehog/pkg/detectors/jiratoken/v1/jiratoken.go Lines 56 to 59 in d1a29f7
|
9959218
to
50f3e98
Compare
@rgmz I believe this check is to prevent index errors like the one demonstrated here https://go.dev/play/p/MS8AyzGb1uq. Rather than removing the check, it would be better if we change the condition to |
That still has the problem of silently ignoring legitimate errors. I believe that logic errors should explicitly fail, rather than quietly continuing. |
I disagree. It's less of a logic error and more of a incorrectly written regex issue. A single index error on a detector shouldn't cause the whole scan to fail imo. |
Some patterns are precise and don't have any capture groups, so you'd only have one match (the entire matching string).
This error means that the detector can never succeed and will miss valid secrets. It would be easy to detect in the build/test process, so a user should never actually ecounter this issue. |
Then the check could be safely removed if present. For me to feel comfortable merging this blanket removal would require a test that ensures we would not get an index out of range error.
I agree with this |
Ideally, each detector would have unit tests but only a few do at the moment. The |
50f3e98
to
79a1bd9
Compare
79a1bd9
to
f2c38e0
Compare
f2c38e0
to
c5833ad
Compare
1639822
to
2ad95b4
Compare
2ad95b4
to
4e475a7
Compare
2896043
to
672de68
Compare
672de68
to
69f7148
Compare
b45f22f
to
31cb8dc
Compare
31cb8dc
to
2217aab
Compare
fbf049c
to
e054c80
Compare
9baaec4
to
1d43308
Compare
1d43308
to
887a9bf
Compare
887a9bf
to
382c516
Compare
@zricethezav Are we able to merge this now that ever detector has unit tests? #3771 was the last of the batch. |
bc20ee5
to
b88c84a
Compare
b88c84a
to
ea9cd69
Compare
Description:
I believe the intention behind this code was to make sure that a given pattern matched, but it doesn't actually do this. A while ago, I explained in a PR comment how the
if len(match) != 2
check doesn't necessarily do what it appears to, and how it can actually silently break detectors.In short,
FindAllStringSubmatch
only returns results that match the given pattern. The number of match groups in a specific match is static, meaning that the pattern(fo.)bar(.?)
will always have 3 groups even if the group afterbar
is empty. If the number of match groups in a pattern is changed and the if statement isn't, it will cause matches to be silently discarded.https://go.dev/play/p/TXYh1bQItaO
Checklist:
make test-community
)?make lint
this requires golangci-lint)?