Skip to content

bug: Trivy doesnt remove duplicate Packages received from SBOM + from the Analyzer interface #8993

@DmitriyLewen

Description

@DmitriyLewen

Description

By default, Trivy removes duplicates by Application type + filepath:

for _, app := range layer.Applications {
key := fmt.Sprintf("%s/type:%s", app.FilePath, app.Type)
nestedMap.SetByString(key, sep, app)
}

So for cases when two same Application have different filepath (e.g. from SBOM and from file (see #8863 (comment))) Trivy doesn't remove duplicates.

But we have one more logic:

for _, app := range result.Applications {
skippedFiles = append(skippedFiles, app.FilePath)
for _, pkg := range app.Packages {
// The analysis result could contain packages listed in SBOM.
// The files of those packages don't have to be analyzed.
// This is especially helpful for expensive post-analyzers such as the JAR analyzer.
if pkg.FilePath != "" {
skippedFiles = append(skippedFiles, pkg.FilePath)
}
}
}

This logic helps with jar files (see #8863 (reply in thread)).
But this logic works only for PostAnalyzers.

That is why it doesn't work for GoBinaries.

Discussed in #8863

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions