Skip to content

Commit

Permalink
Introduced protections against "zip slip" attacks
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeebot[bot] authored Oct 5, 2024
1 parent 5a4b5fa commit e03c106
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.elasticsearch.plugins.cli;

import io.github.pixee.security.ZipSecurity;
import org.apache.lucene.search.spell.LevenshteinDistance;
import org.apache.lucene.util.CollectionUtil;
import org.apache.lucene.util.Constants;
Expand Down Expand Up @@ -776,7 +777,7 @@ private Path unzip(Path zip, Path pluginsDir) throws IOException, UserException
final Path target = stagingDirectory(pluginsDir);
pathsToDeleteOnShutdown.add(target);

try (ZipInputStream zipInput = new ZipInputStream(Files.newInputStream(zip))) {
try (ZipInputStream zipInput = ZipSecurity.createHardenedInputStream(Files.newInputStream(zip))) {
ZipEntry entry;
byte[] buffer = new byte[8192];
while ((entry = zipInput.getNextEntry()) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.elasticsearch.plugins;

import io.github.pixee.security.ZipSecurity;
import org.apache.logging.log4j.Level;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.elasticsearch.Build;
Expand Down Expand Up @@ -173,7 +174,7 @@ void makeJar(Path jarFile, Class<?>... classes) throws Exception {
if (codebase.toString().endsWith(".jar")) {
// copy from jar, exactly as is
out.putNextEntry(new ZipEntry(relativePath));
try (ZipInputStream in = new ZipInputStream(Files.newInputStream(codebase))) {
try (ZipInputStream in = ZipSecurity.createHardenedInputStream(Files.newInputStream(codebase))) {
ZipEntry entry = in.getNextEntry();
while (entry != null) {
if (entry.getName().equals(relativePath)) {
Expand Down

0 comments on commit e03c106

Please sign in to comment.