Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jamestexas
Copy link
Contributor

Fix: Normalize Java runtime qualifiers in Maven version comparisons

Problem

Maven/Java packages may include JRE/JDK runtime qualifiers in filenames (.jreNN, .jdkNN), but these qualifiers may not appear in the JAR's internal version metadata (from MANIFEST.MF).

When Grype compares versions:

  • Scanned package version: 12.10.2 (extracted from JAR metadata)
  • Advisory fixed version: 12.10.2.jre11 (from advisory database)
  • Result: Comparison fails as 12.10.212.10.2.jre11False positive CVE reported

The runtime qualifiers don't affect semantic versioning and should be normalized before comparison.

Solution

Strip .jre<digits> and .jdk<digits> suffixes before Maven version parsing, following the existing pattern used for other version qualifiers (RELEASE, FINAL, GA).

Behavior after fix:

  • 12.10.2 == 12.10.2.jre11
  • 12.10.2.jre11 == 12.10.2.jdk17
  • 12.10.1 < 12.10.2.jre11 ✅ (actual version differences preserved)

Testing

  • Added 7 test cases covering JRE/JDK qualifier scenarios
  • All existing version package tests pass (no regressions)
  • Test coverage includes: equal versions with different qualifiers, qualifier combinations, and real version differences across qualified versions

References

  • Upstream library: github.com/masahiro331/go-mvn-version (does not normalize runtime qualifiers)
  • Affected packages: Maven/Java libraries that use JRE/JDK qualifiers in distribution names

@jamestexas
Copy link
Contributor Author

jamestexas commented Nov 7, 2025

When researching this a bit more, I found that the suffix is non-standard for Maven parsing. It supports . as a delimiter, but treats jre11 as an unknown qualifier that sorts after known ones (alpha, beta, rc, ga, etc.), which breaks version matching.

I believe the fix is still appropriate, but let me know if I should be approaching this differently!

@wagoodman wagoodman enabled auto-merge (squash) November 14, 2025 20:40
@wagoodman wagoodman added the bug Something isn't working label Nov 14, 2025
@wagoodman wagoodman merged commit d743c07 into anchore:main Nov 14, 2025
12 checks passed
@jamestexas
Copy link
Contributor Author

Thank you for the review and help!

@willmurphyscode willmurphyscode linked an issue Nov 14, 2025 that may be closed by this pull request
spiffcs added a commit to joonas/grype that referenced this pull request Nov 20, 2025
* main:
  chore(deps): update tools to latest versions (anchore#3051)
  chore(deps): bump actions/checkout from 5.0.0 to 5.0.1 (anchore#3059)
  chore(deps): bump anchore/sbom-action from 0.20.9 to 0.20.10 (anchore#3060)
  chore(deps): bump github/codeql-action from 4.31.2 to 4.31.4 (anchore#3061)
  chore(deps): bump golang.org/x/crypto from 0.44.0 to 0.45.0 (anchore#3063)
  chore(deps): bump actions/setup-go in /.github/actions/bootstrap (anchore#3064)
  chore(deps): update anchore dependencies (anchore#3055)
  test: update quality gate db to latest version (anchore#3053)
  fix: normalize java runtime qualifiers in maven version comparisons (anchore#3034)
  chore(deps): update tools to latest versions (anchore#3045)
  fix: junit template use CDATA block to prevent XML parse errors (anchore#3019)
  feat: add basic VEX support for SBOM and other sources
  chore(deps): bump golang.org/x/tools from 0.38.0 to 0.39.0 (anchore#3046)
  chore(deps): bump github.com/opencontainers/selinux (anchore#3044)
  chore(deps): bump github.com/olekukonko/tablewriter from 1.1.0 to 1.1.1 (anchore#3039)
  keep nested loggers labeled (anchore#3040)
kbsteere added a commit to kbsteere/wolfictl that referenced this pull request Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unnormalized fix version triggers false-positive in mssql-jdbc

2 participants