From f8842b1f04312a69de0fbbcbd7faa03b63c14e4b Mon Sep 17 00:00:00 2001 From: Ice3man Date: Sun, 16 Jun 2024 19:14:43 +0530 Subject: [PATCH] fix: fixed individual per tracker reporting filters (#5297) * fix: fixed individual per tracker reporting filters * added test case --- pkg/reporting/reporting.go | 2 +- pkg/reporting/trackers/gitea/gitea.go | 6 ++--- pkg/reporting/trackers/github/github.go | 6 ++--- pkg/reporting/trackers/gitlab/gitlab.go | 6 ++--- pkg/reporting/trackers/jira/jira.go | 6 ++--- pkg/reporting/trackers/jira/jira_test.go | 34 ++++++++++++++++++++++++ 6 files changed, 47 insertions(+), 13 deletions(-) diff --git a/pkg/reporting/reporting.go b/pkg/reporting/reporting.go index 08f32e9313..172c31105e 100644 --- a/pkg/reporting/reporting.go +++ b/pkg/reporting/reporting.go @@ -273,7 +273,7 @@ func (c *ReportingClient) CreateIssue(event *output.ResultEvent) error { for _, tracker := range c.trackers { // process tracker specific allow/deny list - if tracker.ShouldFilter(event) { + if !tracker.ShouldFilter(event) { continue } diff --git a/pkg/reporting/trackers/gitea/gitea.go b/pkg/reporting/trackers/gitea/gitea.go index acb82a1de2..e433689c74 100644 --- a/pkg/reporting/trackers/gitea/gitea.go +++ b/pkg/reporting/trackers/gitea/gitea.go @@ -139,15 +139,15 @@ func (i *Integration) CloseIssue(event *output.ResultEvent) error { // ShouldFilter determines if an issue should be logged to this tracker func (i *Integration) ShouldFilter(event *output.ResultEvent) bool { - if i.options.AllowList != nil && i.options.AllowList.GetMatch(event) { + if i.options.AllowList != nil && !i.options.AllowList.GetMatch(event) { return false } if i.options.DenyList != nil && i.options.DenyList.GetMatch(event) { - return true + return false } - return false + return true } func (i *Integration) findIssueByTitle(title string) (*gitea.Issue, error) { diff --git a/pkg/reporting/trackers/github/github.go b/pkg/reporting/trackers/github/github.go index 44c06102ca..8011d8da53 100644 --- a/pkg/reporting/trackers/github/github.go +++ b/pkg/reporting/trackers/github/github.go @@ -175,15 +175,15 @@ func (i *Integration) Name() string { // ShouldFilter determines if an issue should be logged to this tracker func (i *Integration) ShouldFilter(event *output.ResultEvent) bool { - if i.options.AllowList != nil && i.options.AllowList.GetMatch(event) { + if i.options.AllowList != nil && !i.options.AllowList.GetMatch(event) { return false } if i.options.DenyList != nil && i.options.DenyList.GetMatch(event) { - return true + return false } - return false + return true } func (i *Integration) findIssueByTitle(ctx context.Context, title string) (*github.Issue, error) { diff --git a/pkg/reporting/trackers/gitlab/gitlab.go b/pkg/reporting/trackers/gitlab/gitlab.go index 769165ad48..d816a26af6 100644 --- a/pkg/reporting/trackers/gitlab/gitlab.go +++ b/pkg/reporting/trackers/gitlab/gitlab.go @@ -164,13 +164,13 @@ func (i *Integration) CloseIssue(event *output.ResultEvent) error { // ShouldFilter determines if an issue should be logged to this tracker func (i *Integration) ShouldFilter(event *output.ResultEvent) bool { - if i.options.AllowList != nil && i.options.AllowList.GetMatch(event) { + if i.options.AllowList != nil && !i.options.AllowList.GetMatch(event) { return false } if i.options.DenyList != nil && i.options.DenyList.GetMatch(event) { - return true + return false } - return false + return true } diff --git a/pkg/reporting/trackers/jira/jira.go b/pkg/reporting/trackers/jira/jira.go index 1fd2895f13..5499445c87 100644 --- a/pkg/reporting/trackers/jira/jira.go +++ b/pkg/reporting/trackers/jira/jira.go @@ -315,13 +315,13 @@ func (i *Integration) FindExistingIssue(event *output.ResultEvent) (jira.Issue, // ShouldFilter determines if an issue should be logged to this tracker func (i *Integration) ShouldFilter(event *output.ResultEvent) bool { - if i.options.AllowList != nil && i.options.AllowList.GetMatch(event) { + if i.options.AllowList != nil && !i.options.AllowList.GetMatch(event) { return false } if i.options.DenyList != nil && i.options.DenyList.GetMatch(event) { - return true + return false } - return false + return true } diff --git a/pkg/reporting/trackers/jira/jira_test.go b/pkg/reporting/trackers/jira/jira_test.go index 247a440c58..d725a97b29 100644 --- a/pkg/reporting/trackers/jira/jira_test.go +++ b/pkg/reporting/trackers/jira/jira_test.go @@ -4,6 +4,10 @@ import ( "strings" "testing" + "github.com/projectdiscovery/nuclei/v3/pkg/model" + "github.com/projectdiscovery/nuclei/v3/pkg/model/types/severity" + "github.com/projectdiscovery/nuclei/v3/pkg/output" + "github.com/projectdiscovery/nuclei/v3/pkg/reporting/trackers/filters" "github.com/stretchr/testify/require" ) @@ -36,3 +40,33 @@ func TestTableCreation(t *testing.T) { ` require.Equal(t, expected, table) } + +func Test_ShouldFilter_Tracker(t *testing.T) { + jiraIntegration := &Integration{ + options: &Options{AllowList: &filters.Filter{ + Severities: severity.Severities{severity.Critical}, + }}, + } + + require.False(t, jiraIntegration.ShouldFilter(&output.ResultEvent{Info: model.Info{ + SeverityHolder: severity.Holder{Severity: severity.Info}, + }})) + require.True(t, jiraIntegration.ShouldFilter(&output.ResultEvent{Info: model.Info{ + SeverityHolder: severity.Holder{Severity: severity.Critical}, + }})) + + t.Run("deny-list", func(t *testing.T) { + jiraIntegration := &Integration{ + options: &Options{DenyList: &filters.Filter{ + Severities: severity.Severities{severity.Critical}, + }}, + } + + require.True(t, jiraIntegration.ShouldFilter(&output.ResultEvent{Info: model.Info{ + SeverityHolder: severity.Holder{Severity: severity.Info}, + }})) + require.False(t, jiraIntegration.ShouldFilter(&output.ResultEvent{Info: model.Info{ + SeverityHolder: severity.Holder{Severity: severity.Critical}, + }})) + }) +}