Skip to content

fix(models): emit spec-compliant PURLs for distro ecosystems - #768

Merged
abhisek merged 3 commits into
safedep:mainfrom
Dev9269:fix/distro-ecosystem-purl
Aug 25, 2026
Merged

abhisek merged 3 commits into
safedep:mainfrom
Dev9269:fix/distro-ecosystem-purl

Conversation

@Dev9269

@Dev9269 Dev9269 commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

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] n

This 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 + distro qualifier:

  • Alpine:v3.20 -> pkg:apk/alpine/[email protected]?distro=v3.20 (matches the pkg:apk/alpine/[email protected]?arch=x86_64&distro=3.23.3 shape from the issue)
  • Ubuntu:22.04 -> pkg:deb/ubuntu/[email protected]?distro=22.04 (matches the pkg:deb/ubuntu/adduser@...&distro=jammy shape from the issue)
  • Red Hat Enterprise Linux:8 -> pkg:rpm/rhel/curl@...?distro=8 (family names are normalized so spaces/dashes don't matter)
  • Unknown families and non-distro ecosystems keep the existing rendering, so nothing else changes.

Added table tests in pkg/models/purl_test.go covering 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.

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

safedep Bot commented Aug 23, 2026 •

Copy link
Copy Markdown

SafeDep Report Summary

Green Malicious Packages Badge Green Vulnerable Packages Badge Green Risky License Badge

No dependency changes detected. Nothing to scan.

View complete scan results →

This report is generated by SafeDep GitHub App

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 a distro= 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.

Comment thread pkg/models/models.go Resolved
Comment thread pkg/models/models.go Resolved
Dev9269 and others added 2 commits August 24, 2026 23:01
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
abhisek enabled auto-merge (squash) August 25, 2026 05:15
@abhisek
abhisek merged commit c7a9e44 into safedep:main Aug 25, 2026
14 checks passed
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.

Container Scanning : Missing backed functionality for os specific vulnerability

3 participants