Vulnerability Checks: govulncheck
Minimal version selection never upgrades on its own, so a known-vulnerable version stays in your build until someone notices. govulncheck is the Go team's tool for noticing. It compares your module graph with the Go vulnerability database (vuln.go.dev), and, unlike most scanners, it also analyses your call graph: it tells you whether your code actually reaches the vulnerable function, not just whether the module is present.
In this course's container govulncheck 1.9.0 runs offline against a snapshot of the database taken when the image was built (a small wrapper passes -db file:///opt/vulndb). On your machine it downloads the current database.
A vulnerable dependency, called
The old golang.org/x/text that rsc.io/sampler drags in has known bugs. This program calls language.ParseAcceptLanguage directly:
mkdir app && cd app
go mod init example.com/app 2>/dev/null
cat > main.go <<'SRC'
package main
import (
"fmt"
"golang.org/x/text/language"
"rsc.io/quote"
)
func main() {
tags, _, err := language.ParseAcceptLanguage("fr-CH, en;q=0.8")
fmt.Println(quote.Hello(), tags, err)
}
SRC
go get rsc.io/quote@v1.5.2 2>/dev/null
go mod tidy
go run .
govulncheck ./...
echo "exit=$?"Ahoy, world! [fr-CH en] <nil>
=== Symbol Results ===
Vulnerability #1: GO-2022-1059
Denial of service via crafted Accept-Language header in
golang.org/x/text/language
More info: https://pkg.go.dev/vuln/GO-2022-1059
Module: golang.org/x/text
Found in: golang.org/x/text@v0.0.0-20170915032832-14c0d48ead0c
Fixed in: golang.org/x/text@v0.3.8
Example traces found:
#1: main.go:11:46: app.main calls language.ParseAcceptLanguage
Vulnerability #2: GO-2021-0113
Out-of-bounds read in golang.org/x/text/language
More info: https://pkg.go.dev/vuln/GO-2021-0113
Module: golang.org/x/text
Found in: golang.org/x/text@v0.0.0-20170915032832-14c0d48ead0c
Fixed in: golang.org/x/text@v0.3.7
Example traces found:
#1: main.go:11:46: app.main calls language.ParseAcceptLanguage
Your code is affected by 2 vulnerabilities from 1 module.
This scan also found 0 vulnerabilities in packages you import and 3
vulnerabilities in modules you require, but your code doesn't appear to call
these vulnerabilities.
Use '-show verbose' for more details.
exit=3
The report has three levels:
| Level | Meaning | Action |
|---|---|---|
| Symbol results | your code (transitively) calls a vulnerable function; a trace shows where | fix now |
| Package results | you import a vulnerable package but don't reach the bad function | upgrade soon |
| Module results | a required module has a vulnerability in code you don't import | upgrade when convenient |
Exit status 3 means "affected" (symbol-level findings), so govulncheck ./... can fail a CI job directly. Package- and module-level findings alone exit 0 by default; -show verbose prints them.
The fix is an upgrade
Each finding names the first fixed version. One go get moves x/text past all of them, and MVS keeps it there even though sampler still asks for the 2017 version:
mkdir app && cd app
go mod init example.com/app 2>/dev/null
cat > main.go <<'SRC'
package main
import (
"fmt"
"golang.org/x/text/language"
"rsc.io/quote"
)
func main() {
tags, _, err := language.ParseAcceptLanguage("fr-CH, en;q=0.8")
fmt.Println(quote.Hello(), tags, err)
}
SRC
go get rsc.io/quote@v1.5.2 2>/dev/null
go mod tidy
go get golang.org/x/text@v0.43.0
go run .
govulncheck -show verbose ./...
echo "exit=$?"
go mod graph | grep ' golang.org/x/text@'go: downloading golang.org/x/text v0.43.0
go: upgraded golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c => v0.43.0
Ahoy, world! [fr-CH en] <nil>
Fetching vulnerabilities from the database...
Checking the code against the vulnerabilities...
The package pattern matched the following root package:
example.com/app
Govulncheck scanned the following 4 modules and the go1.27.3 standard library:
example.com/app
golang.org/x/text@v0.43.0
rsc.io/quote@v1.5.2
rsc.io/sampler@v1.3.0
No vulnerabilities found.
exit=0
example.com/app golang.org/x/text@v0.43.0
rsc.io/sampler@v1.3.0 golang.org/x/text@v0.0.0-20170915032832-14c0d48ead0c
The graph still contains sampler's old requirement; the build list doesn't. Your go.mod's higher requirement is the fix. tidy keeps it, because since Go 1.17 the main module's go.mod records the selected version of every module that provides a package to the build (as // indirect when you don't import it yourself). Don't hand-edit it back down.
Other modes
| Command | Use |
|---|---|
govulncheck ./... |
source mode: needs the code, does call analysis (the default) |
govulncheck -mode=binary ./app |
scan a compiled binary using its embedded build info; works on binaries you didn't build |
govulncheck -format json ./... / -format sarif / -format openvex |
machine-readable output for CI dashboards, GitHub code scanning, VEX documents |
govulncheck -scan module |
module-level only (fast, no call analysis) |
The standard library is checked too: a vulnerability in, say, net/http of your Go version shows up as a finding whose fix is "build with Go 1.x.y". Keep CI images on the latest patch release.
Note: govulncheck only knows the Go vulnerability database. It does not check licences, malware or typosquatting, and it can't see C libraries linked with cgo. Those belong to the broader Software Supply Chain Security toolset (SBOMs, Grype/Trivy, signatures).
Test yourself
What makes govulncheck different from a scanner that only reads go.mod?
- It is faster
- It analyses the call graph and reports whether your code actually reaches the vulnerable function
- It fixes vulnerabilities automatically
- It only checks the standard library
govulncheck exits with status 3. What does that mean?
- The database could not be loaded
- Your code is affected by at least one vulnerability (a symbol-level finding)
- Only module-level findings
- A build error
A dependency requires a vulnerable x/text version. How do you fix your build?
- Wait for the dependency to release
go get golang.org/x/text@<fixed version>: MVS selects your higher requirement- Add
excludefor every old version - Vendor and patch it