Skip to content

Commit

Permalink
Improve the checks for relative traversal.
Browse files Browse the repository at this point in the history
Use java.nio.file.Path for consistent sub-directory checking
  • Loading branch information
LQxdu authored Oct 17, 2024
1 parent 53c21dc commit 8002802
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/main/java/net/sf/mpxj/common/InputStreamHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ public static byte[] read(InputStream is, byte[] data, int size) throws IOExcept
*/
private static void processZipStream(File dir, InputStream inputStream) throws IOException
{
String canonicalDestinationDirPath = dir.getCanonicalPath();
ZipInputStream zip = new ZipInputStream(inputStream);
while (true)
{
Expand All @@ -187,8 +186,7 @@ private static void processZipStream(File dir, InputStream inputStream) throws I
File file = new File(dir, entry.getName());

// https://snyk.io/research/zip-slip-vulnerability
String canonicalDestinationFile = file.getCanonicalPath();
if (!canonicalDestinationFile.startsWith(canonicalDestinationDirPath + File.separator))
if (!file.getCanonicalFile().toPath().startsWith(dir.getCanonicalFile().toPath()))
{
throw new IOException("Entry is outside of the target dir: " + entry.getName());
}
Expand Down

0 comments on commit 8002802

Please sign in to comment.