Skip to content

Commit

Permalink
Applied path traversal patch
Browse files Browse the repository at this point in the history
Mirrored from MobileChromeApps#94 which itself was based on couple of other people's changes in relation to this issue
  • Loading branch information
gregbgithub authored Apr 26, 2023
1 parent 977b57d commit 92e525b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/android/Zip.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ private void unzipSync(CordovaArgs args, CallbackContext callbackContext) {
dir.mkdirs();
} else {
File file = new File(outputDirectory + compressedName);

String canonicalPath = file.getCanonicalPath();
String absolutePath = file.getAbsolutePath();
if (!canonicalPath.startsWith(outputDirectory) && !absolutePath.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());
Expand Down

0 comments on commit 92e525b

Please sign in to comment.