Skip to content

Commit 85f1e1d

Browse files
author
Chai Tadmor
committed
1. Added database_specific.anchore.record_type = "advisory" in parser.py _normalize()
2. Added comprehensive tests to verify the metadata is set correctly 3. Updated all 5 snapshot fixtures with the new metadata Signed-off-by: Chai Tadmor <[email protected]>
1 parent 65c9905 commit 85f1e1d

File tree

7 files changed

+68
-1
lines changed

7 files changed

+68
-1
lines changed

src/vunnel/providers/rootio/parser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ def _normalize(self, vuln_entry: dict[str, Any]) -> tuple[str, str, dict[str, An
104104
package["ecosystem"] = ecosystem[5:] # Strip "Root:" prefix
105105
self.logger.debug(f"normalized ecosystem: {ecosystem} -> {package['ecosystem']}")
106106

107+
# Set database_specific metadata to mark as advisory for grype-db
108+
# This is critical for grype-db to emit unaffectedPackageHandles for the NAK pattern
109+
if "database_specific" not in vuln_entry:
110+
vuln_entry["database_specific"] = {}
111+
if "anchore" not in vuln_entry["database_specific"]:
112+
vuln_entry["database_specific"]["anchore"] = {}
113+
vuln_entry["database_specific"]["anchore"]["record_type"] = "advisory"
114+
107115
return vuln_id, vuln_schema, vuln_entry
108116

109117
def get(self) -> Generator[tuple[str, str, dict[str, Any]]]:

tests/unit/providers/rootio/test-fixtures/snapshots/root-app-npm-cve-2022-25883.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
"GHSA-c2qf-rxjj-qqgw"
2828
],
2929
"database_specific": {
30+
"anchore": {
31+
"record_type": "advisory"
32+
},
3033
"source": "Root"
3134
},
3235
"details": "Versions of the package semver before 7.5.2 are vulnerable to Regular Expression Denial of Service (ReDoS) via the function new Range, when untrusted user data is provided as a range.",

tests/unit/providers/rootio/test-fixtures/snapshots/root-app-pypi-cve-2025-30473.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
"CVE-2025-30473",
3131
"GHSA-9wx4-h78v-vm56"
3232
],
33+
"database_specific": {
34+
"anchore": {
35+
"record_type": "advisory"
36+
}
37+
},
3338
"details": "The requests library is vulnerable to HTTP Header Injection via CRLF sequences.",
3439
"id": "ROOT-APP-PYPI-CVE-2025-30473",
3540
"modified": "2025-03-15T00:00:00Z",

tests/unit/providers/rootio/test-fixtures/snapshots/root-os-alpine-318-cve-2000-0548.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
"aliases": [
3030
"CVE-2000-0548"
3131
],
32+
"database_specific": {
33+
"anchore": {
34+
"record_type": "advisory"
35+
}
36+
},
3237
"details": "Buffer overflow in util-linux allows local users to gain privileges.",
3338
"id": "ROOT-OS-ALPINE-318-CVE-2000-0548",
3439
"modified": "2024-01-15T00:00:00Z",

tests/unit/providers/rootio/test-fixtures/snapshots/root-os-debian-bookworm-cve-2025-53014.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
"aliases": [
3030
"CVE-2025-53014"
3131
],
32+
"database_specific": {
33+
"anchore": {
34+
"record_type": "advisory"
35+
}
36+
},
3237
"details": "ImageMagick has a security vulnerability that allows remote code execution.",
3338
"id": "ROOT-OS-DEBIAN-bookworm-CVE-2025-53014",
3439
"modified": "2025-01-20T00:00:00Z",

tests/unit/providers/rootio/test-fixtures/snapshots/root-os-ubuntu-2004-cve-2024-12345.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
"aliases": [
3030
"CVE-2024-12345"
3131
],
32+
"database_specific": {
33+
"anchore": {
34+
"record_type": "advisory"
35+
}
36+
},
3237
"details": "OpenSSL has a security vulnerability in Ubuntu 20.04.",
3338
"id": "ROOT-OS-UBUNTU-2004-CVE-2024-12345",
3439
"modified": "2024-11-15T00:00:00Z",

tests/unit/providers/rootio/test_rootio.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def mock_http_get(url, logger, **kwargs):
8282

8383

8484
def test_parser_normalize_with_root_prefix(helpers, auto_fake_fixdate_finder, disable_get_requests, mocker):
85-
"""Test that parser strips 'Root:' prefix from ecosystem field."""
85+
"""Test that parser strips 'Root:' prefix from ecosystem field and sets advisory metadata."""
8686
workspace = helpers.provider_workspace_helper(name=Provider.name())
8787

8888
# Create a mock OSV record with "Root:" prefix (as returned by actual API)
@@ -110,6 +110,42 @@ def test_parser_normalize_with_root_prefix(helpers, auto_fake_fixdate_finder, di
110110
assert schema_version == "1.6.0"
111111
assert normalized_record["affected"][0]["package"]["ecosystem"] == "Alpine:3.18" # Should be stripped
112112

113+
# Verify database_specific metadata is set for advisory type
114+
# This is critical for grype-db to emit unaffectedPackageHandles for NAK pattern
115+
assert "database_specific" in normalized_record
116+
assert "anchore" in normalized_record["database_specific"]
117+
assert normalized_record["database_specific"]["anchore"]["record_type"] == "advisory"
118+
119+
120+
def test_parser_normalize_with_unaffected_records(helpers, auto_fake_fixdate_finder, disable_get_requests, mocker):
121+
"""Test that parser adds database_specific.anchore.record_type = advisory for unaffected packages."""
122+
workspace = helpers.provider_workspace_helper(name=Provider.name())
123+
124+
# Create a mock OSV record WITHOUT database_specific field
125+
mock_record = {
126+
"schema_version": "1.6.0",
127+
"id": "ROOT-OS-DEBIAN-bookworm-CVE-2025-53014",
128+
"modified": "2025-01-10T10:00:00Z",
129+
"published": "2025-01-05T08:00:00Z",
130+
"affected": [
131+
{
132+
"package": {
133+
"ecosystem": "Debian:bookworm",
134+
"name": "rootio-openssl"
135+
}
136+
}
137+
]
138+
# No database_specific field initially
139+
}
140+
141+
parser = Parser(ws=workspace, logger=None)
142+
vuln_id, schema_version, normalized_record = parser._normalize(mock_record)
143+
144+
# Verify database_specific metadata is added
145+
assert "database_specific" in normalized_record
146+
assert "anchore" in normalized_record["database_specific"]
147+
assert normalized_record["database_specific"]["anchore"]["record_type"] == "advisory"
148+
113149

114150
@pytest.mark.parametrize(
115151
"schema_version,expected",

0 commit comments

Comments
 (0)