Skip to content

Commit fad70bd

Browse files
yihanzhenpongad
authored andcommitted
Fix zipslip vulnerability (#3366)
Thanks to The Snyk security team for bringing this up to our attention.
1 parent ccfdd61 commit fad70bd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

google-cloud-clients/google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,13 @@ private Path downloadEmulator() throws IOException {
404404
log.fine("Unzipping emulator");
405405
}
406406
ZipEntry entry = zipIn.getNextEntry();
407-
while (entry != null) {
408-
File filePath = new File(emulatorPath.toFile(), entry.getName());
407+
while (entry != null) {
408+
File filePath = new File(emulatorFolder, entry.getName());
409+
String canonicalEmulatorFolderPath = emulatorFolder.getCanonicalPath();
410+
String canonicalFilePath = filePath.getCanonicalPath();
411+
if (!canonicalFilePath.startsWith(canonicalEmulatorFolderPath + File.separator)) {
412+
throw new IllegalStateException("Entry is outside of the target dir: " + entry.getName());
413+
}
409414
if (!entry.isDirectory()) {
410415
extractFile(zipIn, filePath);
411416
} else {

0 commit comments

Comments
 (0)