Repository navigation
fix(models): emit spec-compliant PURLs for distro ecosystems - #768
Merged
Merged
Conversation
Container scanning sets package ecosystems like Alpine:v3.20 from osv-scalibr. GetPackageUrl() rendered them as pkg:alpine:v3.20/[email protected] which is an invalid PURL (the type segment cannot contain a colon). Render OS packages with their package manager type, namespace and a distro qualifier instead, e.g. pkg:apk/alpine/[email protected]?distro=v3.20 Fixes safedep#500
SafeDep Report SummaryNo dependency changes detected. Nothing to scan. This report is generated by SafeDep GitHub App |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Package.GetPackageUrl() to emit PURL-spec-compliant package URLs for OS distro ecosystems coming from container scanning (e.g. Alpine:v3.20), avoiding invalid PURL types that include : and ensuring downstream consumers (CycloneDX, SQLite reporter) receive valid, distro-scoped identifiers.
Changes:
- Add a mapping for known OSV distro ecosystem families to PURL
type+namespace, and render them using adistro=qualifier. - Keep legacy rendering for non-distro ecosystems and unknown distro families.
- Add table-driven tests covering Alpine/Ubuntu/RHEL/unknown/npm cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/models/models.go | Adds distro ecosystem → PURL mapping and updates GetPackageUrl() to emit spec-compliant distro PURLs for known families. |
| pkg/models/purl_test.go | Adds table tests validating the new distro PURL rendering and legacy behavior for non-distro/unknown ecosystems. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Review feedback: reuse a single TrimSpace for the distro qualifier so leading/trailing spaces cannot reach the distro= param, and note in the GetPackageUrl doc comment that unknown ecosystems keep legacy rendering.
abhisek
approved these changes
Aug 25, 2026
abhisek
enabled auto-merge (squash)
August 25, 2026 05:15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #500
Problem
Container scanning derives package ecosystems from osv-scalibr in OSV form, e.g. Alpine:v3.20, Debian:12. Package.GetPackageUrl() rendered these with the raw ecosystem string as the PURL type:
pkg:alpine:v3.20/[email protected] nThis is an invalid PURL: the type segment cannot contain a colon, and there is no such purl type as
alpine:v3.20. These broken PURLs propagate into CycloneDX SBOMs and the SQLite reporter for every OS package found in a container image.Fix
Render distro ecosystems per the PURL spec for OS packages - package manager type + namespace +
distroqualifier:Alpine:v3.20->pkg:apk/alpine/[email protected]?distro=v3.20(matches thepkg:apk/alpine/[email protected]?arch=x86_64&distro=3.23.3shape from the issue)Ubuntu:22.04->pkg:deb/ubuntu/[email protected]?distro=22.04(matches thepkg:deb/ubuntu/adduser@...&distro=jammyshape from the issue)Red Hat Enterprise Linux:8->pkg:rpm/rhel/curl@...?distro=8(family names are normalized so spaces/dashes don't matter)Added table tests in
pkg/models/purl_test.gocovering alpine/ubuntu/RHEL/unknown/npm cases.Notes on #500
The full ask in #500 (backend enrichment for OS-specific advisories) is server-side; this PR fixes the client-side PURL contract discussed in the issue so downstream consumers (CycloneDX, SQLite) receive valid, distro-scoped PURLs.