From 03d9ce059bfeb1622b5780faaf886340fff75b6e Mon Sep 17 00:00:00 2001 From: Olivier Cervello Date: Tue, 21 Mar 2023 14:10:16 +0000 Subject: [PATCH] fix linting --- pkg/crawler/colly.go | 2 +- pkg/output/beautify.go | 4 ++-- pkg/output/json.go | 24 ++++++++++++++---------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/pkg/crawler/colly.go b/pkg/crawler/colly.go index 0e9b4ac..986316e 100644 --- a/pkg/crawler/colly.go +++ b/pkg/crawler/colly.go @@ -219,7 +219,7 @@ func New(scan *Scan) *Results { } } if scan.JSON { - jsonOutput, err := output.GetJsonString( + jsonOutput, err := output.GetJSONString( r, secrets, parameters, filetype, errors, infos, ) if err == nil { diff --git a/pkg/output/beautify.go b/pkg/output/beautify.go index bb59bd3..29ed3f7 100644 --- a/pkg/output/beautify.go +++ b/pkg/output/beautify.go @@ -49,7 +49,7 @@ func Beautify() { bannerPart2 := banner6 + banner7 + banner8 + banner9 color.Set(color.FgCyan) - fmt.Fprintf(os.Stderr, bannerPart1) + fmt.Fprint(os.Stderr, bannerPart1) color.Unset() - fmt.Fprintf(os.Stderr, bannerPart2) + fmt.Fprint(os.Stderr, bannerPart2) } diff --git a/pkg/output/json.go b/pkg/output/json.go index 673d8ff..5b3e269 100644 --- a/pkg/output/json.go +++ b/pkg/output/json.go @@ -35,7 +35,7 @@ import ( "github.com/gocolly/colly" ) -type JsonData struct { +type JSONData struct { URL string `json:"url"` Method string `json:"method"` StatusCode int `json:"status_code"` @@ -60,7 +60,7 @@ type MatcherResult struct { Match string `json:"match"` } -func GetJsonString( +func GetJSONString( r *colly.Response, secrets []scanner.SecretMatched, parameters []scanner.Parameter, @@ -68,22 +68,28 @@ func GetJsonString( errors []scanner.ErrorMatched, infos []scanner.InfoMatched, ) ([]byte, error) { - // Parse response headers headers := r.Headers contentTypes := (*headers)["Content-Type"] + contentLengths := (*headers)["Content-Length"] contentType := "" + contentLength := 0 + errorList := []MatcherResult{} + infoList := []MatcherResult{} + secretList := []MatcherResult{} + + // Set content type if len(contentTypes) > 0 { contentType = contentTypes[0] } - contentLength := 0 - contentLengths := (*headers)["Content-Length"] + // Set content length if len(contentLengths) > 0 { ret, err := strconv.Atoi(contentLengths[0]) if err != nil { return nil, err } + contentLength = ret } @@ -94,21 +100,19 @@ func GetJsonString( lines := len(strings.Split(string(r.Body), "\n")) // Process secrets - secretList := []MatcherResult{} for _, secret := range secrets { secretMatch := MatcherResult{secret.Secret.Name, secret.Match} secretList = append(secretList, secretMatch) } // Process infos - infoList := []MatcherResult{} + for _, info := range infos { secretMatch := MatcherResult{info.Info.Name, info.Match} infoList = append(infoList, secretMatch) } - // Process - errorList := []MatcherResult{} + // Process errors for _, error := range errors { errorMatch := MatcherResult{error.Error.ErrorName, error.Match} errorList = append(errorList, errorMatch) @@ -122,7 +126,7 @@ func GetJsonString( Infos: infoList, Secrets: secretList, } - resp := &JsonData{ + resp := &JSONData{ URL: r.Request.URL.String(), Method: r.Request.Method, StatusCode: r.StatusCode,