Skip to content

feat(dependencies): declare the Go standard library of a Go module - #140

Merged
matiasdaloia merged 2 commits into
mainfrom
feat/go-stdlib-component
Nov 17, 2026
Merged

matiasdaloia merged 2 commits into
mainfrom
feat/go-stdlib-component

Conversation

@matiasdaloia

Copy link
Copy Markdown
Contributor

Section 3 of #138.

Every Go binary links the standard library, and most Go vulnerabilities land there, but a Go root listed only its required modules. Now every go.mod declares pkg:golang/stdlib@<version> as a direct runtime dependency:

  • Version: the toolchain directive when set (go1.26.11), since that is the toolchain the go command switches to; otherwise the go directive (1.26.11 → go1.26.11). A go 1.26 without a patch release is kept as is: it is the oldest release the module allows.
  • go command resolver: reads both directives with go mod edit -json (no network); if that fails, the GoVersion go list already reports stands in.
  • Flat go.mod parser: reads the same two directives, with the directive's line as source location.

Name: stdlib, not std. #138 suggested cyclonedx-gomod's pkg:golang/std, but Grype v0.121.2 matches nothing on it. stdlib is the module name the Go vulnerability database files standard library advisories under, and the one Syft uses. Same component, Grype matches:

name version matches
std go1.23 0
stdlib go1.23 73
stdlib go1.26.0 48

Tests: directive cases for the parser (go, toolchain over go, no patch, none) and GoStdVersion; a new toolchain-directive golden for the resolver (go 1.22 + toolchain go1.22.12 → stdlib@go1.22.12); the existing goldens now carry stdlib@go1.22.

Checked on a real project (scanoss.api v0.41.3, dependencies . --extract-local --format cyclonedx, then Grype): the root gets pkg:golang/stdlib@go1.26.11 with 0 matches, which agrees with govulncheck on that build; the nested sdk/go module gets stdlib@go1.23 with 73. That nested module is not in the shipped binary: scoping to what ships is section 2.

Every Go binary links the standard library, and most Go vulnerabilities
land there, but a Go root listed only its required modules. A go.mod now
declares pkg:golang/stdlib at the toolchain it builds with: the toolchain
directive when set, else the go directive. Both the go command resolver
(go mod edit -json, falling back to go list's GoVersion) and the flat
go.mod parser emit it.

It is named stdlib, as the Go vulnerability database and Syft name it:
Grype matches nothing on cyclonedx-gomod's "std".

Refs #138
@matiasdaloia
matiasdaloia merged commit b7a8a83 into main Nov 17, 2026
15 checks passed
@matiasdaloia
matiasdaloia deleted the feat/go-stdlib-component branch November 17, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant