Skip to content

Commit 18c4f71

Browse files
laurentschoelensmattrpav
authored andcommitted
[#514] fix path validation of jar entry files
1 parent c2e4fe0 commit 18c4f71

File tree

1 file changed

+5
-3
lines changed
  • maven-plugin/plugin-core/src/main/java/org/jvnet/jaxb/maven/util

1 file changed

+5
-3
lines changed

maven-plugin/plugin-core/src/main/java/org/jvnet/jaxb/maven/util/JarScanner.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
public class JarScanner extends AbstractScanner {
1717
private static final String[] EMPTY_STRING_ARRAY = new String[0];
1818

19+
private File destinationDir = new File("/tmp");
20+
1921
/**
2022
* The jar artifact to be scanned.
2123
*/
@@ -52,9 +54,9 @@ public void scan() {
5254
while (jarFileEntries.hasMoreElements()) {
5355
JarEntry entry = jarFileEntries.nextElement();
5456
String name = entry.getName();
55-
if (name.startsWith("..") || name.startsWith("/")) {
56-
// ignore "zip slip" file pattern attack
57-
continue;
57+
File file = new File(destinationDir, entry.getName());
58+
if (!file.toPath().normalize().startsWith(destinationDir.toPath())) {
59+
throw new IOException("Bad zip entry for " + entry.getName());
5860
}
5961
char[][] tokenizedName = tokenizePathToCharArray(name, File.separator);
6062
if (name.endsWith("/")) {

0 commit comments

Comments
 (0)