|
29 | 29 | import org.labkey.api.security.RequiresPermission; |
30 | 30 | import org.labkey.api.security.permissions.AdminPermission; |
31 | 31 | import org.labkey.api.util.PageFlowUtil; |
32 | | -import org.labkey.api.util.Path; |
33 | | -import org.labkey.api.util.URIUtil; |
34 | 32 | import org.labkey.api.util.URLHelper; |
35 | 33 | import org.labkey.api.view.ActionURL; |
36 | 34 | import org.labkey.api.view.JspView; |
|
40 | 38 | import org.labkey.snprc_ehr.pipeline.FeeScheduleImportForm; |
41 | 39 | import org.labkey.snprc_ehr.pipeline.FeeSchedulePipelineJob; |
42 | 40 | import org.labkey.vfs.FileLike; |
43 | | -import org.labkey.vfs.FileSystemLike; |
44 | 41 | import org.springframework.validation.BindException; |
45 | 42 | import org.springframework.validation.Errors; |
46 | 43 | import org.springframework.web.servlet.ModelAndView; |
47 | 44 |
|
48 | 45 | import java.io.File; |
49 | | -import java.net.URI; |
50 | 46 | import java.text.SimpleDateFormat; |
51 | 47 | import java.util.Date; |
52 | 48 | import java.util.List; |
@@ -155,30 +151,19 @@ public ModelAndView getView(FeeScheduleImportForm form, boolean reshow, BindExce |
155 | 151 |
|
156 | 152 | private File getVerifiedFile(String filePath) |
157 | 153 | { |
158 | | - File fileToVerify = new File(filePath); |
159 | | - |
160 | 154 | PipeRoot pipeRoot = PipelineService.get().findPipelineRoot(getContainer()); |
161 | 155 | if (pipeRoot == null) |
162 | 156 | { |
163 | 157 | throw new NotFoundException("Could not find a pipeline root for '" + getContainer().getPath() + "'"); |
164 | 158 | } |
165 | 159 |
|
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)) |
170 | 162 | { |
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"); |
172 | 164 | } |
173 | 165 |
|
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; |
182 | 167 | } |
183 | 168 |
|
184 | 169 | @Override |
|
0 commit comments