File tree 1 file changed +10
-2
lines changed
javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap
1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -303,8 +303,16 @@ private URL findJarResource(String name) {
303
303
private URL getJarEntryUrl (JarEntry jarEntry ) {
304
304
if (jarEntry != null ) {
305
305
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
+ // in order to resolve CodeQL zip slip warning
309
+ File entryFile = new File (jarBase .getPath (), entryName ).getCanonicalFile ();
310
+ File baseDir = new File (jarBase .getPath ()).getCanonicalFile ();
311
+ if (!entryFile .toPath ().startsWith (baseDir .toPath ())) {
312
+ throw new IllegalStateException ("Bad zip entry: " + entryName );
313
+ }
314
+ return new URL (jarBase , entryName );
315
+ } catch (IOException e ) {
308
316
throw new IllegalStateException (
309
317
"Failed to construct url for jar entry " + jarEntry .getName (), e );
310
318
}
You can’t perform that action at this time.
0 commit comments