You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2026/04/08 11:02:31 UTC
(ofbiz-framework) branch trunk updated (5c627e288b -> 81f802f729)
This is an automated email from the ASF dual-hosted git repository.
jacopoc pushed a change to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
from 5c627e288b Fixed: Enhance string escaping in MacroScreenRenderer
new 05fbeb5c2c Improved: Move file path validation to SecurityUtil
new d06b61393f Fixed: Implement file path validation using SecurityUtil in CoreEvents to enhance security
new 93b08e85d3 Fixed: Integrate SecurityUtil to validate file paths in CommonEvents for enhanced security
new 95b4898a16 Fixed: Remove legacy HttpEngine (disabled 5 years ago for security reasons)
new da00c04638 Fixed: Cast parse result to int in EntityDataLoader
new 81f802f729 Fixed: Cast parse result to int in EntityXmlAssertTest
The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../ofbiz/content/data/DataResourceWorker.java | 79 +-------
.../java/org/apache/ofbiz/common/CommonEvents.java | 5 +-
.../apache/ofbiz/entity/util/EntityDataLoader.java | 2 +-
.../org/apache/ofbiz/security/SecurityUtil.java | 74 ++++++++
framework/service/config/serviceengine.xml | 1 -
.../apache/ofbiz/service/engine/HttpEngine.java | 210 ---------------------
.../ofbiz/testtools/EntityXmlAssertTest.java | 2 +-
.../org/apache/ofbiz/webapp/event/CoreEvents.java | 8 +
.../webapp/webtools/WEB-INF/controller.xml | 8 +-
9 files changed, 95 insertions(+), 294 deletions(-)
delete mode 100644 framework/service/src/main/java/org/apache/ofbiz/service/engine/HttpEngine.java
(ofbiz-framework) 01/06: Improved: Move file path validation to SecurityUtil
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jacopoc pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
commit 05fbeb5c2c4991550d9d99207531308796befeef
Author: Jacopo Cappellato <ja...@gmail.com>
AuthorDate: Wed Apr 8 10:48:18 2026 +0200
Improved: Move file path validation to SecurityUtil
---
.../ofbiz/content/data/DataResourceWorker.java | 79 ++--------------------
.../org/apache/ofbiz/security/SecurityUtil.java | 74 ++++++++++++++++++++
2 files changed, 79 insertions(+), 74 deletions(-)
diff --git a/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java b/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java
index 4035c8d248..9fd6b799b5 100644
--- a/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java
+++ b/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java
@@ -86,6 +86,7 @@ import org.apache.ofbiz.entity.util.EntityQuery;
import org.apache.ofbiz.entity.util.EntityUtilProperties;
import org.apache.ofbiz.service.GenericServiceException;
import org.apache.ofbiz.service.LocalDispatcher;
+import org.apache.ofbiz.security.SecurityUtil;
import org.apache.ofbiz.service.ServiceUtil;
import org.apache.ofbiz.widget.model.FormFactory;
import org.apache.ofbiz.widget.model.ModelForm;
@@ -471,76 +472,6 @@ public class DataResourceWorker implements org.apache.ofbiz.widget.content.DataR
return prefix;
}
- /**
- * Checks that the given file is within one of the directories listed in
- * {@code content.data.local.file.allowed.paths} (security.properties).
- * Use {@code ${ofbiz.home}} as a portable placeholder for the OFBiz home directory.
- */
- private static void checkLocalFileAllowList(File file) throws GeneralException {
- try {
- String canonicalFilePath = file.getCanonicalPath();
- String ofbizHome = System.getProperty("ofbiz.home");
- String allowedPathsStr = UtilProperties.getPropertyValue("security",
- "content.data.local.file.allowed.paths", "${ofbiz.home}");
- if (UtilValidate.isNotEmpty(allowedPathsStr)) {
- boolean inAllowedPath = false;
- for (String allowedPath : allowedPathsStr.split(",")) {
- allowedPath = allowedPath.trim().replace("${ofbiz.home}", ofbizHome);
- if (UtilValidate.isEmpty(allowedPath)) {
- continue;
- }
- String canonicalAllowedDir = new File(allowedPath).getCanonicalPath();
- if (canonicalFilePath.startsWith(canonicalAllowedDir + File.separator)
- || canonicalFilePath.equals(canonicalAllowedDir)) {
- inAllowedPath = true;
- break;
- }
- }
- if (!inAllowedPath) {
- throw new GeneralException("Access to file denied: path is not within an allowed directory");
- }
- }
- } catch (IOException e) {
- throw new GeneralException("Unable to validate file path: " + e.getMessage());
- }
- }
-
- /**
- * Checks that the given file is within the OFBiz home directory and within one of the
- * subdirectories listed in {@code content.data.ofbiz.file.allowed.paths} (security.properties).
- */
- private static void checkOfbizFileAllowList(File file) throws GeneralException {
- try {
- String canonicalHome = new File(System.getProperty("ofbiz.home")).getCanonicalPath();
- String canonicalFilePath = file.getCanonicalPath();
- if (!canonicalFilePath.startsWith(canonicalHome + File.separator)) {
- throw new GeneralException("Access to file denied: path resolves outside of the OFBiz home directory");
- }
- String allowedPathsStr = UtilProperties.getPropertyValue("security",
- "content.data.ofbiz.file.allowed.paths", "applications/,themes/,plugins/,runtime/");
- if (UtilValidate.isNotEmpty(allowedPathsStr)) {
- boolean inAllowedPath = false;
- for (String relPath : allowedPathsStr.split(",")) {
- relPath = relPath.trim().replaceAll("^/+", "");
- if (UtilValidate.isEmpty(relPath)) {
- continue;
- }
- String canonicalAllowedDir = new File(canonicalHome, relPath).getCanonicalPath();
- if (canonicalFilePath.startsWith(canonicalAllowedDir + File.separator)
- || canonicalFilePath.equals(canonicalAllowedDir)) {
- inAllowedPath = true;
- break;
- }
- }
- if (!inAllowedPath) {
- throw new GeneralException("Access to file denied: path is not within an allowed directory");
- }
- }
- } catch (IOException e) {
- throw new GeneralException("Unable to validate file path: " + e.getMessage());
- }
- }
-
/**
* Checks that the given file is within the provided context root directory.
*/
@@ -695,7 +626,7 @@ public class DataResourceWorker implements org.apache.ofbiz.widget.content.DataR
if (!file.isAbsolute()) {
throw new GeneralException("File (" + objectInfo + ") is not absolute");
}
- checkLocalFileAllowList(file);
+ SecurityUtil.checkLocalFileAllowList(file);
} else if ("OFBIZ_FILE".equals(dataResourceTypeId) || "OFBIZ_FILE_BIN".equals(dataResourceTypeId)) {
String prefix = System.getProperty("ofbiz.home");
@@ -707,7 +638,7 @@ public class DataResourceWorker implements org.apache.ofbiz.widget.content.DataR
if (!file.exists()) {
throw new FileNotFoundException("No file found: " + (prefix + sep + objectInfo));
}
- checkOfbizFileAllowList(file);
+ SecurityUtil.checkOfbizFileAllowList(file);
} else if ("CONTEXT_FILE".equals(dataResourceTypeId) || "CONTEXT_FILE_BIN".equals(dataResourceTypeId)) {
if (UtilValidate.isEmpty(contextRoot)) {
throw new GeneralException("Cannot find CONTEXT_FILE with an empty context root!");
@@ -1260,7 +1191,7 @@ public class DataResourceWorker implements org.apache.ofbiz.widget.content.DataR
if (!file.exists()) {
throw new FileNotFoundException("No file found: " + file.getAbsolutePath());
}
- checkLocalFileAllowList(file);
+ SecurityUtil.checkLocalFileAllowList(file);
try (InputStreamReader in = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) {
UtilIO.copy(in, out);
}
@@ -1274,7 +1205,7 @@ public class DataResourceWorker implements org.apache.ofbiz.widget.content.DataR
if (!file.exists()) {
throw new FileNotFoundException("No file found: " + file.getAbsolutePath());
}
- checkOfbizFileAllowList(file);
+ SecurityUtil.checkOfbizFileAllowList(file);
try (InputStreamReader in = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) {
UtilIO.copy(in, out);
}
diff --git a/framework/security/src/main/java/org/apache/ofbiz/security/SecurityUtil.java b/framework/security/src/main/java/org/apache/ofbiz/security/SecurityUtil.java
index 0f6adbd14f..ce61571985 100644
--- a/framework/security/src/main/java/org/apache/ofbiz/security/SecurityUtil.java
+++ b/framework/security/src/main/java/org/apache/ofbiz/security/SecurityUtil.java
@@ -19,12 +19,16 @@
package org.apache.ofbiz.security;
+import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.ofbiz.base.util.Debug;
+import org.apache.ofbiz.base.util.GeneralException;
+import org.apache.ofbiz.base.util.UtilProperties;
import org.apache.ofbiz.base.util.StringUtil;
import org.apache.ofbiz.base.util.UtilMisc;
import org.apache.ofbiz.base.util.UtilValidate;
@@ -135,6 +139,76 @@ public final class SecurityUtil {
return false;
}
+ /**
+ * Checks that the given file is within one of the directories listed in
+ * {@code content.data.local.file.allowed.paths} (security.properties).
+ * Use {@code ${ofbiz.home}} as a portable placeholder for the OFBiz home directory.
+ */
+ public static void checkLocalFileAllowList(File file) throws GeneralException {
+ try {
+ String canonicalFilePath = file.getCanonicalPath();
+ String ofbizHome = System.getProperty("ofbiz.home");
+ String allowedPathsStr = UtilProperties.getPropertyValue("security",
+ "content.data.local.file.allowed.paths", "${ofbiz.home}");
+ if (UtilValidate.isNotEmpty(allowedPathsStr)) {
+ boolean inAllowedPath = false;
+ for (String allowedPath : allowedPathsStr.split(",")) {
+ allowedPath = allowedPath.trim().replace("${ofbiz.home}", ofbizHome);
+ if (UtilValidate.isEmpty(allowedPath)) {
+ continue;
+ }
+ String canonicalAllowedDir = new File(allowedPath).getCanonicalPath();
+ if (canonicalFilePath.startsWith(canonicalAllowedDir + File.separator)
+ || canonicalFilePath.equals(canonicalAllowedDir)) {
+ inAllowedPath = true;
+ break;
+ }
+ }
+ if (!inAllowedPath) {
+ throw new GeneralException("Access to file denied: path is not within an allowed directory");
+ }
+ }
+ } catch (IOException e) {
+ throw new GeneralException("Unable to validate file path: " + e.getMessage());
+ }
+ }
+
+ /**
+ * Checks that the given file is within the OFBiz home directory and within one of the
+ * subdirectories listed in {@code content.data.ofbiz.file.allowed.paths} (security.properties).
+ */
+ public static void checkOfbizFileAllowList(File file) throws GeneralException {
+ try {
+ String canonicalHome = new File(System.getProperty("ofbiz.home")).getCanonicalPath();
+ String canonicalFilePath = file.getCanonicalPath();
+ if (!canonicalFilePath.startsWith(canonicalHome + File.separator)) {
+ throw new GeneralException("Access to file denied: path resolves outside of the OFBiz home directory");
+ }
+ String allowedPathsStr = UtilProperties.getPropertyValue("security",
+ "content.data.ofbiz.file.allowed.paths", "applications/,themes/,plugins/,runtime/");
+ if (UtilValidate.isNotEmpty(allowedPathsStr)) {
+ boolean inAllowedPath = false;
+ for (String relPath : allowedPathsStr.split(",")) {
+ relPath = relPath.trim().replaceAll("^/+", "");
+ if (UtilValidate.isEmpty(relPath)) {
+ continue;
+ }
+ String canonicalAllowedDir = new File(canonicalHome, relPath).getCanonicalPath();
+ if (canonicalFilePath.startsWith(canonicalAllowedDir + File.separator)
+ || canonicalFilePath.equals(canonicalAllowedDir)) {
+ inAllowedPath = true;
+ break;
+ }
+ }
+ if (!inAllowedPath) {
+ throw new GeneralException("Access to file denied: path is not within an allowed directory");
+ }
+ }
+ } catch (IOException e) {
+ throw new GeneralException("Unable to validate file path: " + e.getMessage());
+ }
+ }
+
/**
* Return a JWToken for authenticate a userLogin with salt the token by userLoginId and currentPassword
*/
(ofbiz-framework) 06/06: Fixed: Cast parse result to int in EntityXmlAssertTest
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jacopoc pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
commit 81f802f729436bd1a0044d55a81b11ba864e9349
Author: Jacopo Cappellato <ja...@gmail.com>
AuthorDate: Wed Apr 8 08:25:05 2026 +0200
Fixed: Cast parse result to int in EntityXmlAssertTest
---
.../src/main/java/org/apache/ofbiz/testtools/EntityXmlAssertTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/framework/testtools/src/main/java/org/apache/ofbiz/testtools/EntityXmlAssertTest.java b/framework/testtools/src/main/java/org/apache/ofbiz/testtools/EntityXmlAssertTest.java
index 97346bd6e0..a7f4e036d6 100644
--- a/framework/testtools/src/main/java/org/apache/ofbiz/testtools/EntityXmlAssertTest.java
+++ b/framework/testtools/src/main/java/org/apache/ofbiz/testtools/EntityXmlAssertTest.java
@@ -58,7 +58,7 @@ public class EntityXmlAssertTest extends OFBizTestCase {
try {
URL entityXmlURL = FlexibleLocation.resolveLocation(entityXmlUrlString);
EntitySaxReader reader = new EntitySaxReader(getDelegator());
- testCaseCount += reader.parse(entityXmlURL);
+ testCaseCount += (int) reader.parse(entityXmlURL);
} catch (Exception e) {
Debug.logError(e, "Error getting test case count", MODULE);
}
(ofbiz-framework) 05/06: Fixed: Cast parse result to int in EntityDataLoader
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jacopoc pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
commit da00c0463884f8a5752945da0b4c5463496eccd6
Author: Jacopo Cappellato <ja...@gmail.com>
AuthorDate: Wed Apr 8 08:24:41 2026 +0200
Fixed: Cast parse result to int in EntityDataLoader
---
.../src/main/java/org/apache/ofbiz/entity/util/EntityDataLoader.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityDataLoader.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityDataLoader.java
index be32c9ad12..31c42c319a 100644
--- a/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityDataLoader.java
+++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityDataLoader.java
@@ -264,7 +264,7 @@ public class EntityDataLoader {
reader.setCreateDummyFks(dummyFks);
reader.setMaintainTxStamps(maintainTxs);
reader.setContinueOnFail(continueOnFail);
- rowsChanged += reader.parse(dataUrl);
+ rowsChanged += (int) reader.parse(dataUrl);
} catch (IOException | SAXException e) {
String xmlError = "[loadData]: Error loading XML Resource \"" + dataUrl.toExternalForm() + "\"; Error was: " + e.getMessage();
errorMessages.add(xmlError);
(ofbiz-framework) 03/06: Fixed: Integrate SecurityUtil to validate file paths in CommonEvents for enhanced security
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jacopoc pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
commit 93b08e85d3e156de86893b619132a1fa8891430e
Author: Jacopo Cappellato <ja...@gmail.com>
AuthorDate: Wed Apr 8 11:01:52 2026 +0200
Fixed: Integrate SecurityUtil to validate file paths in CommonEvents for enhanced security
---
.../common/src/main/java/org/apache/ofbiz/common/CommonEvents.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/framework/common/src/main/java/org/apache/ofbiz/common/CommonEvents.java b/framework/common/src/main/java/org/apache/ofbiz/common/CommonEvents.java
index f8e8dead55..7c52297caa 100644
--- a/framework/common/src/main/java/org/apache/ofbiz/common/CommonEvents.java
+++ b/framework/common/src/main/java/org/apache/ofbiz/common/CommonEvents.java
@@ -46,6 +46,7 @@ import org.apache.commons.lang.StringUtils;
import org.apache.ofbiz.base.lang.JSON;
import org.apache.ofbiz.base.location.FlexibleLocation;
import org.apache.ofbiz.base.util.Debug;
+import org.apache.ofbiz.base.util.GeneralException;
import org.apache.ofbiz.base.util.UtilGenerics;
import org.apache.ofbiz.base.util.UtilHttp;
import org.apache.ofbiz.base.util.UtilProperties;
@@ -57,6 +58,7 @@ import org.apache.ofbiz.entity.GenericValue;
import org.apache.ofbiz.entity.util.EntityUtilProperties;
import org.apache.ofbiz.webapp.control.JWTManager;
import org.apache.ofbiz.webapp.control.LoginWorker;
+import org.apache.ofbiz.security.SecurityUtil;
import org.apache.ofbiz.widget.model.ModelWidget;
import org.apache.ofbiz.widget.model.ScriptLinkHelper;
import org.apache.ofbiz.widget.model.ThemeFactory;
@@ -414,6 +416,7 @@ public class CommonEvents {
if (!platformSpecificPath.contains(File.separator) && "\\".equals(File.separator)) {
platformSpecificPath = platformSpecificPath.replace("/", "\\");
}
+ SecurityUtil.checkOfbizFileAllowList(new File(platformSpecificPath));
// get line number
int lineNumber = 1;
if (UtilValidate.isNotEmpty(fragment)) {
@@ -446,7 +449,7 @@ public class CommonEvents {
Debug.logInfo(line, MODULE);
}
return "success";
- } catch (IOException e) {
+ } catch (GeneralException | IOException e) {
Debug.logError(e, MODULE);
}
}
(ofbiz-framework) 04/06: Fixed: Remove legacy HttpEngine (disabled 5 years ago for security reasons)
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jacopoc pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
commit 95b4898a16085f3adfa7a10ca470c39840c5254b
Author: Jacopo Cappellato <ja...@gmail.com>
AuthorDate: Wed Apr 8 11:46:09 2026 +0200
Fixed: Remove legacy HttpEngine (disabled 5 years ago for security reasons)
---
framework/service/config/serviceengine.xml | 1 -
.../apache/ofbiz/service/engine/HttpEngine.java | 210 ---------------------
.../webapp/webtools/WEB-INF/controller.xml | 8 +-
3 files changed, 2 insertions(+), 217 deletions(-)
diff --git a/framework/service/config/serviceengine.xml b/framework/service/config/serviceengine.xml
index e88be850a3..d5613533df 100644
--- a/framework/service/config/serviceengine.xml
+++ b/framework/service/config/serviceengine.xml
@@ -53,7 +53,6 @@ under the License.
<engine name="javascript" class="org.apache.ofbiz.service.engine.ScriptEngine"/>
<!-- -->
<engine name="route" class="org.apache.ofbiz.service.engine.RouteEngine"/>
- <!-- <engine name="http" class="org.apache.ofbiz.service.engine.HttpEngine"/> -->
<engine name="jms" class="org.apache.ofbiz.service.jms.JmsServiceEngine"/>
<engine name="rmi" class="org.apache.ofbiz.service.rmi.RmiServiceEngine"/>
<!-- <engine name="soap" class="org.apache.ofbiz.service.engine.SOAPClientEngine"/> -->
diff --git a/framework/service/src/main/java/org/apache/ofbiz/service/engine/HttpEngine.java b/framework/service/src/main/java/org/apache/ofbiz/service/engine/HttpEngine.java
deleted file mode 100644
index e9d6db7420..0000000000
--- a/framework/service/src/main/java/org/apache/ofbiz/service/engine/HttpEngine.java
+++ /dev/null
@@ -1,210 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *******************************************************************************/
-package org.apache.ofbiz.service.engine;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.HashMap;
-import java.util.Map;
-
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-
-import org.apache.ofbiz.base.util.Debug;
-import org.apache.ofbiz.base.util.HttpClient;
-import org.apache.ofbiz.base.util.HttpClientException;
-import org.apache.ofbiz.base.util.UtilGenerics;
-import org.apache.ofbiz.entity.Delegator;
-import org.apache.ofbiz.entity.serialize.XmlSerializer;
-import org.apache.ofbiz.service.DispatchContext;
-import org.apache.ofbiz.service.GenericServiceException;
-import org.apache.ofbiz.service.LocalDispatcher;
-import org.apache.ofbiz.service.ModelService;
-import org.apache.ofbiz.service.ServiceDispatcher;
-
-/**
- * HttpEngine.java
- */
-public class HttpEngine extends GenericAsyncEngine {
-
- private static final String MODULE = HttpEngine.class.getName();
- private static final boolean EXPORT_ALL = false;
-
- public HttpEngine(ServiceDispatcher dispatcher) {
- super(dispatcher);
- }
-
- /**
- * @see org.apache.ofbiz.service.engine.GenericEngine#runSync(java.lang.String, org.apache.ofbiz.service.ModelService, java.util.Map)
- */
- @Override
- public Map<String, Object> runSync(String localName, ModelService modelService, Map<String, Object> context) throws GenericServiceException {
- DispatchContext dctx = getDispatcher().getLocalContext(localName);
- String xmlContext = null;
-
- try {
- if (Debug.verboseOn()) {
- Debug.logVerbose("Serializing Context --> " + context, MODULE);
- }
- xmlContext = XmlSerializer.serialize(context);
- } catch (Exception e) {
- throw new GenericServiceException("Cannot serialize context.", e);
- }
-
- Map<String, Object> parameters = new HashMap<>();
- parameters.put("serviceName", modelService.getInvoke());
- if (xmlContext != null) {
- parameters.put("serviceContext", xmlContext);
- }
-
- HttpClient http = new HttpClient(this.getLocation(modelService), parameters);
- String postResult = null;
- try {
- postResult = http.post();
- } catch (HttpClientException e) {
- throw new GenericServiceException("Problems invoking HTTP request", e);
- }
-
- Map<String, Object> result = null;
- try {
- Object res = XmlSerializer.deserialize(postResult, dctx.getDelegator());
- if (res instanceof Map<?, ?>) {
- result = UtilGenerics.cast(res);
- } else {
- throw new GenericServiceException("Result not an instance of Map.");
- }
- } catch (Exception e) {
- throw new GenericServiceException("Problems deserializing result.", e);
- }
-
- return result;
- }
-
- /**
- * @see org.apache.ofbiz.service.engine.GenericEngine#runSyncIgnore(java.lang.String, org.apache.ofbiz.service.ModelService, java.util.Map)
- */
- @Override
- public void runSyncIgnore(String localName, ModelService modelService, Map<String, Object> context) throws GenericServiceException {
- runSync(localName, modelService, context);
- }
-
- /**
- * Event for handling HTTP services
- * @param request HttpServletRequest object
- * @param response HttpServletResponse object
- * @return null
- */
- public static String httpEngine(HttpServletRequest request, HttpServletResponse response) {
- LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
- Delegator delegator = (Delegator) request.getAttribute("delegator");
-
- String serviceName = request.getParameter("serviceName");
- String serviceMode = request.getParameter("serviceMode");
- String xmlContext = request.getParameter("serviceContext");
-
- Map<String, Object> result = new HashMap<>();
- Map<String, Object> context = null;
-
- if (serviceName == null) {
- result.put(ModelService.ERROR_MESSAGE, "Cannot have null service name");
- }
-
- if (serviceMode == null) {
- serviceMode = "SYNC";
- }
-
- // deserialize the context
- if (!result.containsKey(ModelService.ERROR_MESSAGE)) {
- if (xmlContext != null) {
- try {
- Object o = XmlSerializer.deserialize(xmlContext, delegator);
- if (o instanceof Map<?, ?>) {
- context = UtilGenerics.cast(o);
- } else {
- Debug.logError("Context not an instance of Map error", MODULE);
- result.put(ModelService.ERROR_MESSAGE, "Context not an instance of Map");
- }
- } catch (Exception e) {
- Debug.logError(e, "Deserialization error", MODULE);
- result.put(ModelService.ERROR_MESSAGE, "Error occurred deserializing context: " + e.toString());
- }
- }
- }
-
- // invoke the service
- if (!result.containsKey(ModelService.ERROR_MESSAGE)) {
- try {
- ModelService model = dispatcher.getDispatchContext().getModelService(serviceName);
- if (model.isExport() || EXPORT_ALL) {
- if ("ASYNC".equals(serviceMode)) {
- dispatcher.runAsync(serviceName, context);
- } else {
- result = dispatcher.runSync(serviceName, context);
- }
- } else {
- Debug.logWarning("Attempt to invoke a non-exported service: " + serviceName, MODULE);
- throw new GenericServiceException("Cannot find requested service");
- }
- } catch (GenericServiceException e) {
- Debug.logError(e, "Service invocation error", MODULE);
- result.put(ModelService.ERROR_MESSAGE, "Service invocation error: " + e.toString());
- }
- }
-
- // backup error message
- StringBuilder errorMessage = new StringBuilder();
-
- // process the result
- String resultString = null;
- try {
- resultString = XmlSerializer.serialize(result);
- } catch (Exception e) {
- Debug.logError(e, "Cannot serialize result", MODULE);
- if (result.containsKey(ModelService.ERROR_MESSAGE)) {
- errorMessage.append(result.get(ModelService.ERROR_MESSAGE));
- }
- errorMessage.append("::");
- errorMessage.append(e);
- }
-
- // handle the response
- try {
- PrintWriter out = response.getWriter();
- response.setContentType("plain/text");
-
- if (errorMessage.length() > 0) {
- response.setContentLength(errorMessage.toString().getBytes("UTF-8").length);
- out.write(errorMessage.toString());
- } else {
- response.setContentLength(resultString.getBytes("UTF-8").length);
- out.write(resultString);
- }
-
- out.flush();
- response.flushBuffer();
- } catch (IOException e) {
- Debug.logError(e, "Problems w/ getting the servlet writer.", MODULE);
- return "error";
- }
-
- return null;
- }
-
-
-}
diff --git a/framework/webtools/webapp/webtools/WEB-INF/controller.xml b/framework/webtools/webapp/webtools/WEB-INF/controller.xml
index d40d30e324..783acb468a 100644
--- a/framework/webtools/webapp/webtools/WEB-INF/controller.xml
+++ b/framework/webtools/webapp/webtools/WEB-INF/controller.xml
@@ -86,14 +86,10 @@ under the License.
</request-map>
<!-- Begin Utility Requests -->
- <!-- The 2 services below have been commented out for security reason, see OFBIZ-12212 -->
+ <!-- Commented out for security reason, see OFBIZ-12212 -->
<!-- If you feel it's ok with you (e.g. totally secured Internet access, or rather
no access at all which is safer!) you may uncomment and use. -->
- <!-- <request-map uri="httpService">
- <event type="java" path="org.apache.ofbiz.service.engine.HttpEngine" invoke="httpEngine"/>
- <response name="success" type="none"/>
- <response name="error" type="none"/>
- </request-map>
+ <!--
<request-map uri="SOAPService">
<security https="false"/>
<event type="soap"/>
(ofbiz-framework) 02/06: Fixed: Implement file path validation using SecurityUtil in CoreEvents to enhance security
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jacopoc pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
commit d06b61393fd5023ef6f8610e013b2b6f299d14f8
Author: Jacopo Cappellato <ja...@gmail.com>
AuthorDate: Wed Apr 8 10:48:52 2026 +0200
Fixed: Implement file path validation using SecurityUtil in CoreEvents to enhance security
---
.../src/main/java/org/apache/ofbiz/webapp/event/CoreEvents.java | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/CoreEvents.java b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/CoreEvents.java
index a10ba9821d..07166a68f2 100644
--- a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/CoreEvents.java
+++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/CoreEvents.java
@@ -37,6 +37,7 @@ import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.apache.ofbiz.base.util.Debug;
+import org.apache.ofbiz.base.util.GeneralException;
import org.apache.ofbiz.base.util.UtilGenerics;
import org.apache.ofbiz.base.util.UtilHttp;
import org.apache.ofbiz.base.util.UtilProperties;
@@ -47,6 +48,7 @@ import org.apache.ofbiz.entity.GenericEntityException;
import org.apache.ofbiz.entity.GenericValue;
import org.apache.ofbiz.entity.util.EntityQuery;
import org.apache.ofbiz.security.Security;
+import org.apache.ofbiz.security.SecurityUtil;
import org.apache.ofbiz.service.GenericServiceException;
import org.apache.ofbiz.service.LocalDispatcher;
import org.apache.ofbiz.service.ModelService;
@@ -489,6 +491,12 @@ public class CoreEvents {
// load the file
File file = new File(filePath);
+ try {
+ SecurityUtil.checkOfbizFileAllowList(file);
+ } catch (GeneralException e) {
+ Debug.logError(e.getMessage(), MODULE);
+ return "error";
+ }
if (file.exists()) {
Long longLen = file.length();
int length = longLen.intValue();