From 2d0d4441349c959d06f493c0d9320416ab146c87 Mon Sep 17 00:00:00 2001 From: Naman Katiyar Date: Tue, 1 Dec 2026 17:35:43 +0000 Subject: [PATCH 1/2] fix: ingest Go advisories in GitHub importers Enable the GO ecosystem in the GitHub API importer and golang in the GitHub OSV v2 importer so Go advisories are collected instead of skipped. The downstream parsing already supports golang: get_purl handles golang packages, univers provides GolangVersionRange, and the OSV v2 parser maps the Go ecosystem to golang PURLs. resolves: https://github.com/aboutcode-org/vulnerablecode/issues/1039 Signed-off-by: Naman Katiyar --- vulnerabilities/pipelines/github_importer.py | 4 ++-- vulnerabilities/pipelines/v2_importers/github_osv_importer.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vulnerabilities/pipelines/github_importer.py b/vulnerabilities/pipelines/github_importer.py index 66c457824..4469ccd1c 100644 --- a/vulnerabilities/pipelines/github_importer.py +++ b/vulnerabilities/pipelines/github_importer.py @@ -56,7 +56,7 @@ def steps(cls): "RUBYGEMS": "gem", "NPM": "npm", "RUST": "cargo", - # "GO": "golang", + "GO": "golang", } def advisories_count(self): @@ -79,7 +79,7 @@ def collect_advisories(self) -> Iterable[AdvisoryData]: # TODO: We will try to gather more info from GH API # Check https://github.com/nexB/vulnerablecode/issues/1039#issuecomment-1366458885 # Check https://github.com/nexB/vulnerablecode/issues/645 - # set of all possible values of first '%s' = {'MAVEN','COMPOSER', 'NUGET', 'RUBYGEMS', 'PYPI', 'NPM', 'RUST'} + # set of all possible values of first '%s' = {'MAVEN','COMPOSER', 'NUGET', 'RUBYGEMS', 'PYPI', 'NPM', 'RUST', 'GO'} # second '%s' is interesting, it will have the value '' for the first request, advisory_query = """ query{ diff --git a/vulnerabilities/pipelines/v2_importers/github_osv_importer.py b/vulnerabilities/pipelines/v2_importers/github_osv_importer.py index 34775fc8c..ddcc8a468 100644 --- a/vulnerabilities/pipelines/v2_importers/github_osv_importer.py +++ b/vulnerabilities/pipelines/v2_importers/github_osv_importer.py @@ -55,7 +55,7 @@ def collect_advisories(self) -> Iterable[AdvisoryDataV2]: "pypi", "npm", "maven", - # "golang", + "golang", "composer", "hex", "gem", From 9653e659fe93727245a8775bf1c103e60a72b686 Mon Sep 17 00:00:00 2001 From: Naman Katiyar Date: Tue, 1 Dec 2026 17:35:43 +0000 Subject: [PATCH 2/2] test: add coverage for Go advisories in GitHub importers Add regression tests asserting that the GitHub API importer queries the GO ecosystem and yields golang packages, and that the GitHub OSV v2 importer keeps affected packages for Go advisories. Both tests fail without the ecosystem enablement and pass with it. Signed-off-by: Naman Katiyar --- .../test_github_importer_pipeline.py | 37 ++++++++++++++++ .../test_github_osv_importer_v2.py | 44 +++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/vulnerabilities/tests/pipelines/test_github_importer_pipeline.py b/vulnerabilities/tests/pipelines/test_github_importer_pipeline.py index dfa5ea371..cc146082d 100644 --- a/vulnerabilities/tests/pipelines/test_github_importer_pipeline.py +++ b/vulnerabilities/tests/pipelines/test_github_importer_pipeline.py @@ -56,6 +56,43 @@ def test_process_response_github_importer(pkg_type, regen=REGEN): assert result == expected +def test_collect_advisories_includes_golang_ecosystem(): + with open(TEST_DATA / "golang.json") as f: + golang_response = json.load(f) + + queried_ecosystems = [] + golang_pages = [golang_response] + + def fake_fetch(graphql_query): + query = graphql_query["query"] + for ecosystem in GitHubAPIImporterPipeline.package_type_by_github_ecosystem: + if f"ecosystem: {ecosystem}" in query: + queried_ecosystems.append(ecosystem) + if ecosystem == "GO" and golang_pages: + return golang_pages.pop() + return { + "data": { + "securityVulnerabilities": { + "edges": [], + "pageInfo": {"hasNextPage": False, "endCursor": None}, + } + } + } + + with mock.patch( + "vulnerabilities.pipelines.github_importer.utils.fetch_github_graphql_query", + side_effect=fake_fetch, + ): + advisories = list(GitHubAPIImporterPipeline().collect_advisories()) + + assert "GO" in queried_ecosystems + golang_packages = [ + affected.package for advisory in advisories for affected in advisory.affected_packages + ] + assert golang_packages + assert all(package.type == "golang" for package in golang_packages) + + def test_process_response_with_empty_vulnaribilities(): logger = TestLogger() list( diff --git a/vulnerabilities/tests/pipelines/v2_importers/test_github_osv_importer_v2.py b/vulnerabilities/tests/pipelines/v2_importers/test_github_osv_importer_v2.py index ae9b6f75f..e9b8d0da0 100644 --- a/vulnerabilities/tests/pipelines/v2_importers/test_github_osv_importer_v2.py +++ b/vulnerabilities/tests/pipelines/v2_importers/test_github_osv_importer_v2.py @@ -68,3 +68,47 @@ def delete(self): assert advisory.original_advisory_text.strip().startswith("{") assert advisory.affected_packages assert advisory.affected_packages[0].package.type == "pypi" + + +@pytest.fixture +def sample_go_osv_advisory(tmp_path: Path): + advisory_data = { + "id": "GHSA-golang-test-0001", + "summary": "Sample Go summary", + "details": "Sample Go details", + "aliases": ["CVE-2021-99998"], + "affected": [ + { + "package": {"name": "github.com/moby/moby", "ecosystem": "Go"}, + "ranges": [{"type": "SEMVER", "events": [{"introduced": "0"}, {"fixed": "1.3.3"}]}], + "versions": ["1.3.2"], + } + ], + "database_specific": {"cwe_ids": ["CWE-22"]}, + } + + advisory_dir = tmp_path / "advisories/github-reviewed/sample_go_project" + advisory_dir.mkdir(parents=True) + + advisory_file = advisory_dir / "GHSA-golang-test-0001.json" + advisory_file.write_text(json.dumps(advisory_data, indent=2)) + + return tmp_path + + +def test_collect_advisories_from_github_osv_golang(sample_go_osv_advisory): + class DummyVCSResponse: + dest_dir = str(sample_go_osv_advisory) + + def delete(self): + pass + + importer = GithubOSVImporterPipeline() + importer.vcs_response = DummyVCSResponse() + + advisories = list(importer.collect_advisories()) + assert len(advisories) == 1 + + advisory = advisories[0] + assert advisory.affected_packages + assert advisory.affected_packages[0].package.type == "golang"