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 Mar 3, 2020
1 parent 990e9d4 commit a21b7bb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bundlerepository/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>org.apache.felix.utils</artifactId>
<version>1.11.0-SNAPSHOT</version>
<version>1.11.4</version>
<optional>true</optional>
</dependency>
<dependency>
Expand Down
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 a21b7bb

Please sign in to comment.