Skip to content

Commit 3965d65

Browse files
committed
Fixed: Prevent arbitrary file read/write in entityImport and entityExportAll
Paths in both methods are now guarded by SecurityUtil.checkOfbizFileAllowList(), which restricts paths to the directories configured in content.data.ofbiz.file.allowed.paths (security.properties). (cherry picked from commit 15c1956)
1 parent fee4d08 commit 3965d65

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

framework/webtools/src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import org.apache.ofbiz.entity.util.EntityUtilProperties;
8888
import org.apache.ofbiz.entityext.EntityGroupUtil;
8989
import org.apache.ofbiz.security.Security;
90+
import org.apache.ofbiz.security.SecurityUtil;
9091
import org.apache.ofbiz.service.DispatchContext;
9192
import org.apache.ofbiz.service.GenericServiceException;
9293
import org.apache.ofbiz.service.LocalDispatcher;
@@ -159,6 +160,11 @@ public static Map<String, Object> entityImport(DispatchContext dctx, Map<String,
159160
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "WebtoolsErrorReadingTemplateFile",
160161
UtilMisc.toMap("filename", fmfilename, "errorString", "Template file not found."), locale));
161162
}
163+
try {
164+
SecurityUtil.checkOfbizFileAllowList(fmFile);
165+
} catch (GeneralException e) {
166+
return ServiceUtil.returnError(e.getMessage());
167+
}
162168
try {
163169
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
164170
factory.setValidating(true);
@@ -515,6 +521,11 @@ public static Map<String, Object> entityExportAll(DispatchContext dctx, Map<Stri
515521

516522
if (UtilValidate.isNotEmpty(outpath)) {
517523
File outdir = new File(outpath);
524+
try {
525+
SecurityUtil.checkOfbizFileAllowList(outdir);
526+
} catch (GeneralException e) {
527+
return ServiceUtil.returnError(e.getMessage());
528+
}
518529
if (!outdir.exists()) {
519530
outdir.mkdir();
520531
}

0 commit comments

Comments
 (0)