Skip to content

bug(composer): versions are compared with SemVer-like rules instead of Composer's version order #11630

Open

Description

@DmitriyLewen

Description

Trivy compares Composer versions with compare.GenericComparer (pkg/detector/library/driver.go), which uses github.com/aquasecurity/go-version/pkg/version.
Composer orders versions differently, so Trivy misses vulnerabilities and reports patched versions as vulnerable.

The largest effect is on patch releases.
Composer orders 2.4.6-p1 after 2.4.6, while pkg/version reads -p1 as a pre-release that comes before 2.4.6.
Adobe ships Magento security fixes as patch releases (2.4.6-p6, 2.4.7-p1), and the advisories are written in terms of them.
For CVE-2024-34102 (CosmicSting, critical), magento/product-community-edition 2.4.7 is not reported, and the patched 2.4.4-p9 is.

315 Composer advisories in the DB have a patch release as a bound, most of them for magento/community-edition and magento/product-community-edition.

Reported in #11626.

Reproduction Steps

mkdir repro && cd repro
cat > composer.lock <<'EOF'
{
    "packages": [
        {
            "name": "magento/product-community-edition",
            "version": "2.4.7"
        }
    ],
    "packages-dev": []
}
EOF
trivy fs --scanners vuln .

Expected: CVE-2024-34102.
Actual: no vulnerabilities.
With "version": "2.4.4-p9", which has the fix, CVE-2024-34102 is reported.

Root cause

Composer normalizes a version with VersionParser::normalize from composer/semver and orders normalized versions with PHP's version_compare.
pkg/version follows SemVer-like rules, and they differ from Composer's in the order of suffixes, in which versions are accepted and in how suffixes are compared.

Rules

Aspect Composer (composer/semver 3.6.0) go-version/pkg/version
Numeric segments 1 to 4, padded to 4 (2.4.6 → 2.4.6.0); 5 or more is an error, except date-like versions (2010.01.02.03.04, 20160828), which are kept as is any number, missing ones compared as zero
v prefix v and V v only
Separator before the suffix -, _, . or none (2.10.RC1, v7.0.0_rc1, 6.0.0.alpha.1) -, or none if the suffix starts with a letter
Accepted suffixes dev, alpha/a, beta/b, RC, stable, patch/pl/p, each with optional numbers; anything else is an error any dot-separated identifiers, as in SemVer
Suffix aliases a = alpha, b = beta, p = pl = patch, rc = RC, stable = no suffix none, every identifier is a distinct string
Case insensitive (rc1 = RC1) sensitive (rc1 > RC1)
Order of suffixes dev < alpha < beta < RC < release < patch every suffix is a pre-release and comes before the release; suffixes are compared as strings
Patch releases (-p1) after the release before the release
Number in a suffix compared by value (beta2 < beta10) part of the string (beta10 < beta2), unless separated by a dot (alpha.2 < alpha.10)
alpha1 vs alpha.1 the same version different versions
Build metadata +... dropped ignored when comparing
x as a suffix error wildcard (x or X, in any identifier) that equals any suffix and the release itself

The table covers the version order only.
Composer's constraints add one more rule on top of it: in >=X and <X, a bound without a suffix is read as X-dev, so pre-releases of X match >=X and do not match <X.

Same pairs compared by both

Composer: VersionParser::normalize + version_compare from composer/semver 3.6.0 on PHP 8.5.
pkg/version: version.Parse + Version.Compare at the commit pinned in Trivy's go.mod.
error means the version is rejected.
The last column shows a version of the same shape published on Packagist or used as a bound in an advisory, — if none was found.

A B Composer pkg/version Real-world example
2.4.6-p1 2.4.6 > < magento/community-edition 2.4.6-p1
2.4.6-pl1 2.4.6 > < phpbb/phpbb 3.1.7-pl1
2.4.6p1 2.4.6 > < laminas/laminas-diactoros 2.2.1p2
2.4.6-patch1 2.4.6-p1 = > sylius/grid-bundle 1.4.0-patch1
2.4.6-p10 2.4.6-p8 > < magento/community-edition 2.4.7-p10
2.0.0-RC1 2.0.0-beta1 > < cakephp/cakephp 3.1.0-RC1
2.0.0-rc1 2.0.0-RC1 = > composer/composer: tag 2.3.0-RC1, advisory bound 2.3.0-rc1
2.0.0-beta10 2.0.0-beta2 > < drupal/core 8.0.0-beta16
2.0.0-alpha1 2.0.0-a1 = > phpbb/phpbb 4.0.0-a2
2.0.0-dev 2.0.0-alpha1 < > advisory bound 2.2-dev for symfony/symfony
1.0.0-alpha.1 1.0.0-alpha1 = < guzzlehttp/guzzle: tag 4.0.0-rc.2, advisory bound 4.0.0-rc2
1.0.0-stable 1.0.0 = < advisory bound 2.5.0-stable for doctrine/common
V0.7.5 0.7.5 = error ssddanbrown/bookstack V0.7.5
2.10.RC1 2.10.0 < error contao/core 2.10.RC1
v7.0.0_rc1 7.0.0 < error funadmin/funadmin v7.0.0_rc1
6.0.0.alpha.1 6.0.0 < error advisory bound 6.0.0.alpha.1 for statamic/cms
1.0.0.0.0 1.0.0 error = —
1.0.0-x 1.0.0 error = —
6.0.0-GM 6.0.0 error < advisory bound 6.0.0-GM for snipe/snipe-it
1.0.0-foo 1.0.0 error < —
1.0.0-0.3.7 1.0.0 error < —
2.4.6-p1 2.4.7-beta1 < <
2.0.0-b1 2.0.0-alpha1 > >
2.0.0-RC 2.0.0-RC1 < <
1.0.0-alpha.2 1.0.0-alpha.10 < <
1.0 1.0.0 = =
1.0.0.0 1.0.0 = =
1.2.3.4 1.2.3 > > yiisoft/yii2 2.0.49.4
v1.0.0 1.0.0 = =
1.0.0+build1 1.0.0 = = appwrite/server-ce 1.4.11+4
20100102 1.0.0 > > librenms/librenms 20160828

2.0.0-b1 > 2.0.0-alpha1 agrees only by chance: pkg/version compares the strings b1 and alpha1.

Impact on real advisories

Trivy 0.76.2, one composer.lock per version.
"Composer" is the answer of normalize + version_compare for the same advisory ranges.

Package Version Advisory Trivy Composer
magento/product-community-edition 2.4.7, 2.4.6, 2.4.6-p5 CVE-2024-34102 not reported vulnerable
magento/product-community-edition 2.4.4-p9 CVE-2024-34102 reported patched
statamic/cms v5.0.0, v6.0.0, v6.7.1 CVE-2026-33885 not reported vulnerable
composer/composer 2.3.0-RC1 CVE-2024-24821 (>=2.3.0-rc1) not reported vulnerable
cakephp/cakephp 3.2.0-RC1 CVE-2016-4793 not reported vulnerable
phpbb/phpbb 3.1.7 CVE-2019-16993 (<3.1.7-PL1) not reported vulnerable
amphp/http-client v4.0.0-rc9 CVE-2024-2653 (>=4.0.0-rc10) reported not affected
guzzlehttp/guzzle 4.0.0-rc.2 CVE-2016-5385 (>=4.0.0-rc2) not reported vulnerable
contao/core 2.10.RC1 4 advisories not reported (version rejected) vulnerable
ssddanbrown/bookstack V0.7.5 9 advisories not reported (version rejected) vulnerable

For statamic/cms, the advisory has the ranges <5.73.16 and >=6.0.0.alpha.1, <6.7.2.
The bound 6.0.0.alpha.1 is rejected, and the whole advisory is dropped, including <5.73.16.

Proposed solution

Create a new library aquasecurity/go-composer-version, like go-npm-version, go-pep440-version and go-gem-version, and implement Composer's version logic there:

  • parsing and normalization following VersionParser::normalize;
  • ordering following version_compare;
  • version constraints.

Trivy then gets a thin pkg/detector/library/compare/composer comparer on top of it, as for npm and PEP 440.

Related

Activity

  1. added
    kind/bug
    on Nov 12, 2026
  2. changed the title [-]Composer: versions are compared with SemVer-like rules instead of Composer's version order[/-] [+]bug(composer): versions are compared with SemVer-like rules instead of Composer's version order[/+] on Nov 12, 2026
  3. added theissue type on Nov 12, 2026
  4. added
    scan/vulnerability
    on Nov 12, 2026
  5. Mampiz commented on Nov 19, 2026

    @Mampiz

    Hey, I'd like to help with this one if it's open to contributors. The other ecosystems use their own comparer libraries (go-npm-version, go-pep440-version, go-gem-version) wrapped in pkg/detector/library/compare. Would you want a new go-composer-version lib following the rules in your table, or a comparer inside Trivy for now? Happy to start with the patch-release ordering and the alias/separator rules plus tests from composer/semver's own test cases.

  6. DmitriyLewen commented on Nov 20, 2026

    @DmitriyLewen
    ContributorAuthor

    Hello @Mampiz,
    I think a new go-composer-version package would be a better approach.
    I will let you know once we create the repository.

  7. DmitriyLewen commented on Nov 20, 2026

    @DmitriyLewen
    ContributorAuthor

    Hello @Mampiz
    We have created https://github.com/aquasecurity/go-composer-version.

    If you are still interested in working on this task, please let me know and I will assign the issue to you.
    During implementation, please refer to related repositories (such as go-npm-version) so that the code style and package structure stay consistent. Also, for testing, please take test cases directly from Composer to clearly demonstrate that we cover all their test scenarios.

  8. Mampiz commented on Nov 24, 2026

    @Mampiz

    Hey @DmitriyLewen, thanks for creating the repo. Yes, I'm still interested, please assign it to me. I'll follow the structure of go-npm-version and port the test cases from Composer's own test suite.

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/vulnerability

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions