Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SECURITY] Fix Partial Path Traversal Vulnerability #10

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
6 changes: 3 additions & 3 deletions core/src/main/java/org/jahia/services/importexport/ImportExportBaseService.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public static String updatedServerDirectoryPath(String serverDirectoryPath) thro
return null;
}
File exportPath = new File(serverDirectoryPath);
return exportPath.getCanonicalPath().startsWith(SettingsBean.getInstance().getJahiaExportsDiskPath())
return exportPath.getCanonicalFile().toPath().startsWith(SettingsBean.getInstance().getJahiaExportsDiskPath())
? exportPath.getCanonicalPath()
: new File(SettingsBean.getInstance().getJahiaExportsDiskPath(), serverDirectoryPath).getCanonicalPath();
}
Expand Down Expand Up @@ -266,7 +266,7 @@ public static boolean isDirectoryEmpty(String pathStr) throws IOException {
public static boolean isValidServerDirectory(String serverDirectory) {
try {
File serverDirectoryFile = new File(serverDirectory);
if (!serverDirectoryFile.getCanonicalPath().startsWith(EXPORT_PATH.getCanonicalPath())) {
if (!serverDirectoryFile.getCanonicalFile().toPath().startsWith(EXPORT_PATH.getCanonicalFile().toPath())) {
logger.error("User is trying to export to {} which is outside the allowed location {}",
serverDirectory, EXPORT_PATH.getCanonicalPath());
return false;
Expand Down Expand Up @@ -2023,7 +2023,7 @@ private String validateZipName(String filename) throws java.io.IOException {
String canonicalPath = new File(filename).getCanonicalPath();
String canonicalID = new File(".").getCanonicalPath();

if (canonicalPath.startsWith(canonicalID)) {
if (new File(filename).getCanonicalFile().toPath().startsWith(canonicalID)) {
Copy link
Member

@bpapez bpapez Dec 12, 2022

Choose a reason for hiding this comment

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

This case here is a false positive as it is only for verifying file names in the zip and is not really extracting the files to the current working directory.

return canonicalPath.substring(canonicalID.length() + 1);
} else {
throw new IllegalStateException("File is outside extraction target directory.");
Expand Down