Skip to content

feat(linter): add opam package registry checks - #652

Open
bn-d wants to merge 3 commits into
ossf:mainfrom
bn-d:linter-opam
Open

bn-d wants to merge 3 commits into
ossf:mainfrom
bn-d:linter-opam

Conversation

@bn-d

@bn-d bn-d commented Nov 3, 2026

Copy link
Copy Markdown

Implements PKG:001 (package-exists) and PKG:002 (package-versions-exist) for the opam ecosystem. Currently both checks pass every opam record without a lookup, since opam is a known ecosystem with no registry checker.

Approach

Packages and versions removed from opam-repository are moved to opam-repository-archive, so both repositories need to be consulted. This matches osv.dev's own opam ecosystem, which enumerates versions from both repositories.

  • Package existence: HEAD https://opam.ocaml.org/packages/<pkg>/, falling back to the GitHub contents API for opam-repository-archive/packages/<pkg>. The API fallback is only hit for archived or non-existent packages, which keeps usage of the unauthenticated API rate limit low.
  • Version existence: HEAD of packages/<pkg>/<pkg>.<version>/opam on raw.githubusercontent.com in opam-repository, then opam-repository-archive. This avoids the API rate limit entirely. osv-scalibr has no opam version parser, so versions are matched exactly, which is also how versions are named in the repository.

Testing

  • Added Test_existsInOpam and Test_versionsExistInOpam, covering current, archived, and non-existent packages and versions.
  • go test ./..., gofmt -s, go vet ./... and go mod tidy -diff pass.
  • Ran osv record lint (ALL collection) over all 35 published OCaml advisories (OSEC-*) covering 619 package versions. 380 of those versions only exist in opam-repository-archive. The run took about 15s with --parallel 8 and flagged 5 genuinely non-existent versions, e.g. ocaml 5 and 4.04 (rather than 5.0.0 / 4.04.0), with no false positives.

bn-d added 3 commits November 3, 2026 07:32
Implement PKG:001 (package-exists) and PKG:002 (package-versions-exist)
for the opam ecosystem.

Packages and versions removed from opam-repository are moved to
opam-repository-archive, so both repositories are consulted:

- Package existence is checked against opam.ocaml.org, falling back to
  opam-repository-archive via the GitHub contents API.
- Version existence is checked by looking up the
  packages/<pkg>/<pkg>.<version>/opam file in opam-repository and then
  opam-repository-archive. osv-scalibr has no opam version parser, so
  versions are matched exactly.

Signed-off-by: Boning <me@boni.ng>
- Check versions against opam.ocaml.org/packages/<pkg>/<pkg>.<version>/
  like the package check, only falling back to opam-repository-archive
  for archived versions.
- Report missing versions with MissingVersionsError. Since opam has no
  API listing all versions of a package, Known is left nil and omitted
  from the message.
- Inline the opam-repository-archive URLs and drop opam.go and the path
  escaping, which no other ecosystem does.

Signed-off-by: Boning <me@boni.ng>
The linter only uses the message of the error, so report missing opam
versions with a plain error, like goVersionsExist does, rather than
changing MissingVersionsError for all ecosystems.

Signed-off-by: Boning <me@boni.ng>
@bn-d
bn-d marked this pull request as ready for review November 3, 2026 20:04
@bn-d

bn-d commented Nov 3, 2026

Copy link
Copy Markdown
Author

@hannesm could you take a look at this PR? Thanks

bn-d added a commit to bn-d/security-advisories that referenced this pull request Nov 3, 2026
Build osv-linter from bn-d/osv-schema#linter-opam (ossf/osv-schema#652) and lint all advisories with the ALL collection, which includes the PKG:001/PKG:002 package checks.

Signed-off-by: Boning <me@boni.ng>
bn-d added a commit to bn-d/security-advisories that referenced this pull request Nov 4, 2026
Build osv-linter from bn-d/osv-schema#linter-opam (ossf/osv-schema#652) and lint all advisories with the ALL collection, which includes the PKG:001/PKG:002 package checks.

Signed-off-by: Boning <me@boni.ng>
bn-d added a commit to bn-d/security-advisories that referenced this pull request Nov 4, 2026
Build osv-linter from bn-d/osv-schema#linter-opam (ossf/osv-schema#652) and lint all advisories with the ALL collection, which includes the PKG:001/PKG:002 package checks.

Signed-off-by: Boning <me@boni.ng>
bn-d added a commit to bn-d/security-advisories that referenced this pull request Nov 4, 2026
Build osv-linter from bn-d/osv-schema#linter-opam (ossf/osv-schema#652) and lint all advisories with the ALL collection, which includes the PKG:001/PKG:002 package checks.

Signed-off-by: Boning <me@boni.ng>
@hannesm

hannesm commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

I'm not very familiar with go, but this looks good. I remember in osv.dev initially I developed the python module for the opam ecosystem which used the GitHub API (google/osv.dev#4582), but due to rate limits this was discarded (google/osv.dev#4756). I guess for the linter it is fine to use the GitHub API.

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.

2 participants