Skip to content

fix(elixir): skip entries with no usable version range - #2541

Open
sanchit955 wants to merge 2 commits into
aboutcode-org:mainfrom
sanchit955:fix/elixir-empty-version-range
Open

sanchit955 wants to merge 2 commits into
aboutcode-org:mainfrom
sanchit955:fix/elixir-empty-version-range

Conversation

@sanchit955

Copy link
Copy Markdown

Fixes #2540.

Problem

An Elixir Security advisory that lists no unaffected_versions and no patched_versions — a disclosed vulnerability with no patched version yet — produces an AffectedPackageV2 whose version range serializes as 'vers:hex/'. VersionRange.from_string rejects that string, so the importer logs Cannot create AffectedPackage with invalid or unknown range and the package is dropped on round-trip.

Evidence

Reproduced on current main with a minimal advisory YAML (valid CVE + package, no version lists): process_file yields the advisory with affected_version_range == 'vers:hex/', and the package disappears after an AdvisoryDataV2.from_dict round-trip.

Fix

Build the range only when constraints are non-empty; when there is no usable range, log and skip the package entry, mirroring the Gentoo fix in #2521 and the apache_httpd fix in #2392 for the same defect family (#2387). The advisory itself is still recorded (with an empty affected_packages list).

Tests

vulnerabilities/tests/pipelines/v2_importers/test_elixir_security_importer_v2.py: 5 passed (3 existing + 2 new).

  • test_collect_advisories_skips_empty_version_range: no version lists → advisory collected, affected_packages == [], no vers:hex/ string anywhere in the advisory dict. Fails on unmodified main.
  • test_collect_advisories_keeps_one_sided_versions: only patched_versions present → range still built, 1 affected package (guard against over-skipping).

black --check clean on both changed files.

Note for reviewers

The package is not recorded as affected for that advisory. A deeper fix in AffectedPackageV2.from_dict (tolerate a None range instead of dropping the package) is a behaviour change beyond the importer — flagging for maintainer decision, not bundling it here.

An advisory with no patched or unaffected versions listed produced a
HexVersionRange with no constraints, which serializes as 'vers:hex/'.
VersionRange.from_string rejects that string, so the affected package
was dropped on round-trip. Skip the entry instead, mirroring the
gentoo/apache_httpd fix for aboutcode-org#2387.

Signed-off-by: Sanchit <dev.sanchit955@gmail.com>

@Jean-Regis-M Jean-Regis-M left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran a YAML with no patched_versions and no unaffected_versions on main (9a9c9b3) and on this branch:

after import after to_dict / from_dict
main plug, vers:hex/ [None]
this PR no affected package no affected package

So the crash-prone None is gone, but plug is now never recorded as affected. A disclosed bug with no fix is when users most need that link.

If "no version lists" means every version is affected, could the importer keep the package with vers:hex/*? I checked that part: it survives the same round trip and contains 1.0.0. I haven't taken it through the improvers or a full import. If the meaning is unknown, skipping is fair, and I'd say so in the log message.

On Windows, test_collect_advisories fails on both branches (it expects / in the advisory ID). The other tests in that file pass, including your two.

Side note: the source repo, dependabot/elixir-security-advisories, is archived. I raised that in #2550.

An advisory with no patched or unaffected versions means no fix is
known and no version is known unaffected, so every version is affected.
Use the wildcard range instead of dropping the package.

Signed-off-by: Sanchit <dev.sanchit955@gmail.com>
@sanchit955
sanchit955 force-pushed the fix/elixir-empty-version-range branch from 94429d8 to 5b99f10 Compare November 30, 2026 16:39
@sanchit955

Copy link
Copy Markdown
Author

Good catch — you're right that skipping loses the link exactly when it matters most. I checked the advisory format: with no patched_versions and no unaffected_versions, no fix is known and no version is known unaffected, so every version is affected. I also checked the archived source data — all 12 advisories there list patched versions, so this only fires for unpatched disclosures.

Changed the importer to keep the package with vers:hex/* in that case, with a log line stating the assumption. Verified it round-trips through to_dict/from_dict with the package intact and contains 1.0.0. The improvers handle the wildcard safely — get_exact_purls skips the None version from a * constraint, and the valid-versions improver would mark all versions affected, which matches the meaning. Updated the test to assert the wildcard range and the round-trip (5 passed).

On the Windows failure: confirmed it's pre-existing — test_collect_advisories fails on both branches, unrelated to this change. And noted on #2550, thanks for raising it.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Elixir Security importer drops affected packages when an advisory lists no patched or unaffected versions

2 participants