Skip to content

Commit 5868fc7

Browse files
authored
Merge pull request #331 from sbs2001/github-refs
Collect references from github importer
2 parents 83a5e18 + f981d9f commit 5868fc7

3 files changed

Lines changed: 53 additions & 16 deletions

File tree

vulnerabilities/importer_yielder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
'data_source': 'GitHubAPIDataSource',
180180
'data_source_cfg': {
181181
'endpoint': 'https://api.github.com/graphql',
182-
'ecosystems': ['MAVEN', 'NUGET', 'COMPOSER', 'PIP', 'RUBYGEMS']
182+
'ecosystems': ['PIP']
183183
}
184184
},
185185
{

vulnerabilities/importers/github.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
value
6161
}
6262
summary
63+
references {
64+
url
65+
}
6366
}
6467
package {
6568
name
@@ -158,6 +161,24 @@ def process_name(ecosystem: str, pkg_name: str) -> Optional[Tuple[Optional[str],
158161
if ecosystem == "NUGET" or ecosystem == "PIP" or ecosystem == "RUBYGEMS":
159162
return None, pkg_name
160163

164+
@staticmethod
165+
def extract_references(reference_data):
166+
references = []
167+
for ref in reference_data:
168+
url = ref["url"]
169+
if "GHSA-" in url.upper():
170+
reference = Reference(
171+
url=url,
172+
reference_id=url.split("/")[-1]
173+
)
174+
else:
175+
reference = Reference(
176+
url=url
177+
)
178+
references.append(reference)
179+
180+
return references
181+
161182
def collect_packages(self, ecosystem):
162183
packages = set()
163184
for page in self.advisories[ecosystem]:
@@ -194,22 +215,13 @@ def process_response(self) -> List[Advisory]:
194215
unaffected_purls = set()
195216

196217
cve_ids = set()
197-
vuln_references = []
218+
vuln_references = self.extract_references(adv["node"]["advisory"]["references"])
198219
vuln_desc = adv["node"]["advisory"]["summary"]
199220

200221
for vuln in adv["node"]["advisory"]["identifiers"]:
201222
if vuln["type"] == "CVE":
202223
cve_ids.add(vuln["value"])
203224

204-
elif vuln["type"] == "GHSA":
205-
ghsa = vuln["value"]
206-
vuln_references.append(
207-
Reference(
208-
reference_id=ghsa,
209-
url="https://github.com/advisories/{}".format(ghsa),
210-
)
211-
)
212-
213225
for cve_id in cve_ids:
214226
adv_list.append(
215227
Advisory(

vulnerabilities/tests/test_data/github_api/response.json

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
"value": "CVE-2019-0199"
1616
}
1717
],
18-
"summary": "Denial of Service in Tomcat"
18+
"summary": "Denial of Service in Tomcat",
19+
"references":[
20+
{
21+
"url":"https://github.com/advisories/GHSA-qcxh-w3j9-58qr"
22+
}
23+
]
1924
},
2025
"package": {
2126
"name": "org.apache.tomcat.embed:tomcat-embed-core"
@@ -36,7 +41,12 @@
3641
"value": "CVE-2019-0199"
3742
}
3843
],
39-
"summary": "Denial of Service in Tomcat"
44+
"summary": "Denial of Service in Tomcat",
45+
"references":[
46+
{
47+
"url":"https://github.com/advisories/GHSA-qcxh-w3j9-58qr"
48+
}
49+
]
4050
},
4151
"package": {
4252
"name": "org.apache.tomcat.embed:tomcat-embed-core"
@@ -57,7 +67,12 @@
5767
"value": "CVE-2020-1938"
5868
}
5969
],
60-
"summary": "Improper Input Validation in Tomcat"
70+
"summary": "Improper Input Validation in Tomcat",
71+
"references":[
72+
{
73+
"url":"https://github.com/advisories/GHSA-c9hw-wf7x-jp9j"
74+
}
75+
]
6176
},
6277
"package": {
6378
"name": "org.apache.tomcat.embed:tomcat-embed-core"
@@ -78,7 +93,12 @@
7893
"value": "CVE-2020-1938"
7994
}
8095
],
81-
"summary": "Improper Input Validation in Tomcat"
96+
"summary": "Improper Input Validation in Tomcat",
97+
"references":[
98+
{
99+
"url":"https://github.com/advisories/GHSA-c9hw-wf7x-jp9j"
100+
}
101+
]
82102
},
83103
"package": {
84104
"name": "org.apache.tomcat.embed:tomcat-embed-core"
@@ -99,7 +119,12 @@
99119
"value": "CVE-2020-1938"
100120
}
101121
],
102-
"summary": "Improper Input Validation in Tomcat"
122+
"summary": "Improper Input Validation in Tomcat",
123+
"references":[
124+
{
125+
"url":"https://github.com/advisories/GHSA-c9hw-wf7x-jp9j"
126+
}
127+
]
103128
},
104129
"package": {
105130
"name": "org.apache.tomcat.embed:tomcat-embed-core"

0 commit comments

Comments
 (0)