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 #219

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private File createFile(JarEntry jarEntry, InputStream is) throws EeClassLoaderE
File tmpFile = null;
try {
if (jarEntry.isDirectory()) {
tmpFile = new File(tempDir + File.separator + jarEntry);
tmpFile = new File(tempDir, jarEntry);
tmpFile.mkdirs();
tmpFile.deleteOnExit();
chmod777(tmpFile);
Expand All @@ -184,13 +184,17 @@ private File createFile(JarEntry jarEntry, InputStream is) throws EeClassLoaderE
int lastPathIndex = jarEntry.getName().lastIndexOf("/");
if (lastPathIndex > -1) {
String dirPath = jarEntry.getName().substring(0, lastPathIndex);
tempDir = new File(tempDir.getPath() + File.separator + dirPath);
tempDir = new File(tempDir.getPath(), dirPath);
tempDir.mkdirs();
tempDir.deleteOnExit();
chmod777(tempDir);
fileName = fileName.substring(lastPathIndex + 1);
}
tmpFile = new File(tempDir + File.separator + fileName);
final File zipEntryFile = new File(tempDir, fileName);
if (!zipEntryFile.toPath().normalize().startsWith(tempDir.toPath().normalize())) {
throw new IOException("Bad zip entry");
}
tmpFile = zipEntryFile;
tmpFile.deleteOnExit();
chmod777(tmpFile); // Unix - allow temp file deletion by any user
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(tmpFile));
Expand Down