Skip to content

gosec: filter issues according to the severity and confidence #2295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add tests for severity and confidence
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx authored and ldez committed Oct 27, 2021
commit ddad3170d865352b107457275cd9551608c71bfd
4 changes: 2 additions & 2 deletions .golangci.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ linters-settings:
# Exclude generated files
exclude-generated: true
# Filter out the issues with a lower severity than the given value. Valid options are: low, medium, high.
severity: "high"
severity: "low"
# Filter out the issues with a lower confidence than the given value. Valid options are: low, medium, high.
confidence: "medium"
confidence: "low"
# To specify the configuration of rules.
# The configuration of rules is not fully documented by gosec:
# https://github.com/securego/gosec#configuration
Expand Down
6 changes: 3 additions & 3 deletions pkg/golinters/gosec.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ func NewGosec(settings *config.GoSecSettings) *goanalysis.Linter {
}
severity, err := convertToScore(settings.Severity)
if err != nil {
lintCtx.Log.Warnf("The provided severity %q is invalid, use low instead. Valid options: low, medium, high", err)
lintCtx.Log.Warnf("The provided severity %v", err)
}

confidence, err := convertToScore(settings.Confidence)
if err != nil {
lintCtx.Log.Warnf("The provided confidence %q is invalid, use low instead. Valid options: low, medium, high", err)
lintCtx.Log.Warnf("The provided confidence %v", err)
}
issues = filterIssues(issues, severity, confidence)
res := make([]goanalysis.Issue, 0, len(issues))
Expand Down Expand Up @@ -148,7 +148,7 @@ func convertToScore(str string) (gosec.Score, error) {
case "high":
return gosec.High, nil
default:
return gosec.Low, errors.Errorf("'%s' not valid", str)
return gosec.Low, errors.Errorf("'%s' is invalid, use low instead. Valid options: low, medium, high", str)
}
}

Expand Down
4 changes: 4 additions & 0 deletions test/testdata/configs/gosec_severity_confidence.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
linters-settings:
gosec:
severity: "medium"
confidence: "medium"
31 changes: 31 additions & 0 deletions test/testdata/gosec_severity_confidence.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//args: -Egosec
//config_path: testdata/configs/gosec_severity_confidence.yml
package testdata

import (
"fmt"
"io/ioutil"
"net/http"
)

var url string = "https://www.abcdefghijk.com"

func gosecVariableURL() {
resp, err := http.Get(url) // ERROR "G107: Potential HTTP request made with variable url"
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Printf("%s", body)
}

func gosecHardcodedCredentials() {
username := "admin"
var password = "f62e5bcda4fae4f82370da0c6f20697b8f8447ef"

fmt.Println("Doing something with: ", username, password)
}