diff --git a/src/android/Zip.java b/src/android/Zip.java index 4b5de862..63cedd75 100644 --- a/src/android/Zip.java +++ b/src/android/Zip.java @@ -126,6 +126,13 @@ private void unzipSync(CordovaArgs args, CallbackContext callbackContext) { dir.mkdirs(); } else { File file = new File(outputDirectory + compressedName); + String canonicalPath = file.getCanonicalPath(); + if (!canonicalPath.startsWith(outputDirectory)) { + 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());