Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ You can also configure the hard-coded credentials rule `G101` with additional pa
}
```

#### Go version

Some rules require a specific Go version which is retrieved from the Go module file present in the project. If this version cannot be found, it will fallback to Go runtime version.

The Go module version is parsed using the `go list` command which in some cases might lead to performance degradation. In this situation, the go module version can be easily disabled by setting the environment variable `GOSECNOMODVERSION=on`.

### Dependencies

gosec will fetch automatically the dependencies of the code which is being analyzed when go module is turned on (e.g.`GO111MODULE=on`). If this is not the case,
Expand Down
14 changes: 9 additions & 5 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import (
"strings"
)

// noGoModVersion disables the parsing of go version from go module file present in the project
const noGoModVersion = "GOSECNOMODVERSION"

// MatchCallByPackage ensures that the specified package is imported,
// adjusts the name for any aliases and ignores cases that are
// initialization only imports.
Expand Down Expand Up @@ -498,12 +501,13 @@ func RootPath(root string) (string, error) {

// GoVersion returns parsed version of Go mod version and fallback to runtime version if not found.
func GoVersion() (int, int, int) {
goVersion, err := goModVersion()
if err != nil {
return parseGoVersion(strings.TrimPrefix(runtime.Version(), "go"))
_, ok := os.LookupEnv(noGoModVersion)
if ok {
if goModVersion, err := goModVersion(); err == nil {
return parseGoVersion(goModVersion)
}
}

return parseGoVersion(goVersion)
return parseGoVersion(strings.TrimPrefix(runtime.Version(), "go"))
}

type goListOutput struct {
Expand Down