Skip to content

Commit

Permalink
Fixed security issue detected by CodeQL ("Zip Slip")
Browse files Browse the repository at this point in the history
  • Loading branch information
salmonb committed Oct 8, 2023
1 parent c1495e2 commit b18e700
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/main/java/dev/webfx/cli/commands/Install.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ private static void uncompressTarGz(Path archivePath, Path destinationFolder) {
while ((tarEntry = tis.getNextTarEntry()) != null) {
if (tarEntry.isFile()) {
Path outputPath = destinationFolder.resolve(tarEntry.getName());
// Fixing security issue detected by CodeQL: Arbitrary file access during archive extraction ("Zip Slip")
// => Checking the file will not be outside the destination folder
if (!outputPath.normalize().startsWith(destinationFolder))
throw new RuntimeException("Bad zip entry");
File outputFile = outputPath.toFile();
outputFile.getParentFile().mkdirs();
if (tarEntry.isSymbolicLink())
Expand All @@ -372,6 +376,8 @@ private static void uncompressTarGz(Path archivePath, Path destinationFolder) {
}
}
} catch (Exception e) {
if (e instanceof RuntimeException)
throw (RuntimeException) e;
throw new RuntimeException(e);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/dev/webfx/cli/version/dev/version.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=0.1.0-SNAPSHOT
build.timestamp=2023-10-08 10:25
build.timestamp=2023-10-08 10:38

0 comments on commit b18e700

Please sign in to comment.