Skip to content

Commit

Permalink
revert changes on jsonl (don't aggregate results)
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardottt committed Oct 16, 2023
1 parent a43092c commit 3bb36e2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pkg/output/jsonl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@
==========
Cariddi
==========
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
@Repository: https://github.com/edoardottt/cariddi
@Author: edoardottt, https://www.edoardoottavianelli.it
@License: https://github.com/edoardottt/cariddi/blob/main/LICENSE
*/

package output

import (
Expand All @@ -39,6 +46,7 @@ type JSONData struct {
Matches *MatcherResults `json:"matches,omitempty"`
// Host string `json:"host"` # TODO: Available in Colly 2.x
}

type MatcherResults struct {
FileType *scanner.FileType `json:"filetype,omitempty"`
Parameters []scanner.Parameter `json:"parameters,omitempty"`
Expand Down Expand Up @@ -74,14 +82,17 @@ func GetJSONString(
if len(contentTypes) > 0 {
contentType = strings.Split(contentTypes[0], "; ")[0]
}

// Set content length
if len(contentLengths) > 0 {
ret, err := strconv.Atoi(contentLengths[0])
if err != nil {
return nil, err
}

contentLength = ret
}

// Parse words from body
words := len(strings.Fields(string(r.Body)))
// Parse lines from body
Expand Down Expand Up @@ -124,8 +135,9 @@ func GetJSONString(
ContentType: contentType,
ContentLength: contentLength,
Matches: matcherResults,
// Host: "", // TODO: this is available in Colly 2.x
// Host: "", // TODO
}

// Set empty data if no matches to bridge the omitempty gap for empty structs
var (
isFileTypeNill = false
Expand All @@ -139,9 +151,11 @@ func GetJSONString(
matcherResults.FileType = nil
isFileTypeNill = true
}

if isFileTypeNill && isParametersEmpty && isErrorsEmpty && isInfoEmpty && isSecretsEmpty {
resp.Matches = nil
}

// Convert struct to JSON string
jsonOutput, err := json.Marshal(resp)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions pkg/output/jsonl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@
==========
Cariddi
==========
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
@Repository: https://github.com/edoardottt/cariddi
@Author: edoardottt, https://www.edoardoottavianelli.it
@License: https://github.com/edoardottt/cariddi/blob/main/LICENSE
*/

package output_test

import (
Expand All @@ -34,6 +41,7 @@ func TestJSONOutput(t *testing.T) {
headers := http.Header{}
headers.Set("Content-Type", "application/pdf")
headers.Set("Content-Length", "128")

secrets := []scanner.SecretMatched{
{
Secret: scanner.Secret{
Expand Down

0 comments on commit 3bb36e2

Please sign in to comment.