|
33 | 33 | from vulnerabilities.data_source import GitDataSource |
34 | 34 | from vulnerabilities.data_source import Reference |
35 | 35 | from vulnerabilities.helpers import nearest_patched_package |
| 36 | +from vulnerabilities.helpers import split_markdown_front_matter |
36 | 37 | from vulnerabilities.package_managers import GitHubTagsAPI |
37 | 38 |
|
38 | 39 | is_release = re.compile(r"^[\d.]+$", re.IGNORECASE).match |
@@ -80,45 +81,6 @@ def get_pkg_versions_from_ranges(self, version_range_list): |
80 | 81 | safe_pkg_versions = set(all_version) - set(vuln_pkg_versions) |
81 | 82 | return safe_pkg_versions, vuln_pkg_versions |
82 | 83 |
|
83 | | - def get_data_from_yaml_lines(self, yaml_lines): |
84 | | - """Return a mapping of data from a iterable of yaml_lines |
85 | | - for example : |
86 | | - ['title: ISTIO-SECURITY-2019-001', |
87 | | - 'description: Incorrect access control.','cves: [CVE-2019-12243]'] |
88 | | -
|
89 | | - would give {'title':'ISTIO-SECURITY-2019-001', |
90 | | - 'description': 'Incorrect access control.', |
91 | | - 'cves': '[CVE-2019-12243]'} |
92 | | - """ |
93 | | - |
94 | | - return saneyaml.load("\n".join(yaml_lines)) |
95 | | - |
96 | | - def get_yaml_lines(self, lines): |
97 | | - """The istio advisory file contains lines similar to yaml format . |
98 | | - This function extracts those lines and return an iterable of lines |
99 | | -
|
100 | | - for example : |
101 | | - lines = |
102 | | - --- |
103 | | - title: ISTIO-SECURITY-2019-001 |
104 | | - description: Incorrect access control. |
105 | | - cves: [CVE-2019-12243] |
106 | | - --- |
107 | | -
|
108 | | - get_yaml_lines(lines) would return |
109 | | - ['title: ISTIO-SECURITY-2019-001','description: Incorrect access control.' |
110 | | - ,'cves: [CVE-2019-12243]'] |
111 | | - """ |
112 | | - |
113 | | - for index, line in enumerate(lines): |
114 | | - line = line.strip() |
115 | | - if line.startswith("---") and index == 0: |
116 | | - continue |
117 | | - elif line.endswith("---"): |
118 | | - break |
119 | | - else: |
120 | | - yield line |
121 | | - |
122 | 84 | def process_file(self, path): |
123 | 85 |
|
124 | 86 | advisories = [] |
@@ -212,10 +174,8 @@ def process_file(self, path): |
212 | 174 | return advisories |
213 | 175 |
|
214 | 176 | def get_data_from_md(self, path): |
215 | | - """Return a mapping of vulnerability data from istio . The data is |
216 | | - in the form of yaml_lines inside a .md file. |
217 | | - """ |
| 177 | + """Return a mapping of vulnerability data extracted from an advisory.""" |
218 | 178 |
|
219 | 179 | with open(path) as f: |
220 | | - yaml_lines = self.get_yaml_lines(f) |
221 | | - return self.get_data_from_yaml_lines(yaml_lines) |
| 180 | + front_matter, _ = split_markdown_front_matter(f.read()) |
| 181 | + return saneyaml.load(front_matter) |
0 commit comments