Skip to content

gosec not detecting an expected issue and output wrongly formatted if no issue #333

@andrea-tortosa

Description

@andrea-tortosa

Summary

gosec sonarqube format sometimes returns

{
	"issues": null
}

when it should not because a vulnerability is in the code.
As a consequence of this SonarQube is not able to process these results and fails with

ERROR: Error during SonarQube Scanner execution
java.lang.NullPointerException
	at org.sonar.scanner.externalissue.ReportParser.validate(ReportParser.java:52)
	at org.sonar.scanner.externalissue.ReportParser.parse(ReportParser.java:43)

This gosec output is returned also if no issue is in the code but it is not correctly managed by SonarQube

Steps to reproduce the behavior

Running

gosec -fmt=sonarqube -out gosec-report.json ./... 

within a cloned repo integrated with Travis and just containing a main.go file as:

package main

import (	
	"fmt"	
	"github.com/streadway/amqp"
)

func main() {	
	var password = "f62e5bcda4fae4f82370da0c6f20697b8f8447ef"
	fmt.Printf(password)
}

it meets the error as above described. If the file is modified to

package main

import (	
	"fmt"	
	"math"
)

func main() {	
	var password = "f62e5bcda4fae4f82370da0c6f20697b8f8447ef"
	fmt.Printf(password)
}

the following is correctly returned

{
	"issues": [
		{
			"engineId": "gosec",
			"ruleId": "G101",
			"primaryLocation": {
				"message": "Potential hardcoded credentials",
				"filePath": "main.go",
				"textRange": {
					"startLine": 9,
					"endLine": 9
				}
			},
			"type": "VULNERABILITY",
			"severity": "BLOCKER",
			"effortMinutes": 5
		}
	]
}

The vulnerability should also be detected in the previous case.
Please notice that the output below

{
	"issues": null
}

is also returned when effectively there is no issue such as in the case the main.go file is

package main

import (	
	"fmt"	
	"math"
)

func main() {	
	fmt.Println(math.Exp2(10))
}

but SonarQube is not able to manage it and get again the exception above reported.
It should be the following if no issue is detected

{
	"issues": []
}

Used Sonar scanner cli version is sonar-scanner-4.0.0.1744-linux.

gosec version

Installed a few minutes ago through go get github.com/securego/gosec/cmd/gosec/...
and latest release in github.com is 2.0.0

Go version (output of 'go version')

1.12.3

Operating system / Environment

Operating System Details
Distributor ID: Ubuntu
Description: Ubuntu 16.04.6 LTS
Release: 16.04
Codename: xenial

Expected behavior

G101 vulnerability should be detected

Actual behavior

G101 vulnerability is not detected and the output file is not correctly formatted

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions