Skip to content

Commit 0e6e1bc

Browse files
Fix XSS in rendered report: HTML-escape user-controlled reportLanguage (via #3337)
1 parent 03b4ee9 commit 0e6e1bc

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
@@ -10,7 +10,7 @@
1010
<#-- @ftlvariable name="reportName" type="java.lang.String" -->
1111
<#-- @ftlvariable name="reportLanguage" type="java.lang.String" -->
1212
<!DOCTYPE html>
13-
<html dir="ltr" lang="${reportLanguage!"en"}">
13+
<html dir="ltr" lang="${(reportLanguage!"en")?html}">
1414
<head>
1515
<meta charset="utf-8">
1616
<meta name="allure-report-uuid" content="${reportUuid}">

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
@@ -104,6 +104,29 @@ void shouldEscapeHtmlInReportName(@TempDir final Path tempDirectory) {
104104
.doesNotContain(hostile);
105105
}
106106

107+
/**
108+
* Verifies that a hostile {@code reportLanguage} containing live HTML
109+
* cannot escape the {@code lang} attribute on the root {@code <html>} tag.
110+
*/
111+
@Description
112+
@Test
113+
void shouldEscapeHtmlInReportLanguage(@TempDir final Path tempDirectory) {
114+
final String hostile = "en\"><script>alert('xss')</script>";
115+
final Configuration configuration = ConfigurationBuilder.empty()
116+
.withReportLanguage(hostile)
117+
.build();
118+
final InMemoryReportStorage reportStorage = new InMemoryReportStorage();
119+
generateReport(configuration, reportStorage, tempDirectory);
120+
121+
final Path indexHtml = tempDirectory.resolve("index.html");
122+
123+
assertThat(indexHtml)
124+
.isRegularFile()
125+
.content(StandardCharsets.UTF_8)
126+
.as("hostile reportLanguage must not break out of the lang attribute")
127+
.doesNotContain(hostile);
128+
}
129+
107130
/**
108131
* Verifies setting language for web report generation.
109132
*/

0 commit comments

Comments
 (0)