Skip to content

Commit 89238a4

Browse files
committed
Test all importers for advisory ID
Signed-off-by: Tushar Goel <[email protected]>
1 parent 084aa81 commit 89238a4

36 files changed

+157
-73
lines changed

vulnerabilities/importers/apache_httpd.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ class ApacheHTTPDImporter(Importer):
3838
license_url = "https://www.apache.org/licenses/LICENSE-2.0"
3939
importer_name = "Apache HTTPD Importer"
4040

41-
def get_advisory_id(self, aliases: list[str]) -> str:
41+
@classmethod
42+
def get_advisory_id(cls, aliases: list[str]) -> str:
4243
"""
4344
Return the Advisory ID for the given aliases.
4445
"""
45-
return self.get_cve_id(aliases)
46+
return cls.get_cve_id(aliases)
4647

4748
def advisory_data(self):
4849
links = fetch_links(self.base_url)

vulnerabilities/importers/apache_kafka.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,12 @@ def fetch_advisory_page(self):
102102
page = requests.get(self.GH_PAGE_URL)
103103
return page.content
104104

105-
def get_advisory_id(self, aliases: list[str]) -> str:
105+
@classmethod
106+
def get_advisory_id(cls, aliases: list[str]) -> str:
106107
"""
107108
Return the Advisory ID for the given aliases.
108109
"""
109-
return self.get_cve_id(aliases)
110+
return cls.get_cve_id(aliases)
110111

111112
def advisory_data(self):
112113
advisory_page = self.fetch_advisory_page(self)

vulnerabilities/importers/apache_tomcat.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,12 @@ class ApacheTomcatImporter(Importer):
120120
license_url = "https://www.apache.org/licenses/LICENSE-2.0"
121121
importer_name = "Apache Tomcat Importer"
122122

123-
def get_advisory_id(self, aliases: list[str]) -> str:
123+
@classmethod
124+
def get_advisory_id(cls, aliases: list[str]) -> str:
124125
"""
125126
Return the Advisory ID for the given aliases.
126127
"""
127-
return self.get_cve_id(aliases)
128+
return cls.get_cve_id(aliases)
128129

129130
def fetch_advisory_pages(self):
130131
"""

vulnerabilities/importers/archlinux.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ class ArchlinuxImporter(Importer):
3030
license_url = "https://github.com/archlinux/arch-security-tracker/blob/master/LICENSE"
3131
importer_name = "Arch Linux Importer"
3232

33-
def get_advisory_id(self, aliases: list[str]) -> str:
33+
@classmethod
34+
def get_advisory_id(cls, aliases: list[str]) -> str:
3435
"""
3536
Return the Advisory ID for the given aliases.
3637
"""
37-
return self.get_cve_id(aliases)
38+
return cls.get_cve_id(aliases)
3839

3940
def fetch(self) -> Iterable[Mapping]:
4041
response = fetch_response(self.url)

vulnerabilities/importers/curl.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ class CurlImporter(Importer):
3939
importer_name = "Curl Importer"
4040
api_url = "https://curl.se/docs/vuln.json"
4141

42-
def get_advisory_id(self, aliases: list[str]) -> str:
42+
@classmethod
43+
def get_advisory_id(cls, aliases: list[str]) -> str:
4344
"""
4445
Return the Advisory ID for the given aliases.
4546
"""
46-
return self.get_cve_id(aliases)
47+
return cls.get_cve_id(aliases)
4748

4849
def fetch(self) -> Iterable[Mapping]:
4950
response = fetch_response(self.api_url)

vulnerabilities/importers/debian.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,12 @@ class DebianImporter(Importer):
8282
api_url = "https://security-tracker.debian.org/tracker/data/json"
8383
importer_name = "Debian Importer"
8484

85-
def get_advisory_id(self, aliases: list[str]) -> str:
85+
@classmethod
86+
def get_advisory_id(cls, aliases: list[str]) -> str:
8687
"""
8788
Return the Advisory ID for the given aliases.
8889
"""
89-
return self.get_cve_id(aliases)
90+
return cls.get_cve_id(aliases)
9091

9192
def get_response(self):
9293
response = requests.get(self.api_url)

vulnerabilities/importers/debian_oval.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ class DebianOvalImporter(OvalImporter):
5656
"""
5757
importer_name = "Debian Oval Importer"
5858

59-
def get_advisory_id(self, aliases: list[str]) -> str:
59+
@classmethod
60+
def get_advisory_id(cls, aliases: list[str]) -> str:
6061
"""
6162
Return the Advisory ID for the given aliases.
6263
"""
63-
return self.get_cve_id(aliases)
64+
return cls.get_cve_id(aliases)
6465

6566
def __init__(self, *args, **kwargs):
6667
super().__init__(*args, **kwargs)

vulnerabilities/importers/elixir_security.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ def advisory_data(self) -> Set[AdvisoryData]:
4141
if self.vcs_response:
4242
self.vcs_response.delete()
4343

44-
def get_advisory_id(self, aliases: list[str]) -> str:
44+
@classmethod
45+
def get_advisory_id(cls, aliases: list[str]) -> str:
4546
"""
4647
Return the Advisory ID for the given aliases.
4748
"""
48-
return self.get_cve_id(aliases)
49+
return cls.get_cve_id(aliases)
4950

5051
def process_file(self, file, base_path):
5152
relative_path = str(file.relative_to(base_path)).strip("/")

vulnerabilities/importers/epss.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ class EPSSImporter(Importer):
2929
spdx_license_expression = "unknown"
3030
importer_name = "EPSS Importer"
3131

32-
def get_advisory_id(self, aliases: list[str]) -> str:
32+
@classmethod
33+
def get_advisory_id(cls, aliases: list[str]) -> str:
3334
"""
3435
Return the Advisory ID for the given aliases.
3536
"""
36-
return self.get_cve_id(aliases)
37+
return cls.get_cve_id(aliases)
3738

3839
def advisory_data(self) -> Iterable[AdvisoryData]:
3940
response = urllib.request.urlopen(self.advisory_url)

vulnerabilities/importers/fireeye.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ class FireyeImporter(Importer):
3535
repo_url = "git+https://github.com/mandiant/Vulnerability-Disclosures"
3636
importer_name = "FireEye Importer"
3737

38-
def get_advisory_id(self, aliases: list[str]) -> str:
38+
@classmethod
39+
def get_advisory_id(cls, aliases: list[str]) -> str:
3940
"""
4041
Return the Advisory ID for the given aliases.
4142
"""
42-
return self.get_cve_id(aliases)
43+
return cls.get_cve_id(aliases)
4344

4445
def advisory_data(self) -> Iterable[AdvisoryData]:
4546
try:

vulnerabilities/importers/gentoo.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ class GentooImporter(Importer):
3333
license_url = "https://creativecommons.org/licenses/by-sa/4.0/"
3434
importer_name = "Gentoo Importer"
3535

36-
def get_advisory_id(self, aliases: list[str]) -> str:
36+
@classmethod
37+
def get_advisory_id(cls, aliases: list[str]) -> str:
3738
"""
3839
Return the Advisory ID for the given aliases.
3940
"""
40-
return self.get_cve_id(aliases)
41+
return cls.get_cve_id(aliases)
4142

4243
def advisory_data(self) -> Iterable[AdvisoryData]:
4344
try:

vulnerabilities/importers/github_osv.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ class GithubOSVImporter(Importer):
2525
repo_url = "git+https://github.com/github/advisory-database/"
2626
importer_name = "GithubOSV Importer"
2727

28+
@classmethod
29+
def get_advisory_id(cls, aliases: list[str]) -> str:
30+
"""
31+
Return the Advisory ID for the given aliases.
32+
"""
33+
for alias in aliases:
34+
if alias.startswith("GHSA"):
35+
return alias
36+
return cls.get_cve_id(aliases)
37+
2838
def advisory_data(self) -> Iterable[AdvisoryData]:
2939
supported_ecosystems = [
3040
"pypi",

vulnerabilities/importers/istio.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ class IstioImporter(Importer):
4444
repo_url = "git+https://github.com/istio/istio.io/"
4545
importer_name = "Istio Importer"
4646

47-
def get_advisory_id(self, aliases: list[str]) -> str:
47+
@classmethod
48+
def get_advisory_id(cls, aliases: list[str]) -> str:
4849
"""
4950
Return the Advisory ID for the given aliases.
5051
"""
51-
return self.get_cve_id(aliases)
52+
return cls.get_cve_id(aliases)
5253

5354
def advisory_data(self) -> Set[AdvisoryData]:
5455
try:

vulnerabilities/importers/mozilla.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ class MozillaImporter(Importer):
3939
repo_url = "git+https://github.com/mozilla/foundation-security-advisories/"
4040
importer_name = "Mozilla Importer"
4141

42-
def get_advisory_id(self, aliases: list[str]) -> str:
42+
@classmethod
43+
def get_advisory_id(cls, aliases: list[str]) -> str:
4344
"""
4445
Return the Advisory ID for the given aliases.
4546
"""
46-
return self.get_cve_id(aliases)
47+
return cls.get_cve_id(aliases)
4748

4849
def advisory_data(self) -> Iterable[AdvisoryData]:
4950
try:

vulnerabilities/importers/openssl.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ class OpensslImporter(Importer):
3535
url = "https://www.openssl.org/news/vulnerabilities.xml"
3636
importer_name = "OpenSSL Importer"
3737

38-
def get_advisory_id(self, aliases: list[str]) -> str:
38+
@classmethod
39+
def get_advisory_id(cls, aliases: list[str]) -> str:
3940
"""
4041
Return the Advisory ID for the given aliases.
4142
"""
4243
for alias in aliases:
4344
if alias.startswith("VC-OPENSSL-"):
4445
return alias
45-
return None
46+
return cls.get_cve_id(aliases)
4647

4748
def fetch(self):
4849
response = requests.get(url=self.url)

vulnerabilities/importers/oss_fuzz.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ class OSSFuzzImporter(Importer):
2626
url = "git+https://github.com/google/oss-fuzz-vulns"
2727
importer_name = "OSS Fuzz Importer"
2828

29-
def get_advisory_id(self, aliases: list[str]) -> str:
29+
@classmethod
30+
def get_advisory_id(cls, aliases: list[str]) -> str:
3031
"""
3132
Return the Advisory ID for the given aliases.
3233
"""
33-
return self.get_cve_id(aliases)
34+
return cls.get_cve_id(aliases)
3435

3536
def advisory_data(self) -> Iterable[AdvisoryData]:
3637
try:

vulnerabilities/importers/postgresql.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ class PostgreSQLImporter(Importer):
3030
spdx_license_expression = "PostgreSQL"
3131
importer_name = "PostgreSQL Importer"
3232

33-
def get_advisory_id(self, aliases: list[str]) -> str:
33+
@classmethod
34+
def get_advisory_id(cls, aliases: list[str]) -> str:
3435
"""
3536
Return the Advisory ID for the given aliases.
3637
"""
37-
return self.get_cve_id(aliases)
38+
return cls.get_cve_id(aliases)
3839

3940
def advisory_data(self):
4041
known_urls = {self.root_url}

vulnerabilities/importers/project_kb_msr2019.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ class ProjectKBMSRImporter(Importer):
2424
license_url = "https://github.com/SAP/project-kb/blob/main/LICENSE.txt"
2525
importer_name = "ProjectKB MSRImporter"
2626

27-
def get_advisory_id(self, aliases: list[str]) -> str:
27+
@classmethod
28+
def get_advisory_id(cls, aliases: list[str]) -> str:
2829
"""
2930
Return the Advisory ID for the given aliases.
3031
"""
31-
return self.get_cve_id(aliases)
32+
return cls.get_cve_id(aliases)
3233

3334
def advisory_data(self):
3435
raw_data = fetch_and_read_from_csv(self.url)

vulnerabilities/importers/redhat.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ class RedhatImporter(Importer):
6767
license_url = "https://access.redhat.com/documentation/en-us/red_hat_security_data_api/1.0/html/red_hat_security_data_api/legal-notice"
6868
importer_name = "RedHat Importer"
6969

70-
def get_advisory_id(self, aliases: list[str]) -> str:
70+
@classmethod
71+
def get_advisory_id(cls, aliases: list[str]) -> str:
7172
"""
7273
Return the Advisory ID for the given aliases.
7374
"""
74-
return self.get_cve_id(aliases)
75+
return cls.get_cve_id(aliases)
7576

7677
def advisory_data(self) -> Iterable[AdvisoryData]:
7778
for redhat_cves in fetch_cves():

vulnerabilities/importers/retiredotnet.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ def advisory_data(self) -> Iterable[AdvisoryData]:
4444
if self.vcs_response:
4545
self.vcs_response.delete()
4646

47-
def get_advisory_id(self, aliases: list[str]) -> str:
47+
@classmethod
48+
def get_advisory_id(cls, aliases: list[str]) -> str:
4849
"""
4950
Return the Advisory ID for the given aliases.
5051
"""
51-
return self.get_cve_id(aliases)
52+
return cls.get_cve_id(aliases)
5253

5354
@staticmethod
5455
def vuln_id_from_desc(desc):

vulnerabilities/importers/ruby.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ class RubyImporter(Importer):
5252
SOFTWARE.
5353
"""
5454

55+
@classmethod
56+
def get_advisory_id(cls, aliases: list[str]) -> str:
57+
"""
58+
Return the Advisory ID for the given aliases.
59+
"""
60+
for alias in aliases:
61+
if alias.startswith("GHSA-"):
62+
return alias
63+
return cls.get_cve_id(aliases)
64+
5565
def advisory_data(self) -> Iterable[AdvisoryData]:
5666
try:
5767
self.clone(self.repo_url)
@@ -72,12 +82,6 @@ def advisory_data(self) -> Iterable[AdvisoryData]:
7282
if self.vcs_response:
7383
self.vcs_response.delete()
7484

75-
def get_advisory_id(self, aliases: list[str]) -> str:
76-
"""
77-
Return the Advisory ID for the given aliases.
78-
"""
79-
return self.get_cve_id(aliases)
80-
8185

8286
def parse_ruby_advisory(record, schema_type, advisory_url):
8387
"""

vulnerabilities/importers/suse_oval.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ def __init__(self, *args, **kwargs):
2626
super().__init__(*args, **kwargs)
2727
self.translations = {"less than": "<", "equals": "=", "greater than or equal": ">="}
2828

29+
@classmethod
30+
def get_advisory_id(cls, aliases: list[str]) -> str:
31+
"""
32+
Return the Advisory ID for the given aliases.
33+
"""
34+
return cls.get_cve_id(aliases)
35+
2936
def _fetch(self):
3037
page = requests.get(self.base_url).text
3138
soup = BeautifulSoup(page, "lxml")

vulnerabilities/importers/suse_scores.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ class SUSESeverityScoreImporter(Importer):
2626
license_url = "https://ftp.suse.com/pub/projects/security/yaml/LICENSE"
2727
importer_name = "SUSE Severity Score Importer"
2828

29+
@classmethod
30+
def get_advisory_id(cls, aliases: list[str]) -> str:
31+
"""
32+
Return the Advisory ID for the given aliases.
33+
"""
34+
return cls.get_cve_id(aliases)
35+
2936
def advisory_data(self) -> Iterable[AdvisoryData]:
3037
score_data = fetch_yaml(URL)
3138
yield from self.to_advisory(score_data)

vulnerabilities/importers/ubuntu.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ class UbuntuImporter(OvalImporter):
6363
"""
6464
importer_name = "Ubuntu OVAL Importer"
6565

66+
@classmethod
67+
def get_advisory_id(cls, aliases: list[str]) -> str:
68+
"""
69+
Return the Advisory ID for the given aliases.
70+
"""
71+
return cls.get_cve_id(aliases)
72+
6673
def __init__(self, *args, **kwargs):
6774
super().__init__(*args, **kwargs)
6875
# we could avoid setting translations, and have it

vulnerabilities/importers/ubuntu_usn.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ class UbuntuUSNImporter(Importer):
6464
"""
6565
importer_name = "Ubuntu USN Importer"
6666

67+
@classmethod
68+
def get_advisory_id(cls, aliases: list[str]) -> str:
69+
"""
70+
Return the Advisory ID for the given aliases.
71+
"""
72+
return cls.get_cve_id(aliases)
73+
6774
def advisory_data(self):
6875
usn_db = fetch(self.db_url)
6976
yield from self.to_advisories(usn_db=usn_db)

0 commit comments

Comments
 (0)