fix: update mixed case dependencies in python to be normalized#4573
fix: update mixed case dependencies in python to be normalized#4573
Conversation
Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
| name: "package name with mixed case and extra", | ||
| pkg: "Django", | ||
| extra: "argon2", | ||
| want: "django[argon2]", |
There was a problem hiding this comment.
How do the extras interact with the resolution in requires/provides?
There was a problem hiding this comment.
So here is the current behavior:
When a package requires another with extras:
- provides is always the base package no extras in the name
- then we always have the base package requirements without any extras so those resolutions can always happen
- If there are extras, the extra variants also get added (now run through the normalize logic)
1
syft/syft/pkg/cataloger/python/dependency.go
Lines 24 to 27 in e8b4527
2
syft/syft/pkg/cataloger/python/dependency.go
Lines 34 to 37 in e8b4527
3
syft/syft/pkg/cataloger/python/dependency.go
Lines 38 to 47 in e8b4527
This change does not update any of the above flow. It just makes sure that we are respecting the casing correctly in both instances of creating the provides:requires and the extras variant.
There was a problem hiding this comment.
We reviewed this offline, and I think the behavior currently in main is correct. Provides and requires are include both a plain and a with extras variant as appropriate, like mashumaro and mashumaro[orjson], and this is unit tested.
There was a problem hiding this comment.
No more changes needed for this PR then and we are 🟢 ❤️
* main: (114 commits) fix: lookup alternate scheme on url->licenseID (anchore#4588) chore(deps): bump the go-minor-patch group with 2 updates (anchore#4583) feat: add Qt6 binary detection (anchore#4550) chore(deps): bump the actions-minor-patch group across 1 directory with 2 updates (anchore#4584) fix: snap cataloger incorrectly identifies snap container as deb package (anchore#4500) chore(deps): update tools to latest versions (anchore#4577) fix: update mixed case dependencies in python to be normalized (anchore#4573) chore(deps): update anchore dependencies (anchore#4575) chore(deps): update tools to latest versions (anchore#4570) feat: detect Debian version from /etc/debian_version (anchore#4569) fix: correctly report supporting evidence for binary packages (anchore#4558) chore(deps): bump the actions-minor-patch group across 2 directories with 3 updates (anchore#4568) chore(deps): bump the go-minor-patch group with 6 updates (anchore#4567) chore(deps): update tools to latest versions (anchore#4565) chore(deps): bump github.com/spdx/tools-golang (anchore#4557) ci: enable zizmor to fail PRs (anchore#4556) Chore new slack action (anchore#4553) chore(deps): update anchore dependencies (anchore#4552) chore(deps): update tools to latest versions (anchore#4551) chore(deps): update tools to latest versions (anchore#4545) ... Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
Description
When generating a CycloneDX SBOM from a Python project that uses poetry.lock, Syft was failing to resolve dependency edges when the dependency name used different casing than the package name.
For example, in a poetry.lock file, dj-rest-auth declares a dependency on Django (capitalized), but the actual package is listed as django (lowercase).
Per the https://packaging.python.org/en/latest/specifications/name-normalization/, package names should be treated as case-insensitive.
Root Cause
The packageRef function in the poetry dependency resolver was not normalizing package names before using them for dependency matching.
Fix
Fix: Apply the existing normalize() function to package names and extras in packageRef(), ensuring case-insensitive matching that complies with Python packaging standards.
Before: The dependency edge dj-rest-auth@7.0.1 → django@5.2.6 was missing from the SBOM dependency graph.
After: Dependency edges are correctly resolved regardless of package name casing in poetry.lock.
Some other tests have been updated that were missing this relationship previously
Type of Change
Issue references
Fixes #4562