Skip to content

bug(license): license listed in a category in trivy.yaml keeps its built-in category #11736

Backlog

Description

@nikpivkin

Reported in #11275.

When trivy.yaml lists a license in a category, Trivy adds the license to that category but keeps it in its built-in category too. Trivy then picks one of the two categories at random for each package. The same scan shows a different classification and severity from run to run.

LicenseFlagGroup.ToOptions in pkg/flag/license_flags.go puts all six categories in one map, and categories that are not set in the config keep their built-in lists. licenseToCategory and ScanTextLicense in pkg/licensing/scanner.go iterate over this map and return the first match. Go iterates over a map in random order.

Steps to reproduce with Trivy 0.74.0

mkdir lic-probe && cd lic-probe
cat > package-lock.json <<'EOF'
{
  "name": "lic-probe",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "packages": {
    "": {"name": "lic-probe", "version": "1.0.0", "dependencies": {"a": "1.0.0", "b": "1.0.0", "c": "1.0.0", "d": "1.0.0", "e": "1.0.0"}},
    "node_modules/a": {"version": "1.0.0", "license": "MIT"},
    "node_modules/b": {"version": "1.0.0", "license": "MIT"},
    "node_modules/c": {"version": "1.0.0", "license": "MIT"},
    "node_modules/d": {"version": "1.0.0", "license": "MIT"},
    "node_modules/e": {"version": "1.0.0", "license": "MIT"}
  }
}
EOF
cat > trivy.yaml <<'EOF'
license:
  forbidden:
    - MIT
EOF
for i in 1 2 3 4 5; do
  trivy fs -q --scanners license -f json . | jq -c '[.Results[]?.Licenses[]?.Category] | group_by(.) | map({(.[0]): length}) | add'
done

Output

{"forbidden":2,"notice":3}
{"forbidden":2,"notice":3}
{"forbidden":4,"notice":1}
{"forbidden":2,"notice":3}
{"forbidden":3,"notice":2}

MIT is in the built-in notice list. All five packages should be forbidden on every run.

Expected behavior

A license listed in a category in the config belongs only to that category. This must work in both directions. For example, license.permissive: [GPL-3.0] must make GPL-3.0 permissive.

Proposed fix

See #11276 (comment). Compare names case-insensitively, as the scanner does. If the config lists the same license in more than one category, the result is still random, so this case needs a rule too.

Activity

  1. added
    kind/bug
    scan/license
    on Nov 25, 2026
  2. Vchekryzhov commented on Nov 25, 2026

    @Vchekryzhov

    I’m working on the config-parsing fix discussed in #11276. I’ll include tests for moving a license in both directions and propose reporting a configuration error if two explicitly configured categories claim the same license.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugscan/license

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions