Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ private static void checkOfbizFileAllowList(File file) throws GeneralException {
/**
* Checks that the given file is within the provided context root directory.
*/
private static void checkContextFileBoundary(File file, String contextRoot) throws GeneralException {
static void checkContextFileBoundary(File file, String contextRoot) throws GeneralException {
try {
String canonicalAllowed = new File(contextRoot).getCanonicalPath();
String canonicalFilePath = file.getCanonicalPath();
Expand Down Expand Up @@ -718,10 +718,10 @@ public static File getContentFile(String dataResourceTypeId, String objectInfo,
sep = "/";
}
file = FileUtil.getFile(contextRoot + sep + objectInfo);
checkContextFileBoundary(file, contextRoot);
if (!file.exists()) {
throw new FileNotFoundException("No file found: " + (contextRoot + sep + objectInfo));
}
checkContextFileBoundary(file, contextRoot);
}

return file;
Expand Down Expand Up @@ -1285,10 +1285,10 @@ public static void renderFile(String dataResourceTypeId, String objectInfo, Stri
sep = "/";
}
File file = FileUtil.getFile(prefix + sep + objectInfo);
checkContextFileBoundary(file, rootDir);
if (!file.exists()) {
throw new FileNotFoundException("No file found: " + file.getAbsolutePath());
}
checkContextFileBoundary(file, rootDir);
try (InputStreamReader in = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) {
if (Debug.infoOn()) {
String enc = in.getEncoding();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ public static Map<String, Object> createFileMethod(DispatchContext dctx, Map<Str
sep = "/";
}
file = new File(prefix + sep + objectInfo);
try {
DataResourceWorker.checkContextFileBoundary(file, prefix);
} catch (GeneralException e) {
return ServiceUtil.returnError(e.getMessage());
}
}
if (file == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "ContentUnableObtainReferenceToFile",
Expand Down Expand Up @@ -478,6 +483,11 @@ public static Map<String, Object> updateFileMethod(DispatchContext dctx, Map<Str
sep = "/";
}
file = new File(prefix + sep + objectInfo);
try {
DataResourceWorker.checkContextFileBoundary(file, prefix);
} catch (GeneralException e) {
return ServiceUtil.returnError(e.getMessage());
}
}
if (file == null) {
throw new IOException("File is null");
Expand Down
Loading