Skip to content

Commit 68725df

Browse files
committed
Fix zip traversal vulnerability
Following this proposal solution MobileChromeApps#92 (comment)
1 parent 977b57d commit 68725df

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/android/Zip.java

+8
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ private void unzipSync(CordovaArgs args, CallbackContext callbackContext) {
126126
dir.mkdirs();
127127
} else {
128128
File file = new File(outputDirectory + compressedName);
129+
String canonicalDestinationPath = (new File(outputDirectory)).getCanonicalPath();
130+
String canonicalPath = file.getCanonicalPath();
131+
if (!canonicalPath.startsWith(canonicalDestinationPath)) {
132+
String errorMessage = "Zip traversal security error";
133+
callbackContext.error(errorMessage);
134+
Log.e(LOG_TAG, errorMessage);
135+
return;
136+
}
129137
file.getParentFile().mkdirs();
130138
if(file.exists() || file.createNewFile()){
131139
Log.w("Zip", "extracting: " + file.getPath());

0 commit comments

Comments
 (0)