mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-10 02:26:18 +00:00
Use DirectoryBrowserSupport to serve FileParameterValue
This will allow the use of Resource Root URLs for those files. Additionally, minor UI improvements: - Explicitly indicate when no file was uploaded - Do not show original file name on the UI, nobody cares
This commit is contained in:
1 parent
78aae881db
commit
bc8ea6cdb6
4 files changed
+25
-50
No files matched your search
@@ -226,46 +226,11 @@ public class FileParameterValue extends ParameterValue {
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @throws ServletException
|
||||
* @throws IOException
|
||||
*/
|
||||
public void doDynamic(StaplerRequest request, StaplerResponse response) throws ServletException, IOException {
|
||||
if (("/" + originalFileName).equals(request.getRestOfPath())) {
|
||||
AbstractBuild build = (AbstractBuild)request.findAncestor(AbstractBuild.class).getObject();
|
||||
File fileParameter = getLocationUnderBuild(build);
|
||||
|
||||
if (!ALLOW_FOLDER_TRAVERSAL_OUTSIDE_WORKSPACE) {
|
||||
File fileParameterFolder = getFileParameterFolderUnderBuild(build);
|
||||
|
||||
//TODO can be replaced by Util#isDescendant in 2.80+
|
||||
Path child = fileParameter.getAbsoluteFile().toPath().normalize();
|
||||
Path parent = fileParameterFolder.getAbsoluteFile().toPath().normalize();
|
||||
if (!child.startsWith(parent)) {
|
||||
throw new IllegalStateException("The fileParameter tried to escape the expected folder: " + location);
|
||||
}
|
||||
}
|
||||
|
||||
if (fileParameter.isFile()) {
|
||||
try (InputStream data = Files.newInputStream(fileParameter.toPath())) {
|
||||
long lastModified = fileParameter.lastModified();
|
||||
long contentLength = fileParameter.length();
|
||||
if (request.hasParameter("view")) {
|
||||
response.serveFile(request, data, lastModified, contentLength, "plain.txt");
|
||||
} else {
|
||||
String csp = SystemProperties.getString(DirectoryBrowserSupport.class.getName() + ".CSP", DirectoryBrowserSupport.DEFAULT_CSP_VALUE);
|
||||
if (!csp.trim().equals("")) {
|
||||
// allow users to prevent sending this header by setting empty system property
|
||||
for (String header : new String[]{"Content-Security-Policy", "X-WebKit-CSP", "X-Content-Security-Policy"}) {
|
||||
response.setHeader(header, csp);
|
||||
}
|
||||
}
|
||||
response.serveFile(request, data, lastModified, contentLength, originalFileName);
|
||||
}
|
||||
} catch (InvalidPathException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
public DirectoryBrowserSupport doDynamic(StaplerRequest request, StaplerResponse response) {
|
||||
AbstractBuild build = (AbstractBuild)request.findAncestor(AbstractBuild.class).getObject();
|
||||
File fileParameter = getFileParameterFolderUnderBuild(build);
|
||||
return new DirectoryBrowserSupport(build, new FilePath(fileParameter), Messages.FileParameterValue_IndexTitle(), "folder.png", false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user