This repository was archived by the owner on Sep 3, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +8
-8
lines changed
main/java/io/whitesource/cure
test/java/io/whitesource/cure Expand file tree Collapse file tree 2 files changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -22,14 +22,7 @@ public static boolean isFileOutsideDir(
2222 @ NonNull final String filePath , @ NonNull final String baseDirPath ) throws IOException {
2323 File file = new File (filePath );
2424 File baseDir = new File (baseDirPath );
25- return !file .getCanonicalPath ().startsWith (addTrailingSeparator (baseDir .getCanonicalPath ()));
26- }
27-
28- private static String addTrailingSeparator (String path ) {
29- if (!path .endsWith (File .separator )) {
30- return path + File .separator ;
31- }
32- return path ;
25+ return !file .getCanonicalFile ().toPath ().startsWith (baseDir .getCanonicalFile ().toPath ());
3326 }
3427
3528 /**
Original file line number Diff line number Diff line change @@ -50,6 +50,13 @@ void normalize_validInput_successfullyWithResult() {
5050 Assertions .assertEquals (expectedResult , actualResult );
5151 }
5252
53+ @ Test
54+ void isFileOutsideDirStartsWithTest () throws IOException {
55+ String taintedInput = "/usr/foo/../foo-bar/bar" ;
56+ String baseDir = "/usr/foo" ;
57+ Assertions .assertTrue (FileSecurityUtils .isFileOutsideDir (taintedInput , baseDir ));
58+ }
59+
5360 @ Test
5461 void normalize_null_successfully () {
5562 Assertions .assertNull (FileSecurityUtils .normalize (null ));
You can’t perform that action at this time.
0 commit comments