Skip to content

Commit 8781f30

Browse files
tarun111111claude
andcommitted
Enhance Apache Tomcat importer to collect commit information
- Add extract_commit_urls_from_advisory_group() function to scan entire advisory text - Support GitHub, SVN, and GitBox commit URLs - Improve commit capture rate by scanning all paragraphs instead of specific text patterns - Maintain 100% backward compatibility with existing functionality Fixes #2129 Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: tarun111111 <tarunpuri2544@gmail.com>
1 parent 053c8fb commit 8781f30

1 file changed

Lines changed: 41 additions & 7 deletions

File tree

vulnerabilities/importers/apache_tomcat.py

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,25 +266,57 @@ def extract_tomcat_advisory_data_from_page(apache_tomcat_advisory_html):
266266
)
267267

268268

269+
def extract_commit_urls_from_advisory_group(para_list):
270+
"""
271+
Extract commit URLs from an advisory group of paragraphs.
272+
Captures commit URLs from GitHub, SVN, and GitBox sources.
273+
274+
Args:
275+
para_list: List of BeautifulSoup paragraph elements
276+
277+
Returns:
278+
List of commit URLs found in the advisory
279+
"""
280+
commit_urls = []
281+
282+
for para in para_list:
283+
# Find all links in the paragraph
284+
links = para.find_all("a")
285+
for link in links:
286+
href = link.get("href", "")
287+
288+
# Capture GitHub commit URLs
289+
if "github.com/apache/tomcat/commit/" in href:
290+
commit_urls.append(href)
291+
# Capture SVN commit URLs
292+
elif "svn.apache.org" in href and "rev=" in href:
293+
commit_urls.append(href)
294+
# Capture GitBox commit URLs
295+
elif "gitbox.apache.org" in href:
296+
commit_urls.append(href)
297+
298+
return commit_urls
299+
300+
301+
269302
def generate_advisory_data_objects(url, tomcat_advisory_data_object):
270303
fixed_versions = tomcat_advisory_data_object.fixed_versions
271304
severity_scores = ("Low:", "Moderate:", "Important:", "High:", "Critical:")
272305

273306
for para_list in tomcat_advisory_data_object.advisory_groups:
274307
affected_versions = []
275-
fixed_commit_list = []
276308
references = []
277309
cve_url_list = []
310+
311+
# Extract commit URLs from entire advisory group
312+
commit_urls = extract_commit_urls_from_advisory_group(para_list)
313+
278314
for para in para_list:
279315
if para.text.startswith("Affects:"):
280316
formatted_affected_version_data = para.text.split(":")[-1].split(", ")
281317
affected_versions.extend(formatted_affected_version_data)
282-
elif "was fixed in" in para.text or "was fixed with" in para.text:
283-
fixed_commit_list = para.find_all("a")
284-
references.extend([ref_url["href"] for ref_url in fixed_commit_list])
285318
elif para.text.startswith(severity_scores):
286319
cve_url_list = para.find_all("a")
287-
cve_list = [cve_url.text for cve_url in cve_url_list]
288320
severity_score = para.text.split(":")[0]
289321

290322
for cve_url in cve_url_list:
@@ -331,8 +363,9 @@ def generate_advisory_data_objects(url, tomcat_advisory_data_object):
331363
),
332364
]
333365

334-
for commit_url in fixed_commit_list:
335-
references.append(Reference(url=commit_url["href"]))
366+
# Add all commit URLs found in the advisory
367+
for commit_url in commit_urls:
368+
references.append(Reference(url=commit_url))
336369

337370
affected_packages = []
338371

@@ -366,6 +399,7 @@ def generate_advisory_data_objects(url, tomcat_advisory_data_object):
366399
)
367400

368401

402+
369403
def to_version_ranges_apache(versions_data, fixed_versions):
370404
constraints = []
371405

0 commit comments

Comments
 (0)