Skip to content

Commit

Permalink
FELIX-6189 - Make sure jar/zip files are jailed to the destination di…
Browse files Browse the repository at this point in the history
…rectory
  • Loading branch information
coheigea committed Apr 14, 2020
1 parent 84b88a5 commit d54e684
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public static void unjar(JarInputStream jis, File dir)
}

File target = new File(dir, je.getName());
if (!target.getCanonicalPath().startsWith(dir.getCanonicalPath())) {
throw new IOException("The output file is not contained in the destination directory");
}

// Check to see if the JAR entry is a directory.
if (je.isDirectory())
Expand Down Expand Up @@ -219,4 +222,4 @@ public static InputStream openURL(final URLConnection conn) throws IOException
throw newException;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,9 @@ public static void unjar(JarInputStream jis, File dir)
}

File target = new File(dir, je.getName());
if (!target.getCanonicalPath().startsWith(dir.getCanonicalPath())) {
throw new IOException("The output file is not contained in the destination directory");
}

// Check to see if the JAR entry is a directory.
if (je.isDirectory())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ protected static void restore(File archiveFile, File targetDir) throws IOExcepti
ZipEntry entry;
while ((entry = input.getNextEntry()) != null) {
File targetEntry = new File(targetDir, entry.getName());
if (!targetEntry.getCanonicalPath().startsWith(targetDir.getCanonicalPath())) {
throw new IOException("The output file is not contained in the destination directory");
}

if (entry.isDirectory()) {
if (!targetEntry.mkdirs()) {
Expand Down Expand Up @@ -223,4 +226,4 @@ protected void onFailure(Exception e) {
m_session.getLog().log(LogService.LOG_WARNING, "Failed to restore snapshot!", e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ public static void unjar(JarInputStream jis, File dir)
}

File target = new File(dir, je.getName());
if (!target.getCanonicalPath().startsWith(dir.getCanonicalPath())) {
throw new IOException("The output file is not contained in the destination directory");
}

// Check to see if the JAR entry is a directory.
if (je.isDirectory())
Expand Down

0 comments on commit d54e684

Please sign in to comment.