Skip to content

Commit

Permalink
Merge pull request #1085 from soot-oss/fix/ZipSlipVulnerabilityInPath…
Browse files Browse the repository at this point in the history
…basedInputLocation

fix zipslip against pathtraversal write in WarFileInputLocation
  • Loading branch information
swissiety authored Sep 25, 2024
2 parents 62401b4 + 796f282 commit 2d7ee55
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,20 @@ void extractWarFile(Path warFilePath, final Path destDirectory) {
Path filepath = destDirectory.resolve(zipEntry.getName());
final File file = filepath.toFile();

String canonicalPathStr = file.getCanonicalPath();
if (!canonicalPathStr.startsWith(destDirectory + File.separator)) {
throw new IllegalArgumentException(
"ZipSlip Attack Mitigated: ZipEntry points outside of the target dir: "
+ file.getName());
}

file.deleteOnExit();
if (zipEntry.isDirectory()) {
file.mkdir();
boolean mkdir = file.mkdir();
if (!mkdir) {
throw new IllegalStateException(
"Could not create Directory: " + file.getAbsolutePath());
}
} else {
byte[] incomingValues = new byte[4096];
int readBytesZip;
Expand Down

0 comments on commit 2d7ee55

Please sign in to comment.