Skip to content

Commit 167c91c

Browse files
Verify fee schedule file with PipeRoot.isUnderRoot (#1031)
1 parent 94276a5 commit 167c91c

1 file changed

Lines changed: 4 additions & 19 deletions

File tree

‎snprc_ehr/src/org/labkey/snprc_ehr/controllers/FeeScheduleController.java‎

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
import org.labkey.api.security.RequiresPermission;
3030
import org.labkey.api.security.permissions.AdminPermission;
3131
import org.labkey.api.util.PageFlowUtil;
32-
import org.labkey.api.util.Path;
33-
import org.labkey.api.util.URIUtil;
3432
import org.labkey.api.util.URLHelper;
3533
import org.labkey.api.view.ActionURL;
3634
import org.labkey.api.view.JspView;
@@ -40,13 +38,11 @@
4038
import org.labkey.snprc_ehr.pipeline.FeeScheduleImportForm;
4139
import org.labkey.snprc_ehr.pipeline.FeeSchedulePipelineJob;
4240
import org.labkey.vfs.FileLike;
43-
import org.labkey.vfs.FileSystemLike;
4441
import org.springframework.validation.BindException;
4542
import org.springframework.validation.Errors;
4643
import org.springframework.web.servlet.ModelAndView;
4744

4845
import java.io.File;
49-
import java.net.URI;
5046
import java.text.SimpleDateFormat;
5147
import java.util.Date;
5248
import java.util.List;
@@ -155,30 +151,19 @@ public ModelAndView getView(FeeScheduleImportForm form, boolean reshow, BindExce
155151

156152
private File getVerifiedFile(String filePath)
157153
{
158-
File fileToVerify = new File(filePath);
159-
160154
PipeRoot pipeRoot = PipelineService.get().findPipelineRoot(getContainer());
161155
if (pipeRoot == null)
162156
{
163157
throw new NotFoundException("Could not find a pipeline root for '" + getContainer().getPath() + "'");
164158
}
165159

166-
FileLike allowedRoot = pipeRoot.getRootFileLike();
167-
URI relativeURI = URIUtil.relativize(allowedRoot.toURI(), fileToVerify.toURI()); // if root = /a/b/c/ and file = /a/b/c/d/e/f.xlsx, relativeURI = d/e/f.xlsx
168-
169-
if (relativeURI == null)
160+
File file = new File(filePath).toPath().normalize().toFile();
161+
if (!pipeRoot.isUnderRoot(file))
170162
{
171-
throw new IllegalArgumentException("File '" + fileToVerify.toURI().getPath() + "' is outside the allowed root '" + allowedRoot.toURI().getPath() + "'");
163+
throw new NotFoundException("File '" + filePath + "' is outside the pipeline root");
172164
}
173165

174-
if (allowedRoot.isDescendant(fileToVerify.toURI())) // if root = /a/b/c/ and file = /a/b/c/d/e/f.xlsx - among other things, this essentially checks if '/a/b/c/d/e/f.xlsx' starts with '/a/b/c/'
175-
{
176-
return FileSystemLike.toFile(allowedRoot.resolveFile(new Path(relativeURI.getPath())));
177-
}
178-
else
179-
{
180-
throw new IllegalArgumentException("File '" + relativeURI.getPath() + "' is not a descendent of '" + allowedRoot.toURI().getPath() + "'");
181-
}
166+
return file;
182167
}
183168

184169
@Override

0 commit comments

Comments
 (0)