-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Define multiple allowlists per rule #1496
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
Define multiple allowlists per rule #1496
Conversation
c526694
to
364eeed
Compare
815a074
to
111227b
Compare
@@ -269,11 +309,9 @@ func (c *Config) extend(extensionConfig Config) { | |||
} | |||
baseRule.Tags = append(baseRule.Tags, currentRule.Tags...) | |||
baseRule.Keywords = append(baseRule.Keywords, currentRule.Keywords...) | |||
baseRule.Allowlist.Commits = append(baseRule.Allowlist.Commits, currentRule.Allowlist.Commits...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this block getting deleted? The extend feature for a singular rule allowlist should function the same as before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this preserves the prior functionality, while allowing the new stuff to function as expected. (Correct me if I'm wrong.)
Consider the following config:
[extend]
useDefault = true
[[rules]]
id = "generic-api-key"
[rules.allowlist]
paths = ['''Some_Files\.xaml''']
stopwords = ["foo"]
With the append logic this would get translated as the following (pseudo-code):
allowlist{
paths = ["some_files.xaml"]
stopwords = ["foo", DefaultStopWords... ]
}
With the new logic, it would get translated as the following. Despite the difference in structure, the logic is still the same: paths == "some_files.xaml" || stopwords == "foo" || stopwords == DefaultStopWords...
.
allowlist{ // extended
stopwords = [ DefaultStopWords... ]
},
allowlist{ // our config
paths = ["some_files.xaml"]
stopwords = ["foo" ]
}
As for the "new stuff", if either your or the extended rule's has an allowlist with AND
then appending commits/paths/regexes/stopwords will break that.
It would be possible to carve out special handling for [rules.allowlist]
vs. [[rules.allowlist]]
, or append for OR
and not AND
, but I figured this way is the most straightforward. I can add more tests to be certain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the new logic, it would get translated as the following. Despite the difference in structure, the logic is still the same: paths == "some_files.xaml" || stopwords == "foo" || stopwords == DefaultStopWords....
I gotcha, that makes sense. Boy this would be much easier to test if I made that config
command already
111227b
to
9f26aa7
Compare
At first blush it wasn't 100% clear to me that
applied to the different checks in this allowlist and not across the different allowlists associated with the rule. I don't know that I have a great suggestion at this moment. It wasn't hard to figure out after looking closer, but just trying to think of something that someone could catch at a glance if they weren't familiar with the behavior. Maybe: Thoughts? |
9f26aa7
to
fd084de
Compare
fd084de
to
b9f7fda
Compare
We can make it extra clear in the readme that the |
b9f7fda
to
0862fcd
Compare
Do you have anything in mind for wording? |
a461259
to
68d8d5a
Compare
I discovered an 'interesting' interaction while testing. While it's outside the scope of this PR, I figured it was worth mentioning. Generic matches are ignored by the
However, if you create an allowlist entry for the rule, the secret will now be reported as a
|
I agree with that. Let's make a follow up issue to track this |
68d8d5a
to
48ba63f
Compare
🥳 nice |
* feat: multiple rule allowlists * feat(config): add allowlist 'condition'
Description:
This is an experimental implementation of two things I described here:
With this change, a rule can have broad regexes AND ones specific to a certain path. This is a bit of a pain point for more complex configurations, at least in my experience.
A contrived example for the sake of demonstration:
This closes #1512.
Checklist: