Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/org/jetbrains/java/decompiler/struct/StructContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ private void addArchive(String path, File file, int type, boolean isOwn) throws
}

String name = entry.getName();
File test = new File(file.getAbsolutePath(), name);
if (!test.getCanonicalPath().startsWith(file.getCanonicalPath() + File.separator)) { // check for zip slip exploit
String normalizedName = name.replace('\\', '/');
if (normalizedName.startsWith("/") || normalizedName.startsWith("../") || normalizedName.contains("/../")) {
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The zip-slip protection is incomplete. It doesn't handle cases where a path ends with .. (e.g., foo/..) or contains multiple consecutive slashes that could be normalized away. Consider using a more robust path normalization approach or additional checks for these edge cases.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check should also reject paths that start with .. without a slash (e.g., ..foo), as startsWith(\"../\") only catches cases with a trailing slash. Consider changing to startsWith(\"..\") to catch all cases where the path begins with two dots.

Suggested change
if (normalizedName.startsWith("/") || normalizedName.startsWith("../") || normalizedName.contains("/../")) {
if (normalizedName.startsWith("/") || normalizedName.startsWith("..") || normalizedName.contains("/../")) {

Copilot uses AI. Check for mistakes.
throw new RuntimeException("Zip entry '" + entry.getName() + "' tries to escape target directory");
}

Expand Down