File tree 1 file changed +12
-2
lines changed
javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -83,11 +83,21 @@ private static void includeEmbeddedExtensionsIfFound(
83
83
File tempDirectory = null ;
84
84
while (entryEnumeration .hasMoreElements ()) {
85
85
JarEntry jarEntry = entryEnumeration .nextElement ();
86
+ String name = jarEntry .getName ();
86
87
87
- if (jarEntry . getName () .startsWith (prefix ) && !jarEntry .isDirectory ()) {
88
+ if (name .startsWith (prefix ) && !jarEntry .isDirectory ()) {
88
89
tempDirectory = ensureTempDirectoryExists (tempDirectory );
89
90
90
- File tempFile = new File (tempDirectory , jarEntry .getName ().substring (prefix .length ()));
91
+ File tempFile = new File (tempDirectory , name .substring (prefix .length ()));
92
+ // reject extensions that would be extracted outside of temp directory
93
+ // https://security.snyk.io/research/zip-slip-vulnerability
94
+ if (name .indexOf (".." ) != -1
95
+ && !tempFile
96
+ .getCanonicalFile ()
97
+ .toPath ()
98
+ .startsWith (tempDirectory .getCanonicalFile ().toPath ())) {
99
+ throw new IllegalStateException ("Invalid extension " + name );
100
+ }
91
101
if (tempFile .createNewFile ()) {
92
102
tempFile .deleteOnExit ();
93
103
extractFile (jarFile , jarEntry , tempFile );
You can’t perform that action at this time.
0 commit comments