Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SECURITY] Fix Zip Slip Vulnerability #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/utils/FileManagementUtil.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ public static void unzip(File archiveFile,File destination) throws Exception{
int count;
byte data[] = new byte[BUFFER];
File file = new File(base,entry.getName());
if (!file.toPath().normalize().startsWith(base.toPath().normalize())) {
throw new IOException("Bad zip entry");
}
if (entry.getName().endsWith("/")){
file.mkdirs();
continue;
Expand Down
3 changes: 3 additions & 0 deletions maven-car-plugin/src/main/java/org/wso2/maven/car/artifact/utils/FileManagementUtil.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ public static void unzip(File archiveFile,File destination) throws Exception{
int count;
byte data[] = new byte[BUFFER];
File file = new File(base,entry.getName());
if (!file.toPath().normalize().startsWith(base.toPath().normalize())) {
throw new IOException("Bad zip entry");
}
if (entry.getName().endsWith("/")){
file.mkdirs();
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ public void extractFromStream(InputStream inputStream, String extractDir) throws
ZipEntry entry;
while ((entry = zin.getNextEntry()) != null) {
String entryName = entry.getName();
File f = new File(extractDir + File.separator + entryName);
File f = new File(extractDir, entryName);
if (!f.toPath().normalize().startsWith(extractDir)) {
throw new IOException("Bad zip entry");
}

if (entryName.endsWith("/") && !f.exists()) { // this is a
// directory
Expand All @@ -171,7 +174,7 @@ public void extractFromStream(InputStream inputStream, String extractDir) throws
String dirPath = "";
if (lastIndexOfSlash != -1) {
dirPath = entryName.substring(0, lastIndexOfSlash);
File dir = new File(extractDir + File.separator + dirPath);
File dir = new File(extractDir, dirPath);
if (!dir.exists()) {
dir.mkdirs();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,10 @@ public static void extractFromStream(InputStream inputStream, String extractDir)
ZipEntry entry;
while ((entry = zin.getNextEntry()) != null) {
String entryName = entry.getName();
File f = new File(extractDir + File.separator + entryName);
File f = new File(extractDir, entryName);
if (!f.toPath().normalize().startsWith(extractDir)) {
throw new IOException("Bad zip entry");
}

if (entryName.endsWith("/") && !f.exists()) { // this is a
// directory
Expand All @@ -674,7 +677,7 @@ public static void extractFromStream(InputStream inputStream, String extractDir)
String dirPath = "";
if (lastIndexOfSlash != -1) {
dirPath = entryName.substring(0, lastIndexOfSlash);
File dir = new File(extractDir + File.separator + dirPath);
File dir = new File(extractDir, dirPath);
if (!dir.exists()) {
dir.mkdirs();
}
Expand Down