Skip to content

The Unified and Autonomous Development Platform

Fix issue #230 - XSS vulnerability when publish html report

Robin Shenba2d42f1f7ec
diff --git a/server-plugin/pom.xml b/server-plugin/pom.xml
index babda99b0e..476d11a3ee 100644
--- a/server-plugin/pom.xml
+++ b/server-plugin/pom.xml
@@ -17,7 +17,6 @@
</dependencies>
<modules>
<module>server-plugin-archetype</module>
- <module>server-plugin-report-html</module>
<module>server-plugin-executor-kubernetes</module>
<module>server-plugin-executor-docker</module>
<module>server-plugin-buildspec-maven</module>
diff --git a/server-plugin/server-plugin-report-clover/src/main/java/org/server/plugin/report/clover/JobCloverReport.java b/server-plugin/server-plugin-report-clover/src/main/java/org/server/plugin/report/clover/JobCloverReport.java
index 2c087110c7..4099a7b83b 100644
--- a/server-plugin/server-plugin-report-clover/src/main/java/org/server/plugin/report/clover/JobCloverReport.java
+++ b/server-plugin/server-plugin-report-clover/src/main/java/org/server/plugin/report/clover/JobCloverReport.java
@@ -32,8 +32,7 @@ import io.onedev.server.web.editable.annotation.Interpolative;
import io.onedev.server.web.editable.annotation.Patterns;
@Editable(name="Clover Coverage Metrics", description="Collected coverage information will be displayed "
- + "when view source files. <b>Note:</b> No any clover report will be displayed at build level "
- + "as clover also generates very powerful html report which can be published if necessary")
+ + "when view source files")
public class JobCloverReport extends JobReport {
private static final long serialVersionUID = 1L;
diff --git a/server-plugin/server-plugin-report-html/pom.xml b/server-plugin/server-plugin-report-html/pom.xml
deleted file mode 100644
index 440bc6a24b..0000000000
--- a/server-plugin/server-plugin-report-html/pom.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <artifactId>server-plugin-report-html</artifactId>
- <parent>
- <groupId>io.onedev</groupId>
- <artifactId>server-plugin</artifactId>
- <version>4.1.2</version>
- </parent>
- <properties>
- <moduleClass>io.onedev.server.plugin.report.html.HtmlReportModule</moduleClass>
- </properties>
-</project>
\ No newline at end of file
diff --git a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportCssResourceReference.java b/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportCssResourceReference.java
deleted file mode 100644
index 65a982a053..0000000000
--- a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportCssResourceReference.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package io.onedev.server.plugin.report.html;
-
-import io.onedev.server.web.page.base.BaseDependentCssResourceReference;
-
-public class HtmlReportCssResourceReference extends BaseDependentCssResourceReference {
-
- private static final long serialVersionUID = 1L;
-
- public HtmlReportCssResourceReference() {
- super(HtmlReportCssResourceReference.class, "html-report.css");
- }
-
-}
diff --git a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportDownloadResource.java b/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportDownloadResource.java
deleted file mode 100644
index 5fea02baa6..0000000000
--- a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportDownloadResource.java
+++ /dev/null
@@ -1,151 +0,0 @@
-package io.onedev.server.plugin.report.html;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.Callable;
-
-import javax.persistence.EntityNotFoundException;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.shiro.authz.UnauthorizedException;
-import org.apache.tika.io.IOUtils;
-import org.apache.wicket.request.mapper.parameter.PageParameters;
-import org.apache.wicket.request.resource.AbstractResource;
-
-import com.google.common.base.Joiner;
-
-import io.onedev.commons.utils.ExplicitException;
-import io.onedev.commons.utils.LockUtils;
-import io.onedev.server.OneDev;
-import io.onedev.server.entitymanager.BuildManager;
-import io.onedev.server.entitymanager.ProjectManager;
-import io.onedev.server.model.Build;
-import io.onedev.server.model.Project;
-import io.onedev.server.security.SecurityUtils;
-import io.onedev.server.storage.StorageManager;
-
-public class HtmlReportDownloadResource extends AbstractResource {
-
- private static final long serialVersionUID = 1L;
-
- private static final String PARAM_PROJECT = "project";
-
- private static final String PARAM_BUILD = "build";
-
- private static final String PARAM_REPORT = "report";
-
- private static final String PARAM_PATH = "path";
-
- @Override
- protected ResourceResponse newResourceResponse(Attributes attributes) {
- PageParameters params = attributes.getParameters();
-
- String projectName = params.get(PARAM_PROJECT).toString();
- if (StringUtils.isBlank(projectName))
- throw new IllegalArgumentException("project name has to be specified");
-
- Project project = OneDev.getInstance(ProjectManager.class).find(projectName);
-
- if (project == null)
- throw new EntityNotFoundException("Unable to find project: " + projectName);
-
- Long buildNumber = params.get(PARAM_BUILD).toOptionalLong();
-
- if (buildNumber == null)
- throw new IllegalArgumentException("build number has to be specified");
-
- Build build = OneDev.getInstance(BuildManager.class).find(project, buildNumber);
-
- if (build == null) {
- String message = String.format("Unable to find build (project: %s, build number: %d)",
- project.getName(), buildNumber);
- throw new EntityNotFoundException(message);
- }
-
- String reportName = params.get(PARAM_REPORT).toOptionalString();
-
- if (reportName == null)
- throw new IllegalArgumentException("Html report name has to be specified");
-
- if (!SecurityUtils.canAccessReport(build, reportName))
- throw new UnauthorizedException();
-
- List<String> pathSegments = new ArrayList<>();
- String pathSegment = params.get(PARAM_PATH).toString();
- if (pathSegment.length() != 0)
- pathSegments.add(pathSegment);
- else
- throw new ExplicitException("Html report path has to be specified");
-
- for (int i = 0; i < params.getIndexedCount(); i++) {
- pathSegment = params.get(i).toString();
- if (pathSegment.length() != 0)
- pathSegments.add(pathSegment);
- }
-
- String htmlPath = Joiner.on("/").join(pathSegments);
-
- File buildDir = OneDev.getInstance(StorageManager.class).getBuildDir(project.getId(), build.getNumber());
- File reportDir = new File(buildDir, JobHtmlReport.DIR + "/" + reportName);
-
- File htmlFile = new File(reportDir, htmlPath);
- if (!htmlFile.exists() || htmlFile.isDirectory()) {
- String message = String.format("Specified html path does not exist or is a directory (project: %s, build number: %d, path: %s)",
- project.getName(), build.getNumber(), htmlPath);
- throw new ExplicitException(message);
- }
-
- ResourceResponse response = new ResourceResponse();
- try {
- response.setContentType(Files.probeContentType(htmlFile.toPath()));
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
-
- response.disableCaching();
-
- try {
- response.setFileName(URLEncoder.encode(htmlFile.getName(), StandardCharsets.UTF_8.name()));
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
- response.setWriteCallback(new WriteCallback() {
-
- @Override
- public void writeData(Attributes attributes) throws IOException {
- LockUtils.read(build.getReportLockKey(JobHtmlReport.DIR), new Callable<Void>() {
-
- @Override
- public Void call() throws Exception {
- try (InputStream is = new FileInputStream(htmlFile)) {
- IOUtils.copy(is, attributes.getResponse().getOutputStream());
- }
- return null;
- }
-
- });
- }
-
- });
-
- return response;
- }
-
- public static PageParameters paramsOf(Project project, Long buildNumber, String reportName, String path) {
- PageParameters params = new PageParameters();
- params.set(PARAM_PROJECT, project.getName());
- params.set(PARAM_BUILD, buildNumber);
- params.set(PARAM_REPORT, reportName);
- params.set(PARAM_PATH, path);
- return params;
- }
-
-}
diff --git a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportDownloadResourceReference.java b/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportDownloadResourceReference.java
deleted file mode 100644
index a652f649c8..0000000000
--- a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportDownloadResourceReference.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package io.onedev.server.plugin.report.html;
-
-import org.apache.wicket.request.resource.IResource;
-import org.apache.wicket.request.resource.ResourceReference;
-
-public class HtmlReportDownloadResourceReference extends ResourceReference {
-
- private static final long serialVersionUID = 1L;
-
- public HtmlReportDownloadResourceReference() {
- super("html-report");
- }
-
- @Override
- public IResource getResource() {
- return new HtmlReportDownloadResource();
- }
-
-}
diff --git a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportModule.java b/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportModule.java
deleted file mode 100644
index e3bb73798a..0000000000
--- a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportModule.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package io.onedev.server.plugin.report.html;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.Callable;
-
-import org.apache.wicket.protocol.http.WebApplication;
-
-import com.google.common.collect.Sets;
-
-import io.onedev.commons.launcher.loader.AbstractPluginModule;
-import io.onedev.commons.launcher.loader.ImplementationProvider;
-import io.onedev.commons.utils.LockUtils;
-import io.onedev.server.buildspec.job.JobReport;
-import io.onedev.server.model.Build;
-import io.onedev.server.security.SecurityUtils;
-import io.onedev.server.web.WebApplicationConfigurator;
-import io.onedev.server.web.mapper.DynamicPathPageMapper;
-import io.onedev.server.web.mapper.DynamicPathResourceMapper;
-import io.onedev.server.web.page.project.builds.detail.BuildTab;
-import io.onedev.server.web.page.project.builds.detail.BuildTabContribution;
-
-public class HtmlReportModule extends AbstractPluginModule {
-
- @Override
- protected void configure() {
- super.configure();
-
- contribute(ImplementationProvider.class, new ImplementationProvider() {
-
- @Override
- public Class<?> getAbstractClass() {
- return JobReport.class;
- }
-
- @Override
- public Collection<Class<?>> getImplementations() {
- return Sets.newHashSet(JobHtmlReport.class);
- }
-
- });
-
- contribute(BuildTabContribution.class, new BuildTabContribution() {
-
- @Override
- public List<BuildTab> getTabs(Build build) {
- List<BuildTab> tabs = new ArrayList<>();
- LockUtils.read(build.getReportLockKey(JobHtmlReport.DIR), new Callable<Void>() {
-
- @Override
- public Void call() throws Exception {
- if (build.getReportDir(JobHtmlReport.DIR).exists()) {
- for (File reportDir: build.getReportDir(JobHtmlReport.DIR).listFiles()) {
- if (SecurityUtils.canAccessReport(build, reportDir.getName()))
- tabs.add(new HtmlReportTab(reportDir.getName()));
- }
- }
- return null;
- }
-
- });
- return tabs;
- }
-
- @Override
- public int getOrder() {
- return 200;
- }
-
- });
-
- contribute(WebApplicationConfigurator.class, new WebApplicationConfigurator() {
-
- @Override
- public void configure(WebApplication application) {
- application.mount(new DynamicPathPageMapper("projects/${project}/builds/${build}/html-reports/${report}", HtmlReportPage.class));
- application.mount(new DynamicPathResourceMapper("downloads/projects/${project}/builds/${build}/html-reports/${report}/${path}",
- new HtmlReportDownloadResourceReference()));
- }
-
- });
-
- }
-
-}
diff --git a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportPage.html b/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportPage.html
deleted file mode 100644
index f7915ebf68..0000000000
--- a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportPage.html
+++ /dev/null
@@ -1,3 +0,0 @@
-<wicket:extend>
- <iframe wicket:id="htmlReport" class="html-report"></iframe>
-</wicket:extend>
\ No newline at end of file
diff --git a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportPage.java b/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportPage.java
deleted file mode 100644
index 31265c7ab1..0000000000
--- a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportPage.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package io.onedev.server.plugin.report.html;
-
-import java.io.File;
-import java.nio.charset.StandardCharsets;
-import java.util.concurrent.Callable;
-
-import org.apache.wicket.behavior.AttributeAppender;
-import org.apache.wicket.markup.ComponentTag;
-import org.apache.wicket.markup.head.CssHeaderItem;
-import org.apache.wicket.markup.head.IHeaderResponse;
-import org.apache.wicket.markup.html.WebMarkupContainer;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.request.cycle.RequestCycle;
-import org.apache.wicket.request.mapper.parameter.PageParameters;
-
-import io.onedev.commons.utils.FileUtils;
-import io.onedev.commons.utils.LockUtils;
-import io.onedev.server.model.Build;
-import io.onedev.server.security.SecurityUtils;
-import io.onedev.server.web.page.project.builds.detail.BuildDetailPage;
-
-@SuppressWarnings("serial")
-public class HtmlReportPage extends BuildDetailPage {
-
- private static final String PARAM_REPORT = "report";
-
- private final String reportName;
-
- public HtmlReportPage(PageParameters params) {
- super(params);
-
- reportName = params.get(PARAM_REPORT).toString();
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- String startPage = LockUtils.read(getBuild().getReportLockKey(JobHtmlReport.DIR), new Callable<String>() {
-
- @Override
- public String call() throws Exception {
- File startPageFile = new File(getBuild().getReportDir(JobHtmlReport.DIR),
- reportName + "/" + JobHtmlReport.START_PAGE);
- if (startPageFile.exists())
- return FileUtils.readFileToString(startPageFile, StandardCharsets.UTF_8);
- else
- return null;
- }
-
- });
-
- if (startPage != null) {
- PageParameters params = HtmlReportDownloadResource.paramsOf(getProject(), getBuild().getNumber(),
- reportName, startPage);
- CharSequence startPageUrl = RequestCycle.get().urlFor(new HtmlReportDownloadResourceReference(), params);
- add(new WebMarkupContainer("htmlReport") {
-
- @Override
- public void renderHead(IHeaderResponse response) {
- super.renderHead(response);
- response.render(CssHeaderItem.forReference(new HtmlReportCssResourceReference()));
- }
-
- }.add(AttributeAppender.append("src", startPageUrl.toString())).add(AttributeAppender.append("class", "d-flex flex-grow-1")));
- } else {
- add(new Label("htmlReport", "No html report published") {
-
- @Override
- protected void onComponentTag(ComponentTag tag) {
- super.onComponentTag(tag);
- tag.setName("div");
- }
-
- }.add(AttributeAppender.append("class", "alert alert-notice alert-light-warning mb-0")));
- }
- }
-
- @Override
- protected boolean isPermitted() {
- return SecurityUtils.canAccessReport(getBuild(), reportName);
- }
-
- public String getReportName() {
- return reportName;
- }
-
- public static PageParameters paramsOf(Build build, String reportName) {
- PageParameters params = paramsOf(build);
- params.add(PARAM_REPORT, reportName);
- return params;
- }
-}
diff --git a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportTab.java b/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportTab.java
deleted file mode 100644
index e9fac6f847..0000000000
--- a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportTab.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package io.onedev.server.plugin.report.html;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.Page;
-import org.apache.wicket.markup.html.link.Link;
-import org.apache.wicket.request.mapper.parameter.PageParameters;
-
-import io.onedev.server.web.component.link.ViewStateAwarePageLink;
-import io.onedev.server.web.component.tabbable.PageTabHead;
-import io.onedev.server.web.page.project.builds.detail.BuildDetailPage;
-import io.onedev.server.web.page.project.builds.detail.BuildTab;
-
-@SuppressWarnings("serial")
-public class HtmlReportTab extends BuildTab {
-
- public HtmlReportTab(String reportName) {
- super(reportName, HtmlReportPage.class);
- }
-
- @Override
- public Component render(String componentId) {
- return new PageTabHead(componentId, this) {
-
- @Override
- protected Link<?> newLink(String linkId, Class<? extends Page> pageClass) {
- BuildDetailPage page = (BuildDetailPage) getPage();
- PageParameters params = HtmlReportPage.paramsOf(
- page.getBuild(), getTitle());
- return new ViewStateAwarePageLink<Void>(linkId, pageClass, params);
- }
-
- };
- }
-
- @Override
- public boolean isActive(Page currentPage) {
- if (super.isActive(currentPage)) {
- HtmlReportPage htmlReportPage = (HtmlReportPage) currentPage;
- return getTitle().equals(htmlReportPage.getReportName());
- } else {
- return false;
- }
- }
-
-}
diff --git a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/JobHtmlReport.java b/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/JobHtmlReport.java
deleted file mode 100644
index e1da1820a2..0000000000
--- a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/JobHtmlReport.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package io.onedev.server.plugin.report.html;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.util.concurrent.Callable;
-
-import org.hibernate.validator.constraints.NotEmpty;
-
-import io.onedev.commons.codeassist.InputSuggestion;
-import io.onedev.commons.utils.FileUtils;
-import io.onedev.commons.utils.LockUtils;
-import io.onedev.server.buildspec.job.Job;
-import io.onedev.server.buildspec.job.JobReport;
-import io.onedev.server.model.Build;
-import io.onedev.server.util.SimpleLogger;
-import io.onedev.server.web.editable.annotation.Editable;
-import io.onedev.server.web.editable.annotation.Interpolative;
-
-@Editable(name="Html Report")
-public class JobHtmlReport extends JobReport {
-
- private static final long serialVersionUID = 1L;
-
- public static final String DIR = "html-reports";
-
- public static final String START_PAGE = "$onedev-htmlreport-startpage$";
-
- private String startPage;
-
- @Editable(order=1100, description="Specify start page of the report relative to <a href='$docRoot/pages/concepts.md#job-workspace' target='_blank'>job workspace</a>, for instance: api/index.html")
- @Interpolative(variableSuggester="suggestVariables")
- @NotEmpty
- public String getStartPage() {
- return startPage;
- }
-
- public void setStartPage(String startPage) {
- this.startPage = startPage;
- }
-
- @SuppressWarnings("unused")
- private static List<InputSuggestion> suggestVariables(String matchWith) {
- return Job.suggestVariables(matchWith);
- }
-
- @Override
- public void process(Build build, File workspace, SimpleLogger logger) {
- File reportDir = new File(build.getReportDir(DIR), getReportName());
- LockUtils.write(build.getReportLockKey(DIR), new Callable<Void>() {
-
- @Override
- public Void call() throws Exception {
- File startPage = new File(workspace, getStartPage());
- if (startPage.exists()) {
- FileUtils.createDir(reportDir);
-
- File startPageFile = new File(reportDir, START_PAGE);
- FileUtils.writeFile(startPageFile, getStartPage());
-
- int baseLen = workspace.getAbsolutePath().length() + 1;
- for (File file: getPatternSet().listFiles(workspace)) {
- try {
- FileUtils.copyFile(file, new File(reportDir, file.getAbsolutePath().substring(baseLen)));
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- } else {
- logger.log("WARNING: Html report start page not found: " + startPage.getAbsolutePath());
- }
- return null;
- }
-
- });
- }
-
-}
diff --git a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/html-report.css b/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/html-report.css
deleted file mode 100644
index 44e5061c09..0000000000
--- a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/html-report.css
+++ /dev/null
@@ -1,4 +0,0 @@
-.html-report {
- width: 100%;
- border: none;
-}
\ No newline at end of file
diff --git a/server-product/pom.xml b/server-product/pom.xml
index d907b91ec9..2fafa6843d 100644
--- a/server-product/pom.xml
+++ b/server-product/pom.xml
@@ -15,11 +15,6 @@
<artifactId>server-core</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>io.onedev</groupId>
- <artifactId>server-plugin-report-html</artifactId>
- <version>${project.version}</version>
- </dependency>
<dependency>
<groupId>io.onedev</groupId>
<artifactId>server-plugin-report-jest</artifactId>