Skip to content

Commit 8d3153b

Browse files
committed
Fixed: Update checkContextFileBoundary method visibility and ensure it is called in DataServices to validate file paths
(cherry picked from commit 44c9055)
1 parent f56bcd7 commit 8d3153b

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ private static void checkOfbizFileAllowList(File file) throws GeneralException {
541541
/**
542542
* Checks that the given file is within the provided context root directory.
543543
*/
544-
private static void checkContextFileBoundary(File file, String contextRoot) throws GeneralException {
544+
static void checkContextFileBoundary(File file, String contextRoot) throws GeneralException {
545545
try {
546546
String canonicalAllowed = new File(contextRoot).getCanonicalPath();
547547
String canonicalFilePath = file.getCanonicalPath();
@@ -1282,10 +1282,10 @@ public static void renderFile(String dataResourceTypeId, String objectInfo, Stri
12821282
sep = "/";
12831283
}
12841284
File file = FileUtil.getFile(prefix + sep + objectInfo);
1285+
checkContextFileBoundary(file, rootDir);
12851286
if (!file.exists()) {
12861287
throw new FileNotFoundException("No file found: " + file.getAbsolutePath());
12871288
}
1288-
checkContextFileBoundary(file, rootDir);
12891289
try (InputStreamReader in = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) {
12901290
if (Debug.infoOn()) {
12911291
String enc = in.getEncoding();

applications/content/src/main/java/org/apache/ofbiz/content/data/DataServices.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ public static Map<String, Object> createFileMethod(DispatchContext dctx, Map<Str
268268
sep = "/";
269269
}
270270
file = new File(prefix + sep + objectInfo);
271+
try {
272+
DataResourceWorker.checkContextFileBoundary(file, prefix);
273+
} catch (GeneralException e) {
274+
return ServiceUtil.returnError(e.getMessage());
275+
}
271276
}
272277
if (file == null) {
273278
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "ContentUnableObtainReferenceToFile",
@@ -478,6 +483,11 @@ public static Map<String, Object> updateFileMethod(DispatchContext dctx, Map<Str
478483
sep = "/";
479484
}
480485
file = new File(prefix + sep + objectInfo);
486+
try {
487+
DataResourceWorker.checkContextFileBoundary(file, prefix);
488+
} catch (GeneralException e) {
489+
return ServiceUtil.returnError(e.getMessage());
490+
}
481491
}
482492
if (file == null) {
483493
throw new IOException("File is null");

0 commit comments

Comments
 (0)