Skip to content

Commit

Permalink
fix: fixed individual per tracker reporting filters (#5297)
Browse files Browse the repository at this point in the history
* fix: fixed individual per tracker reporting filters

* added test case
  • Loading branch information
Ice3man543 committed Jun 16, 2024
1 parent b274fe5 commit f8842b1
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/reporting/reporting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/reporting/trackers/gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/reporting/trackers/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/reporting/trackers/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions pkg/reporting/trackers/jira/jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
34 changes: 34 additions & 0 deletions pkg/reporting/trackers/jira/jira_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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},
}}))
})
}

0 comments on commit f8842b1

Please sign in to comment.