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

Added Filter on Custom Rule parser #1090

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
golang.org/x/net v0.0.0-20220114011407-0dd24b26b47d // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220315194320-039c03cc5b86 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,8 @@ golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 h1:f+lwQ+GtmgoY+A2YaQxlSOnDjXcQ7ZRLWOHbC6HtRqE=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down
1 change: 1 addition & 0 deletions internal/services/custom_rules/custom_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type CustomRule struct {
Name string `json:"name"`
Description string `json:"description"`
Language languages.Language `json:"language"`
Filter string `json:"filter"`
Severity severities.Severity `json:"severity"`
Confidence confidence.Confidence `json:"confidence"`
Type MatchType `json:"type"`
Expand Down
12 changes: 11 additions & 1 deletion internal/services/custom_rules/custom_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func TestValidateAllLanguages(t *testing.T) {
ID: "HS-CSHARP-10000",
Severity: severities.Low,
Confidence: confidence.Low,
Filter: "**/*",
Type: Regular,
Language: languages.CSharp,
},
Expand All @@ -141,6 +142,7 @@ func TestValidateAllLanguages(t *testing.T) {
ID: "HS-DART-10000",
Severity: severities.Low,
Confidence: confidence.Low,
Filter: "**/*",
Type: Regular,
Language: languages.Dart,
},
Expand All @@ -154,6 +156,7 @@ func TestValidateAllLanguages(t *testing.T) {
ID: "HS-JAVA-10000",
Severity: severities.Low,
Confidence: confidence.Low,
Filter: "**/*",
Type: Regular,
Language: languages.Java,
},
Expand All @@ -167,6 +170,7 @@ func TestValidateAllLanguages(t *testing.T) {
ID: "HS-KOTLIN-10000",
Severity: severities.Low,
Confidence: confidence.Low,
Filter: "**/*",
Type: Regular,
Language: languages.Kotlin,
},
Expand All @@ -180,6 +184,7 @@ func TestValidateAllLanguages(t *testing.T) {
ID: "HS-YAML-10000",
Severity: severities.Low,
Confidence: confidence.Low,
Filter: "**/*",
Type: Regular,
Language: languages.Yaml,
},
Expand All @@ -193,6 +198,7 @@ func TestValidateAllLanguages(t *testing.T) {
ID: "HS-LEAKS-10000",
Severity: severities.Low,
Confidence: confidence.Low,
Filter: "**/*",
Type: Regular,
Language: languages.Leaks,
},
Expand All @@ -206,6 +212,7 @@ func TestValidateAllLanguages(t *testing.T) {
ID: "HS-JAVASCRIPT-10000",
Severity: severities.Low,
Confidence: confidence.Low,
Filter: "**/*",
Type: Regular,
Language: languages.Javascript,
},
Expand All @@ -219,6 +226,7 @@ func TestValidateAllLanguages(t *testing.T) {
ID: "HS-NGINX-10000",
Severity: severities.Low,
Confidence: confidence.Low,
Filter: "**/*",
Type: Regular,
Language: languages.Nginx,
},
Expand All @@ -232,6 +240,7 @@ func TestValidateAllLanguages(t *testing.T) {
ID: "HS-NOT-CORRECT-10000",
Severity: severities.Low,
Confidence: confidence.Low,
Filter: "**/*",
Type: Regular,
Language: languages.Nginx,
},
Expand All @@ -245,6 +254,7 @@ func TestValidateAllLanguages(t *testing.T) {
ID: "HS-JAVA-10000",
Severity: severities.Low,
Confidence: confidence.Low,
Filter: "**/*",
Type: Regular,
Language: languages.Language("DOESNTEXIST"),
},
Expand Down Expand Up @@ -380,7 +390,7 @@ func TestToString(t *testing.T) {
validate func(s string)
}

crStr := "{\"id\":\"test123\",\"name\":\"\",\"description\":\"\",\"language\":\"\",\"severity\":\"\",\"confidence\":\"\",\"type\":\"\",\"expressions\":null}"
crStr := "{\"id\":\"test123\",\"name\":\"\",\"description\":\"\",\"language\":\"\",\"filter\":\"\",\"severity\":\"\",\"confidence\":\"\",\"type\":\"\",\"expressions\":null}"
tests := []test{
{
name: "should log an error when failed to compile expression",
Expand Down
1 change: 1 addition & 0 deletions internal/services/custom_rules/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (s *Service) parseCustomRuleToRule(rule *CustomRule) engine.Rule {
ID: rule.ID,
Name: rule.Name,
Description: rule.Description,
Filter: rule.Filter,
Severity: rule.Severity.ToString(),
Confidence: rule.Confidence.ToString(),
},
Expand Down