Skip to content

Commit cac611b

Browse files
committed
fix: resolve Snyk CWE-611 (XXE) and CWE-643 (XPath injection) in report scripts
Use defusedxml for XML parsing in both HTML report scripts to fix insecure parser (XXE/DDoS). Add Scripts/requirements.txt with defusedxml>=0.7.0. Replace dynamic XPath with a safe lookup (find all UnitTest, match by id in Python) in both scripts to fix XPath injection.
1 parent c42e211 commit cac611b

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Scripts/generate_enhanced_html_report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ def parse_trx(self):
158158
test_output = stdout_elem.text
159159
structured_output = self.parse_structured_output(test_output)
160160

161-
# Get test category
161+
# Get test category (find by id without dynamic XPath to avoid CWE-643)
162162
test_def_id = test_result.get('testId', '')
163-
test_def = root.find(f".//UnitTest[@id='{test_def_id}']", ns)
163+
test_def = next((el for el in root.findall('.//UnitTest', ns) if el.get('id') == test_def_id), None)
164164
category = 'General'
165165
if test_def is not None:
166166
test_method = test_def.find('.//TestMethod', ns)

Scripts/generate_html_report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ def parse_trx(self):
7878
if stacktrace_elem is not None:
7979
error_stacktrace = stacktrace_elem.text
8080

81-
# Get test category
81+
# Get test category (find by id without dynamic XPath to avoid CWE-643)
8282
test_def_id = test_result.get('testId', '')
83-
test_def = root.find(f".//UnitTest[@id='{test_def_id}']", ns)
83+
test_def = next((el for el in root.findall('.//UnitTest', ns) if el.get('id') == test_def_id), None)
8484
category = 'General'
8585
if test_def is not None:
8686
test_method = test_def.find('.//TestMethod', ns)

0 commit comments

Comments
 (0)