Skip to content

Commit e102cae

Browse files
omit raw from integrations (#4612)
* omit raw from integrations * fix lint
1 parent b9e2665 commit e102cae

File tree

10 files changed

+57
-61
lines changed

10 files changed

+57
-61
lines changed

internal/runner/options.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,27 +262,28 @@ func createReportingOptions(options *types.Options) (*reporting.Options, error)
262262
}
263263
if options.MarkdownExportDirectory != "" {
264264
reportingOptions.MarkdownExporter = &markdown.Options{
265-
Directory: options.MarkdownExportDirectory,
266-
IncludeRawPayload: !options.OmitRawRequests,
267-
SortMode: options.MarkdownExportSortMode,
265+
Directory: options.MarkdownExportDirectory,
266+
OmitRaw: options.OmitRawRequests,
267+
SortMode: options.MarkdownExportSortMode,
268268
}
269269
}
270270
if options.SarifExport != "" {
271271
reportingOptions.SarifExporter = &sarif.Options{File: options.SarifExport}
272272
}
273273
if options.JSONExport != "" {
274274
reportingOptions.JSONExporter = &jsonexporter.Options{
275-
File: options.JSONExport,
276-
IncludeRawPayload: !options.OmitRawRequests,
275+
File: options.JSONExport,
276+
OmitRaw: options.OmitRawRequests,
277277
}
278278
}
279279
if options.JSONLExport != "" {
280280
reportingOptions.JSONLExporter = &jsonl.Options{
281-
File: options.JSONLExport,
282-
IncludeRawPayload: !options.OmitRawRequests,
281+
File: options.JSONLExport,
282+
OmitRaw: options.OmitRawRequests,
283283
}
284284
}
285285

286+
reportingOptions.OmitRaw = options.OmitRawRequests
286287
return reportingOptions, nil
287288
}
288289

pkg/reporting/exporters/jsonexporter/jsonexporter.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package jsonexporter
22

33
import (
44
"encoding/json"
5-
"github.com/pkg/errors"
6-
"github.com/projectdiscovery/nuclei/v3/pkg/output"
75
"os"
86
"sync"
7+
8+
"github.com/pkg/errors"
9+
"github.com/projectdiscovery/nuclei/v3/pkg/output"
910
)
1011

1112
type Exporter struct {
@@ -17,8 +18,8 @@ type Exporter struct {
1718
// Options contains the configuration options for JSON exporter client
1819
type Options struct {
1920
// File is the file to export found JSON result to
20-
File string `yaml:"file"`
21-
IncludeRawPayload bool `yaml:"include-raw-payload"`
21+
File string `yaml:"file"`
22+
OmitRaw bool `yaml:"omit-raw"`
2223
}
2324

2425
// New creates a new JSON exporter integration client based on options.
@@ -37,11 +38,7 @@ func (exporter *Exporter) Export(event *output.ResultEvent) error {
3738
exporter.mutex.Lock()
3839
defer exporter.mutex.Unlock()
3940

40-
// If the IncludeRawPayload is not set, then set the request and response to an empty string in the event to avoid
41-
// writing them to the list of events.
42-
// This will reduce the amount of storage as well as the fields being excluded from the resulting JSON output since
43-
// the property is set to "omitempty"
44-
if !exporter.options.IncludeRawPayload {
41+
if exporter.options.OmitRaw {
4542
event.Request = ""
4643
event.Response = ""
4744
}

pkg/reporting/exporters/jsonl/jsonl.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package jsonl
22

33
import (
44
"encoding/json"
5-
"github.com/pkg/errors"
6-
"github.com/projectdiscovery/nuclei/v3/pkg/output"
75
"os"
86
"sync"
7+
8+
"github.com/pkg/errors"
9+
"github.com/projectdiscovery/nuclei/v3/pkg/output"
910
)
1011

1112
type Exporter struct {
@@ -17,8 +18,8 @@ type Exporter struct {
1718
// Options contains the configuration options for JSONL exporter client
1819
type Options struct {
1920
// File is the file to export found JSONL result to
20-
File string `yaml:"file"`
21-
IncludeRawPayload bool `yaml:"include-raw-payload"`
21+
File string `yaml:"file"`
22+
OmitRaw bool `yaml:"omit-raw"`
2223
}
2324

2425
// New creates a new JSONL exporter integration client based on options.
@@ -37,11 +38,7 @@ func (exporter *Exporter) Export(event *output.ResultEvent) error {
3738
exporter.mutex.Lock()
3839
defer exporter.mutex.Unlock()
3940

40-
// If the IncludeRawPayload is not set, then set the request and response to an empty string in the event to avoid
41-
// writing them to the list of events.
42-
// This will reduce the amount of storage as well as the fields being excluded from the resulting JSONL output since
43-
// the property is set to "omitempty"
44-
if !exporter.options.IncludeRawPayload {
41+
if exporter.options.OmitRaw {
4542
event.Request = ""
4643
event.Response = ""
4744
}

pkg/reporting/exporters/markdown/markdown.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ type Exporter struct {
2626
// Options contains the configuration options for GitHub issue tracker client
2727
type Options struct {
2828
// Directory is the directory to export found results to
29-
Directory string `yaml:"directory"`
30-
IncludeRawPayload bool `yaml:"include-raw-payload"`
31-
SortMode string `yaml:"sort-mode"`
29+
Directory string `yaml:"directory"`
30+
OmitRaw bool `yaml:"omit-raw"`
31+
SortMode string `yaml:"sort-mode"`
3232
}
3333

3434
// New creates a new markdown exporter integration client based on options.
@@ -56,15 +56,6 @@ func New(options *Options) (*Exporter, error) {
5656

5757
// Export exports a passed result event to markdown
5858
func (exporter *Exporter) Export(event *output.ResultEvent) error {
59-
// If the IncludeRawPayload is not set, then set the request and response to an empty string in the event to avoid
60-
// writing them to the list of events.
61-
// This will reduce the amount of storage as well as the fields being excluded from the markdown report output since
62-
// the property is set to "omitempty"
63-
if !exporter.options.IncludeRawPayload {
64-
event.Request = ""
65-
event.Response = ""
66-
}
67-
6859
// index file generation
6960
file, err := os.OpenFile(filepath.Join(exporter.directory, indexFileName), os.O_APPEND|os.O_WRONLY, 0644)
7061
if err != nil {
@@ -114,7 +105,7 @@ func (exporter *Exporter) Export(event *output.ResultEvent) error {
114105
dataBuilder.WriteString(util.CreateHeading3(format.Summary(event)))
115106
dataBuilder.WriteString("\n")
116107
dataBuilder.WriteString(util.CreateHorizontalLine())
117-
dataBuilder.WriteString(format.CreateReportDescription(event, util.MarkdownFormatter{}))
108+
dataBuilder.WriteString(format.CreateReportDescription(event, util.MarkdownFormatter{}, exporter.options.OmitRaw))
118109
data := dataBuilder.Bytes()
119110

120111
return os.WriteFile(filepath.Join(exporter.directory, subdirectory, filename), data, 0644)

pkg/reporting/format/format_utils.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func GetMatchedTemplateName(event *output.ResultEvent) string {
3434
return matchedTemplateName
3535
}
3636

37-
func CreateReportDescription(event *output.ResultEvent, formatter ResultFormatter) string {
37+
func CreateReportDescription(event *output.ResultEvent, formatter ResultFormatter, omitRaw bool) string {
3838
template := GetMatchedTemplateName(event)
3939
builder := &bytes.Buffer{}
4040
builder.WriteString(fmt.Sprintf("%s: %s matched at %s\n\n", formatter.MakeBold("Details"), formatter.MakeBold(template), event.Host))
@@ -51,20 +51,22 @@ func CreateReportDescription(event *output.ResultEvent, formatter ResultFormatte
5151
builder.WriteString("\n\n")
5252
builder.WriteString(CreateTemplateInfoTable(&event.Info, formatter))
5353

54-
if event.Request != "" {
55-
builder.WriteString(formatter.CreateCodeBlock("Request", types.ToHexOrString(event.Request), "http"))
56-
}
57-
if event.Response != "" {
58-
var responseString string
59-
// If the response is larger than 5 kb, truncate it before writing.
60-
maxKbSize := 5 * 1024
61-
if len(event.Response) > maxKbSize {
62-
responseString = event.Response[:maxKbSize]
63-
responseString += ".... Truncated ...."
64-
} else {
65-
responseString = event.Response
54+
if !omitRaw {
55+
if event.Request != "" {
56+
builder.WriteString(formatter.CreateCodeBlock("Request", types.ToHexOrString(event.Request), "http"))
57+
}
58+
if event.Response != "" {
59+
var responseString string
60+
// If the response is larger than 5 kb, truncate it before writing.
61+
maxKbSize := 5 * 1024
62+
if len(event.Response) > maxKbSize {
63+
responseString = event.Response[:maxKbSize]
64+
responseString += ".... Truncated ...."
65+
} else {
66+
responseString = event.Response
67+
}
68+
builder.WriteString(formatter.CreateCodeBlock("Response", responseString, "http"))
6669
}
67-
builder.WriteString(formatter.CreateCodeBlock("Response", responseString, "http"))
6870
}
6971

7072
if len(event.ExtractedResults) > 0 || len(event.Metadata) > 0 {

pkg/reporting/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ type Options struct {
3939
JSONLExporter *jsonl.Options `yaml:"jsonl"`
4040

4141
HttpClient *retryablehttp.Client `yaml:"-"`
42+
OmitRaw bool `yaml:"-"`
4243
}

pkg/reporting/reporting.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func New(options *Options, db string) (Client, error) {
9999

100100
if options.GitHub != nil {
101101
options.GitHub.HttpClient = options.HttpClient
102+
options.GitHub.OmitRaw = options.OmitRaw
102103
tracker, err := github.New(options.GitHub)
103104
if err != nil {
104105
return nil, errorutil.NewWithErr(err).Wrap(ErrReportingClientCreation)
@@ -107,6 +108,7 @@ func New(options *Options, db string) (Client, error) {
107108
}
108109
if options.GitLab != nil {
109110
options.GitLab.HttpClient = options.HttpClient
111+
options.GitLab.OmitRaw = options.OmitRaw
110112
tracker, err := gitlab.New(options.GitLab)
111113
if err != nil {
112114
return nil, errorutil.NewWithErr(err).Wrap(ErrReportingClientCreation)
@@ -115,6 +117,7 @@ func New(options *Options, db string) (Client, error) {
115117
}
116118
if options.Jira != nil {
117119
options.Jira.HttpClient = options.HttpClient
120+
options.Jira.OmitRaw = options.OmitRaw
118121
tracker, err := jira.New(options.Jira)
119122
if err != nil {
120123
return nil, errorutil.NewWithErr(err).Wrap(ErrReportingClientCreation)

pkg/reporting/trackers/github/github.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ package github
33
import (
44
"context"
55
"fmt"
6+
"io"
7+
"net/http"
8+
"net/url"
9+
"strings"
10+
611
"github.com/google/go-github/github"
712
"github.com/pkg/errors"
813
"github.com/projectdiscovery/nuclei/v3/pkg/output"
@@ -11,10 +16,6 @@ import (
1116
"github.com/projectdiscovery/nuclei/v3/pkg/types"
1217
"github.com/projectdiscovery/retryablehttp-go"
1318
"golang.org/x/oauth2"
14-
"io"
15-
"net/http"
16-
"net/url"
17-
"strings"
1819
)
1920

2021
// Integration is a client for an issue tracker integration
@@ -45,6 +46,7 @@ type Options struct {
4546
DuplicateIssueCheck bool `yaml:"duplicate-issue-check"`
4647

4748
HttpClient *retryablehttp.Client `yaml:"-"`
49+
OmitRaw bool `yaml:"-"`
4850
}
4951

5052
// New creates a new issue tracker integration client based on options.
@@ -80,7 +82,7 @@ func New(options *Options) (*Integration, error) {
8082
// CreateIssue creates an issue in the tracker
8183
func (i *Integration) CreateIssue(event *output.ResultEvent) (err error) {
8284
summary := format.Summary(event)
83-
description := format.CreateReportDescription(event, util.MarkdownFormatter{})
85+
description := format.CreateReportDescription(event, util.MarkdownFormatter{}, i.options.OmitRaw)
8486
labels := []string{}
8587
severityLabel := fmt.Sprintf("Severity: %s", event.Info.SeverityHolder.Severity.String())
8688
if i.options.SeverityAsLabel && severityLabel != "" {

pkg/reporting/trackers/gitlab/gitlab.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type Options struct {
3737
DuplicateIssueCheck bool `yaml:"duplicate-issue-check" default:"false"`
3838

3939
HttpClient *retryablehttp.Client `yaml:"-"`
40+
OmitRaw bool `yaml:"-"`
4041
}
4142

4243
// New creates a new issue tracker integration client based on options.
@@ -62,7 +63,7 @@ func New(options *Options) (*Integration, error) {
6263
// CreateIssue creates an issue in the tracker
6364
func (i *Integration) CreateIssue(event *output.ResultEvent) error {
6465
summary := format.Summary(event)
65-
description := format.CreateReportDescription(event, util.MarkdownFormatter{})
66+
description := format.CreateReportDescription(event, util.MarkdownFormatter{}, i.options.OmitRaw)
6667
labels := []string{}
6768
severityLabel := fmt.Sprintf("Severity: %s", event.Info.SeverityHolder.Severity.String())
6869
if i.options.SeverityAsLabel && severityLabel != "" {

pkg/reporting/trackers/jira/jira.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type Options struct {
7777
// that will be used to create the issue
7878
CustomFields map[string]interface{} `yaml:"custom-fields" json:"custom_fields"`
7979
StatusNot string `yaml:"status-not" json:"status_not"`
80+
OmitRaw bool `yaml:"-"`
8081
}
8182

8283
// New creates a new issue tracker integration client based on options.
@@ -154,7 +155,7 @@ func (i *Integration) CreateNewIssue(event *output.ResultEvent) error {
154155
}
155156
}
156157
fields := &jira.IssueFields{
157-
Description: format.CreateReportDescription(event, i),
158+
Description: format.CreateReportDescription(event, i, i.options.OmitRaw),
158159
Unknowns: customFields,
159160
Type: jira.IssueType{Name: i.options.IssueType},
160161
Project: jira.Project{Key: i.options.ProjectName},
@@ -164,7 +165,7 @@ func (i *Integration) CreateNewIssue(event *output.ResultEvent) error {
164165
if !i.options.Cloud {
165166
fields = &jira.IssueFields{
166167
Assignee: &jira.User{Name: i.options.AccountID},
167-
Description: format.CreateReportDescription(event, i),
168+
Description: format.CreateReportDescription(event, i, i.options.OmitRaw),
168169
Type: jira.IssueType{Name: i.options.IssueType},
169170
Project: jira.Project{Key: i.options.ProjectName},
170171
Summary: summary,
@@ -196,7 +197,7 @@ func (i *Integration) CreateIssue(event *output.ResultEvent) error {
196197
return err
197198
} else if issueID != "" {
198199
_, _, err = i.jira.Issue.AddComment(issueID, &jira.Comment{
199-
Body: format.CreateReportDescription(event, i),
200+
Body: format.CreateReportDescription(event, i, i.options.OmitRaw),
200201
})
201202
return err
202203
}

0 commit comments

Comments
 (0)