From 62323bcab0aacd5180204d613abb5a4dedab9532 Mon Sep 17 00:00:00 2001 From: Diego Galaviz Date: Thu, 29 Oct 2026 20:57:14 -0600 Subject: [PATCH] fix(report): escape the executive summary's document count The Documents card interpolated document_count into the page unescaped. ProcessEvaluation validates the field as an int at construction, but not on assignment or through model_construct, so a caller that assigns it, or builds the model with model_construct, could put markup into the report. Document data does not reach it: the bulk evaluator sets an int, and a results dict falls back to 1. The value now goes through html.escape like the other cells, and a test assigns markup after construction and asserts it is escaped. It has the same in-process-caller reachability as #453; #456 escapes the visualization_engine.py cells, not this one. --- CHANGELOG.md | 6 ++++++ src/stickler/reporting/html/section_generator.py | 2 +- tests/reporting/html/test_section_generator.py | 16 +++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4a19d31..f6bbd07b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -199,6 +199,12 @@ Each release links to full notes on the no longer split an entity such as `&` ([#422](https://github.com/awslabs/stickler/issues/422)) +- **The HTML report's Executive Summary escapes its `Documents` count.** A + `document_count` assigned to a `ProcessEvaluation` after construction, or set + through `model_construct`, is not validated as an `int`, so a string assigned + there was written into the page unescaped. Document data does not reach this + value. + - List reporting ([#332](https://github.com/awslabs/stickler/issues/332)): `non_matches` and `field_comparisons` reuse the pairings, scores, and threshold decisions made during list scoring. Rejected pairs produce indexed diff --git a/src/stickler/reporting/html/section_generator.py b/src/stickler/reporting/html/section_generator.py index e2b5548e..509b76bd 100644 --- a/src/stickler/reporting/html/section_generator.py +++ b/src/stickler/reporting/html/section_generator.py @@ -30,7 +30,7 @@ def generate_executive_summary(self, config: ReportConfig) -> str: html_string += f"""
-
{doc_count}
+
{html.escape(str(doc_count))}
Documents
""" diff --git a/tests/reporting/html/test_section_generator.py b/tests/reporting/html/test_section_generator.py index 2113fcb5..e1f87873 100644 --- a/tests/reporting/html/test_section_generator.py +++ b/tests/reporting/html/test_section_generator.py @@ -65,7 +65,21 @@ def test_generate_executive_summary_missing_document_count(self, mock_extract_me result = self.section_generator.generate_executive_summary(config) assert '
1
' in result # Default value - + + def test_executive_summary_escapes_the_document_count(self): + """A document_count assigned after construction is not validated, so it is escaped.""" + results = ProcessEvaluation(document_count=3, metrics={}) + results.document_count = '' + generator = SectionGenerator(results, self.mock_viz_engine) + + result = generator.generate_executive_summary(ReportConfig()) + + assert '' not in result + assert ( + '
<img src=x onerror=alert(1)>
' + in result + ) + @patch('stickler.reporting.html.utils.data_extractors.DataExtractor.extract_field_metrics') def test_generate_field_analysis(self, mock_extract_field_metrics): """Test field analysis generation."""