Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SECURITY] Fix Partial Path Traversal Vulnerability #148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/zeroturnaround/zip/ZipUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ private static File checkDestinationFileForTraversal(File outputDir, String name
* that the outputdir + name doesn't leave the outputdir. See
* DirectoryTraversalMaliciousTest for details.
*/
if (name.indexOf("..") != -1 && !destFile.getCanonicalPath().startsWith(outputDir.getCanonicalPath())) {
if (name.indexOf("..") != -1 && !destFile.getCanonicalFile().toPath().startsWith(outputDir.getCanonicalFile().toPath())) {
throw new MaliciousZipException(outputDir, name);
}
return destFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ public static void copyDirectory(File srcDir, File destDir,

// Cater for destination being directory within the source directory (see IO-141)
List<String> exclusionList = null;
if (destDir.getCanonicalPath().startsWith(srcDir.getCanonicalPath())) {
if (destDir.getCanonicalFile().toPath().startsWith(srcDir.getCanonicalFile().toPath())) {
File[] srcFiles = filter == null ? srcDir.listFiles() : srcDir.listFiles(filter);
if (srcFiles != null && srcFiles.length > 0) {
exclusionList = new ArrayList<String>(srcFiles.length);
Expand Down Expand Up @@ -997,7 +997,7 @@ public static void moveDirectory(File srcDir, File destDir) throws IOException {
}
boolean rename = srcDir.renameTo(destDir);
if (!rename) {
if (destDir.getCanonicalPath().startsWith(srcDir.getCanonicalPath())) {
if (destDir.getCanonicalFile().toPath().startsWith(srcDir.getCanonicalFile().toPath())) {
throw new IOException("Cannot move directory: "+srcDir+" to a subdirectory of itself: "+destDir);
}
copyDirectory( srcDir, destDir );
Expand Down