diff --git a/src/android/Zip.java b/src/android/Zip.java index 4b5de862..9406dbb6 100644 --- a/src/android/Zip.java +++ b/src/android/Zip.java @@ -126,6 +126,14 @@ private void unzipSync(CordovaArgs args, CallbackContext callbackContext) { dir.mkdirs(); } else { File file = new File(outputDirectory + compressedName); + String canonicalDestinationPath = (new File(outputDirectory)).getCanonicalPath(); + String canonicalPath = file.getCanonicalPath(); + if (!canonicalPath.startsWith(canonicalDestinationPath)) { + String errorMessage = "Zip traversal security error"; + callbackContext.error(errorMessage); + Log.e(LOG_TAG, errorMessage); + return; + } file.getParentFile().mkdirs(); if(file.exists() || file.createNewFile()){ Log.w("Zip", "extracting: " + file.getPath());