Skip to content

Commit

Permalink
[highsource#514] fix path validation of jar entry files
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentschoelens committed Apr 1, 2024
1 parent d4a51e5 commit 6bdcbb7
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
public class JarScanner extends AbstractScanner {
private static final String[] EMPTY_STRING_ARRAY = new String[0];

private File destinationDir = new File("/tmp");

/**
* The jar artifact to be scanned.
*/
Expand Down Expand Up @@ -52,9 +54,9 @@ public void scan() {
while (jarFileEntries.hasMoreElements()) {
JarEntry entry = jarFileEntries.nextElement();
String name = entry.getName();
if (name.startsWith("..") || name.startsWith("/")) {
// ignore "zip slip" file pattern attack
continue;
File file = new File(destinationDir, entry.getName());
if (!file.toPath().normalize().startsWith(destinationDir.toPath())) {
throw new IOException("Bad zip entry for " + entry.getName());
}
char[][] tokenizedName = tokenizePathToCharArray(name, File.separator);
if (name.endsWith("/")) {
Expand Down

0 comments on commit 6bdcbb7

Please sign in to comment.