Skip to content

Commit 74da5ec

Browse files
committed
fix path traversal vulnerability issue
1 parent b3d2a5f commit 74da5ec

File tree

13 files changed

+1491
-1777
lines changed

13 files changed

+1491
-1777
lines changed

android/src/main/java/com/rnziparchive/RNZipArchiveModule.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ public void onCopyProgress(long bytesRead) {
159159
};
160160

161161
File fout = new File(destDirectory, entry.getName());
162+
String destDirCanonicalPath = (new File(destDirectory)).getCanonicalPath();
163+
String canonicalPath = fout.getCanonicalPath();
164+
if (!canonicalPath.startsWith(destDirCanonicalPath)) {
165+
throw new Exception(String.format("Found Zip Path Traversal Vulnerability with %s", canonicalPath));
166+
}
167+
162168
if (!fout.exists()) {
163169
//noinspection ResultOfMethodCallIgnored
164170
(new File(fout.getParent())).mkdirs();
@@ -245,6 +251,13 @@ public void run() {
245251
while ((entry = zipIn.getNextEntry()) != null) {
246252
if (entry.isDirectory()) continue;
247253
fout = new File(destDirectory, entry.getName());
254+
255+
String destDirCanonicalPath = (new File(destDirectory)).getCanonicalPath();
256+
String canonicalPath = fout.getCanonicalPath();
257+
if (!canonicalPath.startsWith(destDirCanonicalPath)) {
258+
throw new Exception(String.format("Found Zip Path Traversal Vulnerability with %s", canonicalPath));
259+
}
260+
248261
if (!fout.exists()) {
249262
//noinspection ResultOfMethodCallIgnored
250263
(new File(fout.getParent())).mkdirs();

example/App.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,13 @@ import {
1010
StyleSheet,
1111
View
1212
} from 'react-native'
13-
import App from './App'
1413
import UnzipApp from './UnzipApp'
1514

16-
export default class example extends Component {
17-
constructor () {
18-
super()
19-
this.state = {
20-
unzipWithPassword: true
21-
}
22-
}
23-
15+
export default class Example extends Component {
2416
render () {
2517
return (
2618
<View style={styles.container}>
27-
{this.state.unzipWithPassword ? (<UnzipApp />) : (<App />)}
19+
<UnzipApp />
2820
</View>
2921
)
3022
}
@@ -37,4 +29,4 @@ const styles = StyleSheet.create({
3729
}
3830
})
3931

40-
AppRegistry.registerComponent('example', () => example)
32+
AppRegistry.registerComponent('example', () => Example)

example/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ android {
137137
}
138138

139139
dependencies {
140+
implementation project(':react-native-custom-tabs')
140141
implementation project(':react-native-zip-archive')
141142
implementation project(':react-native-fs')
142143
implementation project(':react-native-document-picker')
143-
implementation project(':react-native-custom-tabs')
144144
implementation fileTree(dir: "libs", include: ["*.jar"])
145145
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
146146
implementation "com.facebook.react:react-native:+" // From node_modules

example/android/app/src/main/java/com/example/MainApplication.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import android.app.Application;
44

55
import com.facebook.react.ReactApplication;
6+
import com.github.droibit.android.reactnative.customtabs.CustomTabsPackage;
67
import com.rnziparchive.RNZipArchivePackage;
78
import com.rnfs.RNFSPackage;
89
import com.reactnativedocumentpicker.ReactNativeDocumentPicker;
9-
import com.github.droibit.android.reactnative.customtabs.CustomTabsPackage;
1010
import com.facebook.react.ReactNativeHost;
1111
import com.facebook.react.ReactPackage;
1212
import com.facebook.react.shell.MainReactPackage;
@@ -27,10 +27,10 @@ public boolean getUseDeveloperSupport() {
2727
protected List<ReactPackage> getPackages() {
2828
return Arrays.<ReactPackage>asList(
2929
new MainReactPackage(),
30+
new CustomTabsPackage(),
3031
new RNZipArchivePackage(),
3132
new RNFSPackage(),
32-
new ReactNativeDocumentPicker(),
33-
new CustomTabsPackage()
33+
new ReactNativeDocumentPicker()
3434
);
3535
}
3636

example/android/build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ buildscript {
1313
jcenter()
1414
}
1515
dependencies {
16-
classpath 'com.android.tools.build:gradle:3.2.1'
16+
classpath 'com.android.tools.build:gradle:3.4.1'
1717

1818
// NOTE: Do not place your application dependencies here; they belong
1919
// in the individual module build.gradle files
@@ -35,8 +35,7 @@ allprojects {
3535
}
3636
}
3737

38-
39-
task wrapper(type: Wrapper) {
40-
gradleVersion = '4.7'
38+
wrapper {
39+
gradleVersion = '5.1.1'
4140
distributionUrl = distributionUrl.replace("bin", "all")
4241
}
861 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
34
zipStoreBase=GRADLE_USER_HOME
45
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip

example/android/gradlew

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ APP_NAME="Gradle"
2828
APP_BASE_NAME=`basename "$0"`
2929

3030
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31-
DEFAULT_JVM_OPTS=""
31+
DEFAULT_JVM_OPTS='"-Xmx64m"'
3232

3333
# Use the maximum available, or set MAX_FD != -1 to use that value.
3434
MAX_FD="maximum"

example/android/gradlew.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ set APP_BASE_NAME=%~n0
1414
set APP_HOME=%DIRNAME%
1515

1616
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17-
set DEFAULT_JVM_OPTS=
17+
set DEFAULT_JVM_OPTS="-Xmx64m"
1818

1919
@rem Find java.exe
2020
if defined JAVA_HOME goto findJavaFromJavaHome

example/android/settings.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
rootProject.name = 'example'
2+
include ':react-native-custom-tabs'
3+
project(':react-native-custom-tabs').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-custom-tabs/android')
24
include ':react-native-zip-archive'
35
project(':react-native-zip-archive').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-zip-archive/android')
46
include ':react-native-fs'
57
project(':react-native-fs').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fs/android')
68
include ':react-native-document-picker'
79
project(':react-native-document-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-document-picker/android')
8-
include ':react-native-custom-tabs'
9-
project(':react-native-custom-tabs').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-custom-tabs/android')
1010

1111
include ':app'

0 commit comments

Comments
 (0)