Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0d243a8

Browse files
committedFeb 4, 2025·
Resolve CodeQL zip slip warning
1 parent 8c0b510 commit 0d243a8

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed
 

‎javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/AgentClassLoader.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,16 @@ 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+
// 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) {
308316
throw new IllegalStateException(
309317
"Failed to construct url for jar entry " + jarEntry.getName(), e);
310318
}

0 commit comments

Comments
 (0)
Please sign in to comment.