Skip to content

Commit 98d91c0

Browse files
Fix XSS in rendered report: HTML-escape user-controlled reportName (via #3334)
1 parent ab5da57 commit 98d91c0

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

allure-generator/src/main/resources/tpl/index.html.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<head>
1515
<meta charset="utf-8">
1616
<meta name="allure-report-uuid" content="${reportUuid}">
17-
<title>${reportName!"Allure Report"}</title>
17+
<title>${(reportName!"Allure Report")?html}</title>
1818
<link rel="icon" href="${faviconUrl}">
1919
<!-- allure-core-head:start -->
2020
<#list coreStyleUrls as styleUrl>

allure-generator/src/test/java/io/qameta/allure/core/ReportWebGeneratorTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,29 @@ void shouldDisableAnalytics(@TempDir final Path tempDirectory) {
8181
.doesNotContain("dataLayer");
8282
}
8383

84+
/**
85+
* Verifies that a hostile {@code reportName} containing live HTML / JS
86+
* is HTML-escaped rather than rendered raw into the {@code <title>} tag.
87+
*/
88+
@Description
89+
@Test
90+
void shouldEscapeHtmlInReportName(@TempDir final Path tempDirectory) {
91+
final String hostile = "<script>alert('xss')</script>";
92+
final Configuration configuration = ConfigurationBuilder.empty()
93+
.withReportName(hostile)
94+
.build();
95+
final InMemoryReportStorage reportStorage = new InMemoryReportStorage();
96+
generateReport(configuration, reportStorage, tempDirectory);
97+
98+
final Path indexHtml = tempDirectory.resolve("index.html");
99+
100+
assertThat(indexHtml)
101+
.isRegularFile()
102+
.content(StandardCharsets.UTF_8)
103+
.as("hostile reportName must not appear as live HTML in the generated report")
104+
.doesNotContain(hostile);
105+
}
106+
84107
/**
85108
* Verifies setting language for web report generation.
86109
*/

0 commit comments

Comments
 (0)