Merge pull request #2072 from iBotPeaches/issue-2058

Prevent directory traversal on asset decoding
This commit is contained in:
Connor Tumbleson 2019-07-20 11:10:31 -04:00 committed by GitHub
commit f58e043c67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -71,6 +71,18 @@ public class UnknownDirectoryTraversalTest extends BaseTest {
BrutIO.sanitizeUnknownFile(sTmpDir, "");
}
@Test(expected = TraversalUnknownFileException.class)
public void invalidBackwardPathOnWindows() throws IOException, BrutException {
String invalidPath;
if (! OSDetection.isWindows()) {
invalidPath = "../../app";
} else {
invalidPath = "..\\..\\app.exe";
}
BrutIO.sanitizeUnknownFile(sTmpDir, invalidPath);
}
@Test
public void validDirectoryFileTest() throws IOException, BrutException {
String validFilename = BrutIO.sanitizeUnknownFile(sTmpDir, "dir" + File.separator + "file");

View File

@ -81,7 +81,8 @@ public class DirUtil {
if (fileName.equals("res") && !in.containsFile(fileName)) {
return;
}
File outFile = new File(out, fileName);
String cleanedFilename = BrutIO.sanitizeUnknownFile(out, fileName);
File outFile = new File(out, cleanedFilename);
outFile.getParentFile().mkdirs();
BrutIO.copyAndClose(in.getFileInput(fileName),
new FileOutputStream(outFile));