File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling Expand file tree Collapse file tree 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(
8383 File tempDirectory = null ;
8484 while (entryEnumeration .hasMoreElements ()) {
8585 JarEntry jarEntry = entryEnumeration .nextElement ();
86+ String name = jarEntry .getName ();
8687
87- if (jarEntry . getName () .startsWith (prefix ) && !jarEntry .isDirectory ()) {
88+ if (name .startsWith (prefix ) && !jarEntry .isDirectory ()) {
8889 tempDirectory = ensureTempDirectoryExists (tempDirectory );
8990
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+ }
91101 if (tempFile .createNewFile ()) {
92102 tempFile .deleteOnExit ();
93103 extractFile (jarFile , jarEntry , tempFile );
You can’t perform that action at this time.
0 commit comments