Add V2 Importer for Tuxcare advisories#2104
Add V2 Importer for Tuxcare advisories#2104Samk1710 wants to merge 9 commits intoaboutcode-org:mainfrom
Conversation
vulnerabilities/tests/pipelines/v2_importers/test_tuxcare_importer_v2.py
Outdated
Show resolved
Hide resolved
|
@ziadhany Thanks for your review. |
|
@Samk1710, could you please also fix the CI ? |
|
Hey @ziadhany |
|
Hey @ziadhany |
|
Hey @ziadhany I have rectified the PURL. Also added more data to test each OS type with their respective PURLs. Kindly review the changes when you have time. Thanks. |
|
Hey @ziadhany |
0f27746 to
7d47d46
Compare
ziadhany
left a comment
There was a problem hiding this comment.
The code looks good, just a few nits.
| ) | ||
| ) | ||
|
|
||
| if severity and score and not severity_added: |
There was a problem hiding this comment.
What is the use of the severity_added variable? Why aren’t severity and score enough to add severity if it exists?
There was a problem hiding this comment.
Each CVE has only one severity score shared across all packages/distributions for that CVE, so we only want to add the severity once per advisory.
See: https://cve.tuxcare.com/els/cve?cve=CVE-2023-52922&os=&project=&version=&status=&after=&before=&orderBy=updated-desc
I have added a minor refactor and used if severity and score and not severities instead of the boolean.
e4e1684 to
66be491
Compare
Thanks @ziadhany |
Signed-off-by: Sampurna Pyne <sampurnapyne1710@gmail.com>
Signed-off-by: Sampurna Pyne <sampurnapyne1710@gmail.com>
Signed-off-by: Sampurna Pyne <sampurnapyne1710@gmail.com>
Signed-off-by: Sampurna Pyne <sampurnapyne1710@gmail.com>
Signed-off-by: Sampurna Pyne <sampurnapyne1710@gmail.com>
Signed-off-by: Sampurna Pyne <sampurnapyne1710@gmail.com>
Signed-off-by: Sampurna Pyne <sampurnapyne1710@gmail.com>
Signed-off-by: Sampurna Pyne <sampurnapyne1710@gmail.com>
Signed-off-by: Sampurna Pyne <sampurnapyne1710@gmail.com>
66be491 to
9597abf
Compare
|
Hey @ziadhany. Could you kindly have a look at the changes when time. Thanks. |
| self.log(f"Skipping {cve_id} - no valid affected packages") | ||
| continue | ||
|
|
||
| yield AdvisoryData( |
There was a problem hiding this comment.
| yield AdvisoryData( | |
| yield AdvisoryDataV2( |
| type=pkg_type, namespace=namespace, name=project_name, qualifiers=qualifiers | ||
| ) | ||
|
|
||
| def collect_advisories(self) -> Iterable[AdvisoryData]: |
There was a problem hiding this comment.
| def collect_advisories(self) -> Iterable[AdvisoryData]: | |
| def collect_advisories(self) -> Iterable[AdvisoryDataV2]: |
| @classmethod | ||
| def steps(cls): | ||
| return ( | ||
| cls.fetch, |
There was a problem hiding this comment.
| cls.fetch, | |
| cls.fetch, | |
| cls.group_records_by_cve, |
| self.log(f"Fetching `{url}`") | ||
| response = fetch_response(url) | ||
| self.response = response.json() if response else [] | ||
| self._grouped = self._group_records_by_cve() |
There was a problem hiding this comment.
The fetch function should only be used for fetching. It is wrong to run any other function in it, such as group_records_by_cve.
| self._grouped = self._group_records_by_cve() |
| self.response = response.json() if response else [] | ||
| self._grouped = self._group_records_by_cve() | ||
|
|
||
| def _group_records_by_cve(self) -> dict: |
There was a problem hiding this comment.
| def _group_records_by_cve(self) -> dict: | |
| def group_records_by_cve(self): |
| return grouped | ||
|
|
||
| def advisories_count(self) -> int: | ||
| return len(self._grouped) |
There was a problem hiding this comment.
| return len(self._grouped) | |
| return len(self.grouped_cve) |
| f"(skipped {total_skipped:,d}: {skipped_invalid:,d} invalid, " | ||
| f"{skipped_non_affected:,d} non-affected)" | ||
| ) | ||
| return grouped |
There was a problem hiding this comment.
| return grouped |
| """ | ||
| A single CVE can appear in multiple records across different operating systems, distributions, or package versions. This method groups all records with the same CVE together and skips entries that are invalid or marked as not affected. The result is a dictionary keyed by CVE ID, with each value containing the related records. | ||
| """ | ||
| grouped = {} |
There was a problem hiding this comment.
| grouped = {} | |
| self.grouped_cve = {} |
There was a problem hiding this comment.
also, please use a more descriptive and meaningful name for this variable.
ex: cve_to_records
| VERSION_RANGE_BY_PURL_TYPE = { | ||
| "rpm": RANGE_CLASS_BY_SCHEMES["rpm"], | ||
| "deb": RANGE_CLASS_BY_SCHEMES["deb"], | ||
| "apk": AlpineLinuxVersionRange, | ||
| "generic": RANGE_CLASS_BY_SCHEMES["generic"], | ||
| } |
There was a problem hiding this comment.
why this ?
| VERSION_RANGE_BY_PURL_TYPE = { | |
| "rpm": RANGE_CLASS_BY_SCHEMES["rpm"], | |
| "deb": RANGE_CLASS_BY_SCHEMES["deb"], | |
| "apk": AlpineLinuxVersionRange, | |
| "generic": RANGE_CLASS_BY_SCHEMES["generic"], | |
| } | |
| from univers.version_range import RANGE_CLASS_BY_SCHEMES |
|
|
||
| return PackageURL( | ||
| type=pkg_type, namespace=namespace, name=project_name, qualifiers=qualifiers | ||
| ) |
There was a problem hiding this comment.
Please add a unit test to cover this function.
Addresses Issue:
Data Source: https://cve.tuxcare.com/els/download-json?orderBy=updated-desc
Importer Log Excerpt: