Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions vulnerabilities/pipelines/v2_importers/mattermost_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ def collect_advisories(self) -> Iterable[AdvisoryDataV2]:
name=MM_REPO.get(platform),
)

# Newer entries hold the list as a JSON string: '["12.0","11.11.1"]'
if isinstance(fixed_versions, str) and fixed_versions.startswith("["):
try:
fixed_versions = json.loads(fixed_versions)
except json.JSONDecodeError:
self.log(
f"Invalid fix_versions '{fixed_versions}' for advisory '{advisory_id}'"
)

if isinstance(fixed_versions, list):
fixed_versions = [v for v in fixed_versions if v and v.strip()]
fixed_versions = [v.lstrip("v") for v in fixed_versions]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,13 @@ def test_parse_vuln_ids(issue_id, cve_id, expected_advisory_id, expected_aliases
advisory_id, aliases = parse_vuln_ids(issue_id, cve_id)
assert advisory_id == expected_advisory_id
assert aliases == expected_aliases


def test_collect_advisories_fix_versions_as_json_string(importer, sample_mattermost_data):
# newer entries in the feed hold the list as a JSON string
sample_mattermost_data[0]["fix_versions"] = '["12.0","11.11.1"]'

advisory = list(importer.collect_advisories())[0]

ranges = [str(package.fixed_version_range) for package in advisory.affected_packages]
assert ranges == ["vers:github/11.11.1|12.0.0"]