Skip to content

fix(go): handle Go 1.26 GOEXPERIMENT version format change#10393

Closed
VoidChecksum wants to merge 1 commit intoaquasecurity:mainfrom
VoidChecksum:fix/go-1.26-goexperiment-version-parsing
Closed

fix(go): handle Go 1.26 GOEXPERIMENT version format change#10393
VoidChecksum wants to merge 1 commit intoaquasecurity:mainfrom
VoidChecksum:fix/go-1.26-goexperiment-version-parsing

Conversation

@VoidChecksum
Copy link
Copy Markdown

Summary

Go 1.26 changed the format used to embed GOEXPERIMENT flags in binary build info, switching the separator from a space to a dash:

Go version info.GoVersion format
≤ 1.25 go1.25.3 X:nodwarf5
≥ 1.26 go1.26.0-X:nodwarf5

Trivy's Go binary parser only stripped the suffix using strings.Cut(stdlibVersion, " "), which fails for the new format, producing v1.26.0-X:nodwarf5 — a malformed semver that can't match against the vulnerability DB.

Changes

  • Add a second strings.Cut(stdlibVersion, "-X:") to handle the Go 1.26+ format
  • Add test cases covering both old and new formats, multiple experiments, and no-experiment baselines
  • Reference: golang/go@9daaab3

Before

WARN Version matching error err="version error (v1.26.0-X:nodwarf5): malformed version: v1.26.0-X:nodwarf5"

After

stdlib version correctly extracted as v1.26.0

Test plan

  • Added TestStripGoExperiment with 7 test cases (both separators, multiple experiments, no experiment, patch-only)
  • Verify with real Go 1.26 binary containing GOEXPERIMENT flags
  • Run full test suite: go test ./pkg/dependency/parser/golang/binary/...

Fixes #10350

Go 1.26 changed the GOEXPERIMENT suffix separator from space to dash:
- Go <=1.25: "go1.25.3 X:boringcrypto"
- Go >=1.26: "go1.26.0-X:nodwarf5"

Add a second strings.Cut for the new "-X:" separator to correctly
extract stdlib versions from binaries built with Go 1.26+.

Fixes #10350
Copilot AI review requested due to automatic review settings March 16, 2026 11:12
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


VoidChecksum seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


VoidChecksum seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Trivy’s Go binary build-info parsing to correctly extract the stdlib version when Go 1.26+ embeds GOEXPERIMENT flags using the new -X: separator, preventing malformed semver strings from reaching version matching.

Changes:

  • Strip -X: GOEXPERIMENT suffix in Parser.Parse to support Go 1.26+ build-info format.
  • Add a test-only helper for GOEXPERIMENT stripping and a new table-driven unit test covering common cases.
  • Update test bridge exports/imports to support the new helper from the external binary_test package.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
pkg/dependency/parser/golang/binary/parse.go Extends stdlib version extraction to handle Go 1.26+ -X: GOEXPERIMENT suffix.
pkg/dependency/parser/golang/binary/parse_test.go Adds TestStripGoExperiment to validate suffix stripping behavior.
pkg/dependency/parser/golang/binary/export_test.go Exposes a test-only StripGoExperiment helper to the binary_test package.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +64 to 71
// Strip GOEXPERIMENT suffix:
// Go <=1.25: "go1.25.3 X:boringcrypto" (space separator)
// Go >=1.26: "go1.26.0-X:nodwarf5" (dash separator)
// Ref: https://github.com/golang/go/commit/9daaab305c4d1dede9e4f6efdc5e1268a69327e6
stdlibVersion := strings.TrimPrefix(info.GoVersion, "go")
stdlibVersion, _, _ = strings.Cut(stdlibVersion, " ")
stdlibVersion, _, _ = strings.Cut(stdlibVersion, "-X:")
// Add the `v` prefix to be consistent with module and dependency versions.
Comment on lines +375 to +406
func TestStripGoExperiment(t *testing.T) {
tests := []struct {
name string
input string
want string
}{
{
name: "Go 1.26+ dash separator",
input: "1.26.0-X:nodwarf5",
want: "1.26.0",
},
{
name: "Go <=1.25 space separator (boringcrypto)",
input: "1.25.3 X:boringcrypto",
want: "1.25.3",
},
{
name: "Go <=1.25 space separator (loopvar)",
input: "1.22.1 X:loopvar",
want: "1.22.1",
},
{
name: "No GOEXPERIMENT suffix",
input: "1.26.0",
want: "1.26.0",
},
{
name: "Regular version without experiment",
input: "1.22.3",
want: "1.22.3",
},
}
@nikpivkin
Copy link
Copy Markdown
Contributor

Hi @VoidChecksum !

Thanks for the contribution! There is already a PR addressing this issue: #10351

@nikpivkin nikpivkin closed this Mar 17, 2026
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.

bug(go): Go 1.26 GOEXPERIMENT version format change causes stdlib version parsing warning

4 participants