Skip to content

Commit

Permalink
Merge pull request from GHSA-fvf5-grm7-538p
Browse files Browse the repository at this point in the history
CureKit-GHSA-fvf5-grm7-538p adding trailing separator to base dir if …
  • Loading branch information
shukiavraham authored May 15, 2022
2 parents d6ac3c3 + 77e276d commit af35e87
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
13 changes: 0 additions & 13 deletions .idea/libraries/Maven__org_owasp_encoder_encoder_1_2_3.xml

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/io/whitesource/cure/FileSecurityUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static boolean isFileOutsideDir(
@NonNull final String filePath, @NonNull final String baseDirPath) throws IOException {
File file = new File(filePath);
File baseDir = new File(baseDirPath);
return !file.getCanonicalPath().startsWith(baseDir.getCanonicalPath());
return !file.getCanonicalFile().toPath().startsWith(baseDir.getCanonicalFile().toPath());
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/io/whitesource/cure/FileSecurityUtilsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ void normalize_validInput_successfullyWithResult() {
Assertions.assertEquals(expectedResult, actualResult);
}

@Test
void isFileOutsideDirStartsWithTest() throws IOException {
String taintedInput = "/usr/foo/../foo-bar/bar";
String baseDir = "/usr/foo";
Assertions.assertTrue(FileSecurityUtils.isFileOutsideDir(taintedInput, baseDir));
}

@Test
void normalize_null_successfully() {
Assertions.assertNull(FileSecurityUtils.normalize(null));
Expand Down

0 comments on commit af35e87

Please # to comment.