Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.

Commit af35e87

Browse files
authored
Merge pull request from GHSA-fvf5-grm7-538p
CureKit-GHSA-fvf5-grm7-538p adding trailing separator to base dir if …
2 parents d6ac3c3 + 77e276d commit af35e87

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

.idea/libraries/Maven__org_owasp_encoder_encoder_1_2_3.xml

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/main/java/io/whitesource/cure/FileSecurityUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +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(baseDir.getCanonicalPath());
25+
return !file.getCanonicalFile().toPath().startsWith(baseDir.getCanonicalFile().toPath());
2626
}
2727

2828
/**

src/test/java/io/whitesource/cure/FileSecurityUtilsTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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));

0 commit comments

Comments
 (0)