Skip to content

The Unified and Autonomous Development Platform

fix: A possible XSS vulnerability when GTest report is published (OD-2718)

Robin Shen8454d9d49f7a
diff --git a/server-plugin/server-plugin-report-gtest/src/main/java/io/onedev/server/plugin/report/gtest/GTestReportParser.java b/server-plugin/server-plugin-report-gtest/src/main/java/io/onedev/server/plugin/report/gtest/GTestReportParser.java
index c24e494086..099f0a5dcb 100644
--- a/server-plugin/server-plugin-report-gtest/src/main/java/io/onedev/server/plugin/report/gtest/GTestReportParser.java
+++ b/server-plugin/server-plugin-report-gtest/src/main/java/io/onedev/server/plugin/report/gtest/GTestReportParser.java
@@ -112,7 +112,7 @@ public class GTestReportParser {
private static Component renderMessage(String componentId, Build build,
@Nullable Pair<String, Integer> blobLocation,
@Nullable String message) {
- if (blobLocation != null) {
+ if (blobLocation != null && message != null) {
ProjectBlobPage.State state = new ProjectBlobPage.State();
state.blobIdent = new BlobIdent(build.getCommitHash(), blobLocation.getLeft());
PlanarRange range = new PlanarRange(blobLocation.getRight()-1, -1, blobLocation.getRight()-1, -1);
@@ -121,8 +121,8 @@ public class GTestReportParser {
String url = RequestCycle.get().urlFor(ProjectBlobPage.class, params).toString();
var html = String.format("<a href='%s'>%s</a><br>%s",
url,
- StringUtils.substringBefore(message, "\n").trim(),
- StringUtils.substringAfter(message, "\n"));
+ HtmlEscape.escapeHtml5(StringUtils.substringBefore(message, "\n").trim()),
+ HtmlEscape.escapeHtml5(StringUtils.substringAfter(message, "\n")));
return new Label(componentId, html).setEscapeModelStrings(false);
} else if (message != null) {
return new Label(componentId, message);