Skip to content
Open
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
8 changes: 7 additions & 1 deletion docs/guide/coverage/os/echo.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ Same as [Debian](debian.md#license).

## Language Packages
Echo provides patched versions of language packages.
Trivy identifies them by the version suffix and uses Echo's own security advisories from the [Echo OSV feed][osv-feed] for them instead of the upstream ones.
Trivy identifies them by the version suffix and checks both upstream advisories and Echo's own advisories from the [Echo OSV feed][osv-feed].
Upstream advisories are evaluated against the base version before `+echo.N`, while Echo advisories are evaluated against the full Echo version.
When Echo has an advisory with the same primary vulnerability ID, the Echo advisory replaces the upstream one so that Echo fixes are taken into account.
Unrelated upstream advisories remain in the scan, and an upstream advisory is used when there is no active Echo advisory for that vulnerability.

If a version-specific `not_applicable` decision is published only as a withdrawn Echo OSV record, Trivy has no active Echo advisory to apply and reports a matching upstream advisory.
Known non-applicable findings can be filtered with [VEX](../../supply-chain/vex/index.md).

| Ecosystem | Version Suffix | Example |
|----------------------------------|----------------|-----------------------------------------------------------|
Expand Down
15 changes: 6 additions & 9 deletions pkg/detector/library/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,16 @@ func (d *Driver) DetectVulnerabilities(pkgID, pkgName, pkgVer string) ([]types.D
return vulns, nil
}

// advisories resolves the advisory bucket for the package and returns the
// matching advisories together with the version comparer to use.
// advisories returns the advisories and version comparer for the package.
//
// For supplier packages (e.g. Seal Security), it prefers the supplier-specific
// bucket and comparer. When the supplier match is only a candidate (a version
// suffix that can also appear on real packages, e.g. `-spN` on Go/npm), the
// supplier bucket is used only if it actually contains advisories for the
// package; otherwise it falls back to the default ecosystem bucket.
// Suppliers choose their own advisory sources and precedence rules. When the
// supplier match is only a candidate, the supplier result is used only if it
// contains advisories; otherwise detection falls back to the default ecosystem.
func (d *Driver) advisories(normalizedName, pkgVer string) ([]dbTypes.Advisory, compare.Comparer, error) {
if v, res := lookupSupplier(d.ecosystem, normalizedName, pkgVer); res != NoMatch {
advisories, err := d.dbc.GetAdvisories(v.BucketPrefix(d.ecosystem), normalizedName)
advisories, err := v.Advisories(d.dbc, d.ecosystem, normalizedName)
if err != nil {
return nil, nil, xerrors.Errorf("failed to get %s advisories: %w", d.ecosystem, err)
return nil, nil, xerrors.Errorf("failed to get %s %s advisories: %w", v.Name(), d.ecosystem, err)
}
if res == Matched || len(advisories) > 0 {
return advisories, v.Comparer(d.ecosystem, d.comparer), nil
Expand Down
195 changes: 192 additions & 3 deletions pkg/detector/library/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ func TestDriver_Detect(t *testing.T) {
pkgName string
pkgVer string
}
upstreamTestDataSource := &dbTypes.DataSource{
ID: "echo-upstream-test",
Name: "Echo Upstream Test",
URL: "https://example.com/upstream",
}
echoTestDataSource := &dbTypes.DataSource{
ID: "echo-osv",
Name: "Echo OSV",
URL: "https://advisory.echohq.com/osv/all.zip",
}
tests := []struct {
name string
fixtures []string
Expand Down Expand Up @@ -372,7 +382,8 @@ func TestDriver_Detect(t *testing.T) {
{
// No-prefix name (no seal- prefix) detected by the "+spN" version
// suffix. Also exercises the pip AllowLocalSpecifier comparer on the
// Matched-by-suffix path.
// Matched-by-suffix path and confirms a definitive Seal match does not
// include the upstream advisory stored in the same fixture.
name: "seal security pip no-prefix package",
fixtures: []string{
"testdata/fixtures/seal.yaml",
Expand Down Expand Up @@ -669,7 +680,9 @@ func TestDriver_Detect(t *testing.T) {
want: nil,
},
{
name: "echo pip package ignores upstream advisories",
// Withdrawn Echo entries are not stored in the vulnerability DB, so
// they follow the same path as a package with no Echo advisory.
name: "echo pip package with no active Echo advisory falls back to upstream",
fixtures: []string{
"testdata/fixtures/pip.yaml",
"testdata/fixtures/echo.yaml",
Expand All @@ -680,7 +693,19 @@ func TestDriver_Detect(t *testing.T) {
pkgName: "Django",
pkgVer: "4.2.1+echo.1",
},
want: nil,
want: []types.DetectedVulnerability{
{
VulnerabilityID: "CVE-2023-36053",
PkgName: "Django",
InstalledVersion: "4.2.1+echo.1",
FixedVersion: "4.2.3",
DataSource: &dbTypes.DataSource{
ID: vulnerability.GHSA,
Name: "GitHub Security Advisory Pip",
URL: "https://github.com/advisories?query=type%3Areviewed+ecosystem%3Apip",
},
},
},
},
{
name: "echo maven package below both fixes",
Expand Down Expand Up @@ -995,6 +1020,170 @@ func TestDriver_Detect(t *testing.T) {
},
want: nil,
},
{
name: "echo pip package keeps unrelated upstream advisories",
fixtures: []string{"testdata/fixtures/echo-upstream.yaml"},
libType: ftypes.PythonPkg,
args: args{
pkgName: "echomergepip",
pkgVer: "1.2.3+echo.1",
},
want: []types.DetectedVulnerability{
{
VulnerabilityID: "CVE-2026-10102",
PkgName: "echomergepip",
InstalledVersion: "1.2.3+echo.1",
FixedVersion: "1.2.4",
DataSource: upstreamTestDataSource,
},
{
VulnerabilityID: "CVE-2026-10103",
PkgName: "echomergepip",
InstalledVersion: "1.2.3+echo.1",
DataSource: upstreamTestDataSource,
},
},
},
{
name: "echo maven package compares upstream inclusive range against base version",
fixtures: []string{"testdata/fixtures/echo-upstream.yaml"},
libType: ftypes.Jar,
args: args{
pkgName: "com.example:echo-merge",
pkgVer: "1.2.3+echo.1",
},
want: []types.DetectedVulnerability{
{
VulnerabilityID: "CVE-2026-10202",
PkgName: "com.example:echo-merge",
InstalledVersion: "1.2.3+echo.1",
FixedVersion: "1.2.4",
DataSource: upstreamTestDataSource,
},
{
VulnerabilityID: "CVE-2026-10203",
PkgName: "com.example:echo-merge",
InstalledVersion: "1.2.3+echo.1",
DataSource: upstreamTestDataSource,
},
},
},
{
name: "echo maven package reports Echo and upstream advisories together",
fixtures: []string{"testdata/fixtures/echo-upstream.yaml"},
libType: ftypes.Jar,
args: args{
pkgName: "com.example:echo-merge",
pkgVer: "1.2.2+echo.1",
},
want: []types.DetectedVulnerability{
{
VulnerabilityID: "CVE-2026-10201",
VendorIDs: []string{
"ECHO-1020-1020-1020",
},
PkgName: "com.example:echo-merge",
InstalledVersion: "1.2.2+echo.1",
FixedVersion: "1.2.3+echo.1",
DataSource: echoTestDataSource,
},
{
VulnerabilityID: "CVE-2026-10202",
PkgName: "com.example:echo-merge",
InstalledVersion: "1.2.2+echo.1",
FixedVersion: "1.2.4",
DataSource: upstreamTestDataSource,
},
{
VulnerabilityID: "CVE-2026-10203",
PkgName: "com.example:echo-merge",
InstalledVersion: "1.2.2+echo.1",
DataSource: upstreamTestDataSource,
},
},
},
{
name: "echo npm package keeps a different primary ID even when aliases overlap",
fixtures: []string{"testdata/fixtures/echo-upstream.yaml"},
libType: ftypes.NodePkg,
args: args{
pkgName: "echo-merge-npm",
pkgVer: "1.2.3+echo.1",
},
want: []types.DetectedVulnerability{
{
VulnerabilityID: "CVE-2026-10302",
PkgName: "echo-merge-npm",
InstalledVersion: "1.2.3+echo.1",
FixedVersion: "1.2.4",
DataSource: upstreamTestDataSource,
},
{
VulnerabilityID: "CVE-2026-10303",
PkgName: "echo-merge-npm",
InstalledVersion: "1.2.3+echo.1",
DataSource: upstreamTestDataSource,
},
{
VulnerabilityID: "GHSA-1111-2222-3333",
VendorIDs: []string{
"CVE-2026-10301",
},
PkgName: "echo-merge-npm",
InstalledVersion: "1.2.3+echo.1",
FixedVersion: "1.2.4",
DataSource: upstreamTestDataSource,
},
},
},
{
name: "echo nuget package keeps unrelated upstream advisories",
fixtures: []string{"testdata/fixtures/echo-upstream.yaml"},
libType: ftypes.DotNetCore,
args: args{
pkgName: "Echo.Merge.NuGet",
pkgVer: "1.2.3+echo.1",
},
want: []types.DetectedVulnerability{
{
VulnerabilityID: "CVE-2026-10402",
PkgName: "Echo.Merge.NuGet",
InstalledVersion: "1.2.3+echo.1",
FixedVersion: "1.2.4",
DataSource: upstreamTestDataSource,
},
{
VulnerabilityID: "CVE-2026-10403",
PkgName: "Echo.Merge.NuGet",
InstalledVersion: "1.2.3+echo.1",
DataSource: upstreamTestDataSource,
},
},
},
{
name: "echo go package keeps unrelated upstream advisories",
fixtures: []string{"testdata/fixtures/echo-upstream.yaml"},
libType: ftypes.GoModule,
args: args{
pkgName: "example.com/echo-merge",
pkgVer: "v1.2.3+echo.1",
},
want: []types.DetectedVulnerability{
{
VulnerabilityID: "CVE-2026-10502",
PkgName: "example.com/echo-merge",
InstalledVersion: "v1.2.3+echo.1",
FixedVersion: "v1.2.4",
DataSource: upstreamTestDataSource,
},
{
VulnerabilityID: "CVE-2026-10503",
PkgName: "example.com/echo-merge",
InstalledVersion: "v1.2.3+echo.1",
DataSource: upstreamTestDataSource,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
71 changes: 62 additions & 9 deletions pkg/detector/library/echo/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ import (
"golang.org/x/mod/semver"

"github.com/aquasecurity/go-version/pkg/version"
"github.com/aquasecurity/trivy-db/pkg/db"
"github.com/aquasecurity/trivy-db/pkg/ecosystem"
dbTypes "github.com/aquasecurity/trivy-db/pkg/types"
"github.com/aquasecurity/trivy-db/pkg/vulnsrc/vulnerability"
"github.com/aquasecurity/trivy/pkg/detector/library"
"github.com/aquasecurity/trivy/pkg/detector/library/compare"
"github.com/aquasecurity/trivy/pkg/detector/library/compare/npm"
"github.com/aquasecurity/trivy/pkg/detector/library/compare/pep440"
"github.com/aquasecurity/trivy/pkg/set"
)

var (
Expand Down Expand Up @@ -79,26 +83,75 @@ func isValidGoSemVer(ver string) bool {
return semver.IsValid(ver) || semver.IsValid("v"+ver)
}

// BucketPrefix returns the supplier-specific advisory bucket prefix.
func (e echoSupplier) BucketPrefix(eco ecosystem.Type) string {
func (e echoSupplier) bucketPrefix(eco ecosystem.Type) string {
return fmt.Sprintf("%s %s::", e.Name(), eco)
}

// Advisories combines upstream and Echo advisories, preferring Echo when the
// primary vulnerability IDs match.
func (e echoSupplier) Advisories(dbc db.Config, eco ecosystem.Type, pkgName string) ([]dbTypes.Advisory, error) {
echoAdvisories, err := dbc.GetAdvisories(e.bucketPrefix(eco), pkgName)
if err != nil {
return nil, err
}
upstreamAdvisories, err := dbc.GetAdvisories(string(eco)+"::", pkgName)
if err != nil {
return nil, fmt.Errorf("failed to get upstream advisories: %w", err)
}

echoIDs := set.New[string]()
for _, adv := range echoAdvisories {
echoIDs.Append(adv.VulnerabilityID)
}

merged := make([]dbTypes.Advisory, 0, len(upstreamAdvisories)+len(echoAdvisories))
for _, adv := range upstreamAdvisories {
if !echoIDs.Contains(adv.VulnerabilityID) {
merged = append(merged, adv)
}
}
return append(merged, echoAdvisories...), nil
}

// Comparer returns a version comparer for the given ecosystem.
// pip, npm, NuGet, and Go get comparers that keep the "+echo.N" suffix significant,
// PEP 440 local versions and SemVer build metadata are otherwise ignored;
// Maven's default comparer already orders it correctly.
// Maven's default comparer already orders Echo revisions correctly. Upstream
// advisories are evaluated with the ecosystem comparer.
func (e echoSupplier) Comparer(eco ecosystem.Type, defaultComparer compare.Comparer) compare.Comparer {
specialComparer := defaultComparer
switch eco {
case ecosystem.Pip:
return e.pipComparer
specialComparer = e.pipComparer
case ecosystem.Npm:
return e.npmComparer
specialComparer = e.npmComparer
case ecosystem.NuGet:
return e.nugetComparer
specialComparer = e.nugetComparer
case ecosystem.Go:
return e.goComparer
default:
return defaultComparer
specialComparer = e.goComparer
}
return echoComparer{
ecosystem: eco,
defaultComparer: defaultComparer,
specialComparer: specialComparer,
}
}

// echoComparer selects the comparison rules according to the advisory source.
// Echo advisories compare the complete Echo version, while upstream Maven
// advisories compare the base version because Maven orders X+echo.N above X.
type echoComparer struct {
ecosystem ecosystem.Type
defaultComparer compare.Comparer
specialComparer compare.Comparer
}

func (c echoComparer) IsVulnerable(ver string, adv dbTypes.Advisory) bool {
if adv.DataSource != nil && adv.DataSource.ID == vulnerability.EchoOSV {
return c.specialComparer.IsVulnerable(ver, adv)
}
if c.ecosystem == ecosystem.Maven {
ver, _, _ = strings.Cut(ver, "+echo.")
}
return c.defaultComparer.IsVulnerable(ver, adv)
}
Loading
Loading