Skip to content

Commit 21e947e

Browse files
committed
Update 'DownloadTempImageAction' to use FileLike.
1 parent dd196e3 commit 21e947e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

SequenceAnalysis/src/org/labkey/sequenceanalysis/SequenceAnalysisController.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,21 @@ public static class DownloadTempImageAction extends ExportAction<TempImageAction
435435
@Override
436436
public void export(TempImageAction form, HttpServletResponse response, BindException errors) throws Exception
437437
{
438-
File parentDir = form.getDirectory() == null ? FileUtil.getTempDirectory() : new File(FileUtil.getTempDirectory(), form.getDirectory());
439-
File targetFile = new File(parentDir, form.getFileName());
438+
File targetFile;
439+
FileLike tempDirRoot = new FileSystemLike.Builder(FileUtil.getTempDirectory()).root();
440+
if (!(tempDirRoot.getFileSystem().isDescendant(tempDirRoot, new File(form.getDirectory()).toURI())))
441+
{
442+
throw new FileNotFoundException("Directory '" + form.getDirectory() + "' is not the descendant of '" + tempDirRoot.getFileSystem() + "'");
443+
}
444+
FileLike parentDirFileLike = form.getDirectory() == null ? tempDirRoot : tempDirRoot.resolveFile(new Path(form.getDirectory()));
445+
File parentDir = FileSystemLike.toFile(parentDirFileLike);
446+
447+
if (!(parentDirFileLike.getFileSystem().isDescendant(parentDirFileLike, new File(form.getFileName()).toURI())))
448+
{
449+
throw new FileNotFoundException("File '" + form.getFileName() + "' is not the descendant of '" + parentDirFileLike.getPath() + "'");
450+
}
451+
452+
targetFile = FileSystemLike.toFile(parentDirFileLike.resolveChild(form.getFileName()));
440453
targetFile = FileUtil.getAbsoluteCaseSensitiveFile(targetFile);
441454

442455
if (!NetworkDrive.exists(targetFile))

0 commit comments

Comments
 (0)