File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -303,8 +303,15 @@ private URL findJarResource(String name) {
303303 private URL getJarEntryUrl (JarEntry jarEntry ) {
304304 if (jarEntry != null ) {
305305 try {
306- return new URL (jarBase , jarEntry .getName ());
307- } catch (MalformedURLException e ) {
306+ String entryName = jarEntry .getName ();
307+ // normalize the path and check for directory traversal
308+ File entryFile = new File (jarBase .getPath (), entryName ).getCanonicalFile ();
309+ File baseDir = new File (jarBase .getPath ()).getCanonicalFile ();
310+ if (!entryFile .toPath ().startsWith (baseDir .toPath ())) {
311+ throw new IllegalStateException ("Bad zip entry: " + entryName );
312+ }
313+ return new URL (jarBase , entryName );
314+ } catch (IOException e ) {
308315 throw new IllegalStateException (
309316 "Failed to construct url for jar entry " + jarEntry .getName (), e );
310317 }
You can’t perform that action at this time.
0 commit comments