Improve Zip Slip detection
This commit is contained in:
parent
c968e94b2c
commit
1ec02658fe
1 changed files with 6 additions and 1 deletions
|
@ -44,6 +44,11 @@ public final class ZipUtils {
|
||||||
* @throws IOException Signals that an I/O exception has occurred.
|
* @throws IOException Signals that an I/O exception has occurred.
|
||||||
*/
|
*/
|
||||||
public static void unzipFilesToPath(String jarPath, String destinationDir) throws IOException {
|
public static void unzipFilesToPath(String jarPath, String destinationDir) throws IOException {
|
||||||
|
String canonicalDestDir = new File(destinationDir).getCanonicalPath();
|
||||||
|
if (!canonicalDestDir.endsWith(File.separator)) {
|
||||||
|
canonicalDestDir += File.separator;
|
||||||
|
}
|
||||||
|
|
||||||
File file = new File(jarPath);
|
File file = new File(jarPath);
|
||||||
try (JarFile jar = new JarFile(file)) {
|
try (JarFile jar = new JarFile(file)) {
|
||||||
|
|
||||||
|
@ -68,7 +73,7 @@ public final class ZipUtils {
|
||||||
String fileName = destinationDir + File.separator + entry.getName();
|
String fileName = destinationDir + File.separator + entry.getName();
|
||||||
File f = new File(fileName);
|
File f = new File(fileName);
|
||||||
|
|
||||||
if (!f.getCanonicalPath().startsWith(destinationDir)) {
|
if (!f.getCanonicalPath().startsWith(canonicalDestDir)) {
|
||||||
System.out.println("Zip Slip exploit detected. Skipping entry " + entry.getName());
|
System.out.println("Zip Slip exploit detected. Skipping entry " + entry.getName());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue