Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 35119d7

Browse files
author
Igor Krasavin
authored
Mitigate zipperdown (#1881)
1 parent 89f4edc commit 35119d7

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

CodePush.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Pod::Spec.new do |s|
2121
# we explicitly let CocoaPods pull in the versions below so all dependencies are resolved and
2222
# linked properly at a parent workspace level.
2323
s.dependency 'React'
24-
s.dependency 'SSZipArchive', '~> 2.1'
24+
s.dependency 'SSZipArchive', '~> 2.2.2'
2525
s.dependency 'JWT', '~> 3.0.0-beta.12'
2626
s.dependency 'Base64', '~> 1.1'
2727
end

android/app/src/main/java/com/microsoft/codepush/react/FileUtils.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@ public static String readFileToString(String filePath) throws IOException {
123123
}
124124
}
125125

126+
private static String validateFileName(String fileName, String targetDirectory) throws IOException {
127+
File file = new File(fileName);
128+
String canonicalPath = file.getCanonicalPath();
129+
130+
File targetFile = new File(targetDirectory);
131+
String targetCanonicalPath = targetFile.getCanonicalPath();
132+
133+
if (!canonicalPath.startsWith(targetCanonicalPath)) {
134+
throw new IllegalStateException("File is outside extraction target directory.");
135+
}
136+
137+
return canonicalPath;
138+
}
139+
126140
public static void unzipFile(File zipFile, String destination) throws IOException {
127141
FileInputStream fileStream = null;
128142
BufferedInputStream bufferedStream = null;
@@ -142,7 +156,7 @@ public static void unzipFile(File zipFile, String destination) throws IOExceptio
142156

143157
byte[] buffer = new byte[WRITE_BUFFER_SIZE];
144158
while ((entry = zipStream.getNextEntry()) != null) {
145-
String fileName = entry.getName();
159+
String fileName = validateFileName(entry.getName(), ".");
146160
File file = new File(destinationFolder, fileName);
147161
if (entry.isDirectory()) {
148162
file.mkdirs();

0 commit comments

Comments
 (0)