Author SHA1 Message Date
Jacques Le Roux 00896e73bc Fixed: Announce 17.12.09 EOL (OFBIZ-12479)
Includes:
[SECURITY] CVE-2021-44228: Apache Log4j2 (OFBIZ-12449)
[SECURITY] CVE-2021-45105: Apache Log4j2 (OFBIZ-12470)
[SECURITY] Update TIka because of Apache Log4j2 vulnerability (OFBIZ-12474)
[SECURITY] CVE-2021-44832: Apache Log4j2 (OFBIZ-12475)
2022-01-06 14:19:06 +01:00
Jacques Le Roux fb6b508d56 Improved: Migrate Ofbiz bb 0.8 config to 3.2 (OFBIZ-12456)
Comment out the XMLRPC tests. This alone should allow Buildbot 3.2 to run the
integration tests.

Conflict handled by hand
2021-12-16 08:07:08 +01:00
Mathieu Lirzin bdf94f31a1 Fixed: All local XML schema files are now present in classpath, Backport form trunk
(OFBIZ-11132) (OFBIZ-12437)

Previously there was some warnings about missing “.xsd” files that
‘UtilXml#resolveEntity’ failed to find in classpath.  This has been
fixed by declaring all “dtd” directories inside components as resources.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1862346 13f79535-47bb-0310-9956-ffa450edef68
2021-12-12 15:40:17 +01:00
Wiebke Pätzold c5d262aeab Fixed: Builds fail due to unauthorized access to
repo.spring.io/plugins-release (OFBIZ-12351)

Replaces repository syndication by rometools
2021-12-06 11:45:06 +01:00
Jacques Le Roux 208d44e0a3 Fixed: Builds fail due to unauthorized access to repo.spring.io/plugins-release (OFBIZ-12351)
The old demo crashed. I guess this should be OK, let's try...
2021-12-06 09:54:09 +01:00
rohitkouandRohit Koushal e3691d1b21 Fixed: CVE-2021-37608 vulnerability bypass (OFBIZ-12307) (#352)
Fixed the Additional image uploading issue which got somehow missed in service addAdditionalViewForProduct.

Co-authored-by: Rohit Koushal <rohit.koushal39@gmail.com>
2021-11-23 10:40:26 +01:00
Jacques Le Roux dfb702cd9c Fixed: In LookupProduct some categories don't show, only blank lines (OFBIZ-12368)
For now only description is shown. OOTB some categories have no description
We can easily fix that by showing more info. I suggest to add categoryName and
productCategoryId. That should be enough. There are then no blank lines since
productCategoryId always show.

This is anyway customisable by users
2021-11-09 10:05:38 +01:00
Jacques Le Roux 39db98a535 Fixed: RAINBOWSTONE_SAPHIR does not show right on old demo.
I'm unable to test that locally because I get an error with com.sun.syndication
even when using jcenter and 0.9.0. It works on demo I guess because ASF is
authorised.

Anyway, manually turning to Flat Grey on demo works, so here a patch to do that.
2021-11-09 07:53:43 +01:00
Jacques Le Roux 2aca1121ee Fixed: [SECURITY] CVE-2021-42340 Apache Tomcat DoS (OFBIZ-12337)
Upgrades to Apache Tomcat 9.0.54
2021-10-14 19:31:08 +02:00
Jacques Le Roux 7de28070a3 Improved: post-auth Remote Code Execution Vulnerability (OFBIZ-12332)
Prevents an useless inevitable warning by commenting out
RequestWrapper::getParameterNames and with it all the unused methods in
RequestWrapper class

Also better comments CacheFilter::doFilter by giving its real and only goal:
<<to prevent a post-auth security issue described in OFBIZ-12332>>
2021-10-11 09:44:45 +02:00
Jacques Le Roux c859c6f636 Fixed: post-auth Remote Code Execution Vulnerability (OFBIZ-12332)
When I removed service-permission-tests, I forgot to remove associated
load-data-service-permission-tests :/
2021-10-10 17:28:29 +02:00
Jacques Le Roux d960b2b0ca Improved: Refactor methods signature to reduce the number of params they use (OFBIZ-12335)
Fixes a typo about filterConfiguration in CacheFilter.java
2021-10-10 13:36:30 +02:00
Jacques Le Roux 1c93a26ccc Fixed: post-auth Remote Code Execution Vulnerability (OFBIZ-12332)
Removes service-permission-tests accidentally added while handling conflicts by
hand
2021-10-10 13:25:24 +02:00
Jacques Le Roux 006ce17647 Fixed: post-auth Remote Code Execution Vulnerability (OFBIZ-12332)
In previous commit, in CacheFilter::doFilter, I checked "xmlrpc"  when it was
actually "/control/xmlrpc"
2021-10-10 12:19:35 +02:00
Jacques Le Roux b6257b720b Fixed: post-auth Remote Code Execution Vulnerability (OFBIZ-12332)
This definitely solves all issues by introducing a CacheFilter and
RequestWrapper classes inspired by several works found on the Net.
Also moves the change introduced before in ContextFilter to CacheFilter.

The basic problem is that you only can use once
ServletRequest::getInputStream or the ServletRequest::getReader
Also not both, even once, ie they can be seen as same from this POV.

The integration tests all pass.

Also replace the checked String "</serializable>" by "</serializable" as, like
reported by Jie Zhu, the former could be bypassed by using "</serializable >"

Thanks: Jie Zhu for report

# Conflicts handled by hand
  CacheFilter.java
  RequestWrapper.java
2021-10-10 08:14:57 +02:00
Jacques Le Roux fb49563744 Fixed: post-auth Remote Code Execution Vulnerability (OFBIZ-12332)
This definitely solves all issues by introducing a CacheFilter and
RequestWrapper classes inspired by several works found on the Net.
Also moves the change introduced before in ContextFilter to CacheFilter.

The basic problem is that you only can use once
ServletRequest::getInputStream or the ServletRequest::getReader
Also not both, even once, ie they can be seen as same from this POV.

The integration tests all pass.

Also replace the checked String "</serializable>" by "</serializable" as, like
reported by Jie Zhu, the former could be bypassed by using "</serializable >"

Thanks: Jie Zhu for report

Conflicts: ContextFilter.java handled by hand
2021-10-09 20:00:50 +02:00
Jacques Le Roux 7db83d6a53 Improved: post-auth Remote Code Execution Vulnerability (OFBIZ-12332)
Temporarily comments out XMLRPC tests.

I'll work on a definitive solution ASAP

Conflicts handled by hand: framework/service/testdef/servicetests.xml
2021-10-09 08:01:46 +02:00
Jacques Le Roux 8e8ef4c9dc Fixed: post-auth Remote Code Execution Vulnerability (OFBIZ-12332)
Fixes the "eternal" (for R17 and R18 ;) bug about MODULE (trunk) vs module
2021-10-08 19:35:00 +02:00
Jacques Le Roux 15c209a475 Fixed: post-auth Remote Code Execution Vulnerability (OFBIZ-12332)
As reported by Jie Zhu:
<<The latest version of the OFBiz framework (17.12.08) is affected by an
XMLRPC Remote Code Execution Vulnerability.
This vulnerability is caused by incomplete patch repair of cve-2020-9496.>>

Actually this is not an OFBiz bug (so not related to CVE-2020-9496)
but an old XMLRPC bug (Archiva was(/is?)) also affected:
https://nvd.nist.gov/vuln/detail/CVE-2016-5003

Unfortunately XMLRPC is no longer maintained, so it's OFBiz responsibility to
fix this bug.

As the code that secures serialisation in OFBiz is not reached by this bug, the
solution is to secure it at the ContextFilter class level (ie before it reaches
secured serialisation in OFBiz source).

Thanks: Jie Zhu for report and help.
2021-10-08 19:15:21 +02:00
Jacques Le Roux c79321c479 Fixed: Edit record in product promotion, "Promotion Last Modified Date" is invalid, but don't notice to user (OFBIZ-12046)
As Lalit reported it's not really a bug. But an annoying service transformation
of updateProductPromo to entity-auto (I checked using R15.12). Note that
createProductPromo is not affected

I'm not sure other update services using entity-auto are not affected

Thanks: Do Nhu Vy for report, Lalit Dashora  for initial analysis
2021-10-02 13:58:36 +02:00
Gil Portenseigne d02386d2d1 Improved: Create a deny list to reject webshell tokens (OFBIZ-12324)
Improve readability using stream api
Fix deniedWebShellTokens property where some blank space where removed
and '// python' comment was inlined.
2021-09-22 15:08:41 +02:00
Jacques Le Roux 364f4264b0 Improved: Create a deny list to reject webshell tokens (OFBIZ-12324)
Extracts the list of words used in SecuredUpload::isValidText in a
deniedWebShellTokens property in security.properties
2021-09-20 18:15:16 +02:00
Jacques Le Roux 72e2eacef8 Fixed: Groovy Program sandbox bypass (OFBIZ-12305)
This much increases the current security by creating SecuredUpload::isValidText
and call it from ProgramExport.groovy

This said I agree with thiscodecc that a better solution would be to use a
Groovy sandbox, and not only in ProgramExport.groovy.

I had a quick glance at a such solution. Unfortunately as Cédric Champeau reports
at https://melix.github.io/blog/2015/03/sandboxing.html and unlike thiscodecc
suggest there are no "mature solutions on the market".

Nevertheless I'll have a deeper look at an OFBiz specific Groovy sandbox
solution.

Somehow related: I'll also soon extract the list of words used in
SecuredUpload::isValidText in a deniedWebShellWords property in security.properties

Thanks: thiscodecc for report

Conflicts handled by hand
  framework/webtools/groovyScripts/entity/ProgramExport.groovy
2021-09-17 18:49:27 +02:00
Jacques Le Roux 0a49e0addd Fixed: CVE-2021-37608 vulnerability bypass (OFBIZ-12307)
Fixes a number of issues I spotted while working on OFBIZ-12305 in relation with
OFBIZ-12055

The last change I made for OFBIZ-12305 was incomplete, the files could not be
checked by SecuredUpload because they did not exist! This concerns
ImageManagementServices, DataServices, FrameImage and ProductServices classes.
I used Files::createTempFile to fix that.

Also fixes a bug in SecuredUpload where I reversed the check on
fileToCheck.length in Windows case. I also added a comment, Windows 10 now
allows more length (need an OS parameter change though)

Finally, creates public SecuredUpload::isValidText to be used in OFBIZ-12305

Conflicts handled by hand
  DataServices.java
2021-09-17 11:42:06 +02:00
Jacques Le Roux 95ec51ecd1 Fixed: Found a new XXE (XML External Entity Injection) vulnerability in EntityImport (OFBIZ-12304)
Fixes a typo issue
2021-09-13 10:11:02 +02:00
Jacques Le Roux 123f30eb6b Fixed: Found a new XXE (XML External Entity Injection) vulnerability in EntityImport (OFBIZ-12304)
The XXE vulnerability can read arbitrary files on the server.

Thanks: thiscodecc for reporting this security issue (post-auth)
2021-09-13 08:44:43 +02:00
Jacques Le Roux a28316b70d Fixed: Found a new XXE (XML External Entity Injection) vulnerability in EntityImport (OFBIZ-12304)
The XXE vulnerability can read arbitrary files on the server.

Thanks: thiscodecc for reporting this security issue (post-auth)
2021-09-13 08:16:49 +02:00
Jacques Le Roux 7e00617828 Fixed: Found a new XXE (XML External Entity Injection) vulnerability in ArtifactInfo (OFBIZ-12306)
The XXE vulnerability can read arbitrary files on the server.

Thanks: thiscodecc for reporting this security issue (post-auth)
2021-09-13 08:16:47 +02:00
Jacques Le Roux 1b907b06e8 Fixed: CVE-2021-37608 vulnerability bypass (OFBIZ-12307)
Safer completing solution as recommended by weinull orz <weinull@outlook.com>
Previous commit was OK, but better be safe than sorry ;)

Also forgot to commit the DENIEDFILEEXTENSIONS checkstyle change last time

Thanks: weinull orz for the the right suggestion (done 2021-08-13)
2021-09-03 17:18:11 +02:00
Jacques Le Roux dfd71bf7dd Fixed: CVE-2021-37608 vulnerability bypass (OFBIZ-12307)
The fix I did is two folds:
filters extensions (thanks to Zhujie's suggestion of a list of extensions to ban)
deletes bad files at the right place (thanks to thiscodecc's report)

Thanks: thiscodecc for the security report
2021-09-03 13:48:55 +02:00
Jacques Le Roux 3e5d0b73a8 Documented: Changes the link to issue tracker (Jira) to simplify things related to security 2021-09-01 09:55:51 +02:00
24 changed files with 637 additions and 227 deletions
+4 -1
View File
@@ -129,9 +129,12 @@ In case of problems visit our link:#further-reading[Further reading section].
[[security]]
== Security
If you find a security issue, please report it to: security @ ofbiz.apache.org.
* If you find a pre-auth security issue, please report it to: security @ ofbiz.apache.org.
Once proper mitigations to the security issues are complete the OFBiz team will
disclose this information to the public mailing list.
* If you find a post-auth security issue, please https://s.apache.org/dsj2p[create a bug in our issue tracker (Jira)] .
You can find more information about security in OFBiz at
https://cwiki.apache.org/confluence/display/OFBIZ/Keeping+OFBiz+secure[Keeping OFBiz secure]
@@ -39,12 +39,12 @@ import org.apache.ofbiz.service.DispatchContext;
import org.apache.ofbiz.service.LocalDispatcher;
import org.apache.ofbiz.service.ServiceUtil;
import com.sun.syndication.feed.synd.SyndContent;
import com.sun.syndication.feed.synd.SyndContentImpl;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndEntryImpl;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.feed.synd.SyndFeedImpl;
import com.rometools.rome.feed.synd.SyndContent;
import com.rometools.rome.feed.synd.SyndContentImpl;
import com.rometools.rome.feed.synd.SyndEntry;
import com.rometools.rome.feed.synd.SyndEntryImpl;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.feed.synd.SyndFeedImpl;
/**
* BlogRssServices
@@ -27,6 +27,10 @@ import java.io.RandomAccessFile;
import java.io.StringWriter;
import java.io.Writer;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.HashMap;
@@ -38,7 +42,6 @@ import org.apache.ofbiz.base.util.Debug;
import org.apache.ofbiz.base.util.GeneralException;
import org.apache.ofbiz.base.util.UtilDateTime;
import org.apache.ofbiz.base.util.UtilGenerics;
import org.apache.ofbiz.base.util.UtilIO;
import org.apache.ofbiz.base.util.UtilMisc;
import org.apache.ofbiz.base.util.UtilProperties;
import org.apache.ofbiz.base.util.UtilValidate;
@@ -57,8 +60,8 @@ import org.apache.ofbiz.service.ServiceUtil;
*/
public class DataServices {
public static final String module = DataServices.class.getName();
public static final String resource = "ContentUiLabels";
private static final String MODULE = DataServices.class.getName();
private static final String RESOURCE = "ContentUiLabels";
public static Map<String, Object> clearAssociatedRenderCache(DispatchContext dctx, Map<String, Object> context) {
Delegator delegator = dctx.getDelegator();
@@ -67,8 +70,9 @@ public class DataServices {
try {
DataResourceWorker.clearAssociatedRenderCache(delegator, dataResourceId);
} catch (GeneralException e) {
Debug.logError(e, "Unable to clear associated render cache with dataResourceId=" + dataResourceId, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentClearAssociatedRenderCacheError", UtilMisc.toMap("dataResourceId", dataResourceId), locale));
Debug.logError(e, "Unable to clear associated render cache with dataResourceId=" + dataResourceId, MODULE);
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "ContentClearAssociatedRenderCacheError",
UtilMisc.toMap("dataResourceId", dataResourceId), locale));
}
return ServiceUtil.returnSuccess();
}
@@ -129,7 +133,7 @@ public class DataServices {
dataResourceId = delegator.getNextSeqId("DataResource");
}
if (Debug.infoOn()) {
Debug.logInfo("in createDataResourceMethod, dataResourceId:" + dataResourceId, module);
Debug.logInfo("in createDataResourceMethod, dataResourceId:" + dataResourceId, MODULE);
}
GenericValue dataResource = delegator.makeValue("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId));
dataResource.setNonPKFields(context);
@@ -140,9 +144,10 @@ public class DataServices {
// get first statusId for content out of the statusItem table if not provided
if (UtilValidate.isEmpty(dataResource.get("statusId"))) {
try {
GenericValue statusItem = EntityQuery.use(delegator).from("StatusItem").where("statusTypeId", "CONTENT_STATUS").orderBy("sequenceId").queryFirst();
GenericValue statusItem = EntityQuery.use(delegator).from("StatusItem").where("statusTypeId", "CONTENT_STATUS")
.orderBy("sequenceId").queryFirst();
if (statusItem != null) {
dataResource.put("statusId", statusItem.get("statusId"));
dataResource.put("statusId", statusItem.get("statusId"));
}
} catch (GenericEntityException e) {
return ServiceUtil.returnError(e.getMessage());
@@ -173,7 +178,8 @@ public class DataServices {
String dataResourceId = (String) context.get("dataResourceId");
String textData = (String) context.get("textData");
if (UtilValidate.isNotEmpty(textData)) {
GenericValue electronicText = delegator.makeValue("ElectronicText", UtilMisc.toMap("dataResourceId", dataResourceId, "textData", textData));
GenericValue electronicText = delegator.makeValue("ElectronicText",
UtilMisc.toMap("dataResourceId", dataResourceId, "textData", textData));
try {
electronicText.create();
} catch (GenericEntityException e) {
@@ -210,18 +216,19 @@ public class DataServices {
// extended validation for binary/character data
if (UtilValidate.isNotEmpty(textData) && binData != null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentCannotProcessBothCharacterAndBinaryFile", locale));
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "ContentCannotProcessBothCharacterAndBinaryFile", locale));
}
// obtain a reference to the file
File file = null;
if (UtilValidate.isEmpty(objectInfo)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentUnableObtainReferenceToFile", UtilMisc.toMap("objectInfo", ""), locale));
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "ContentUnableObtainReferenceToFile",
UtilMisc.toMap("objectInfo", ""), locale));
}
if (UtilValidate.isEmpty(dataResourceTypeId) || "LOCAL_FILE".equals(dataResourceTypeId) || "LOCAL_FILE_BIN".equals(dataResourceTypeId)) {
file = new File(objectInfo);
if (!file.isAbsolute()) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentLocalFileDoesNotPointToAbsoluteLocation", locale));
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "ContentLocalFileDoesNotPointToAbsoluteLocation", locale));
}
} else if ("OFBIZ_FILE".equals(dataResourceTypeId) || "OFBIZ_FILE_BIN".equals(dataResourceTypeId)) {
prefix = System.getProperty("ofbiz.home");
@@ -232,7 +239,7 @@ public class DataServices {
} else if ("CONTEXT_FILE".equals(dataResourceTypeId) || "CONTEXT_FILE_BIN".equals(dataResourceTypeId)) {
prefix = (String) context.get("rootDir");
if (UtilValidate.isEmpty(prefix)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentCannotFindContextFileWithEmptyContextRoot", locale));
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "ContentCannotFindContextFileWithEmptyContextRoot", locale));
}
if (objectInfo.indexOf('/') != 0 && prefix.lastIndexOf('/') != (prefix.length() - 1)) {
sep = "/";
@@ -240,43 +247,49 @@ public class DataServices {
file = new File(prefix + sep + objectInfo);
}
if (file == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentUnableObtainReferenceToFile", UtilMisc.toMap("objectInfo", objectInfo), locale));
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "ContentUnableObtainReferenceToFile",
UtilMisc.toMap("objectInfo", objectInfo), locale));
}
// write the data to the file
if (UtilValidate.isNotEmpty(textData)) {
try (
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), UtilIO.getUtf8());
) {
try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8);) {
out.write(textData);
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(file.getAbsolutePath(), "Text", delegator)) {
String errorMessage = UtilProperties.getMessage("SecurityUiLabels", "SupportedTextFileFormats", locale);
return ServiceUtil.returnError(errorMessage);
}
} catch (IOException | ImageReadException e) {
Debug.logWarning(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentUnableWriteCharacterDataToFile", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale));
Debug.logWarning(e, MODULE);
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "ContentUnableWriteCharacterDataToFile",
UtilMisc.toMap("fileName", file.getAbsolutePath()), locale));
}
} else if (binData != null) {
try {
RandomAccessFile out = new RandomAccessFile(file, "rw");
out.write(binData.array());
out.close();
// Check if a webshell is not uploaded
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(file.getAbsolutePath(), "All", delegator)) {
Path tempFile = Files.createTempFile(null, null);
Files.write(tempFile, binData.array(), StandardOpenOption.APPEND);
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(tempFile.toString(), "All", delegator)) {
String errorMessage = UtilProperties.getMessage("SecurityUiLabels", "SupportedFileFormatsIncludingSvg", locale);
return ServiceUtil.returnError(errorMessage);
}
Files.delete(tempFile);
RandomAccessFile out = new RandomAccessFile(file, "rw");
out.write(binData.array());
out.close();
} catch (FileNotFoundException | ImageReadException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentUnableToOpenFileForWriting", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale));
Debug.logError(e, MODULE);
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "ContentUnableToOpenFileForWriting",
UtilMisc.toMap("fileName", file.getAbsolutePath()), locale));
} catch (IOException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentUnableWriteBinaryDataToFile", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale));
Debug.logError(e, MODULE);
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "ContentUnableWriteBinaryDataToFile",
UtilMisc.toMap("fileName", file.getAbsolutePath()), locale));
}
} else {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentNoContentFilePassed", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale));
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "ContentNoContentFilePassed",
UtilMisc.toMap("fileName", file.getAbsolutePath()), locale));
}
Map<String, Object> result = ServiceUtil.returnSuccess();
@@ -324,8 +337,9 @@ public class DataServices {
try {
dataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", dataResourceId).queryOne();
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentDataResourceNotFound", UtilMisc.toMap("parameters.dataResourceId", dataResourceId), locale));
Debug.logWarning(e, MODULE);
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "ContentDataResourceNotFound",
UtilMisc.toMap("parameters.dataResourceId", dataResourceId), locale));
}
dataResource.setNonPKFields(context);
@@ -335,7 +349,7 @@ public class DataServices {
try {
dataResource.store();
} catch (GenericEntityException e) {
Debug.logError(e, module);
Debug.logError(e, MODULE);
return ServiceUtil.returnError(e.getMessage());
}
@@ -352,8 +366,8 @@ public class DataServices {
}
/**
* Because sometimes a DataResource will exist, but no ElectronicText has been created,
* this method will create an ElectronicText if it does not exist.
* Because sometimes a DataResource will exist, but no ElectronicText has been created, this method will create an
* ElectronicText if it does not exist.
* @param dctx the dispatch context
* @param context the context
* @return update the ElectronicText
@@ -368,12 +382,12 @@ public class DataServices {
String contentId = (String) context.get("contentId");
result.put("contentId", contentId);
if (UtilValidate.isEmpty(dataResourceId)) {
Debug.logError("dataResourceId is null.", module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentDataResourceIsNull", locale));
Debug.logError("dataResourceId is null.", MODULE);
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "ContentDataResourceIsNull", locale));
}
String textData = (String) context.get("textData");
if (Debug.verboseOn()) {
Debug.logVerbose("in updateElectronicText, textData:" + textData, module);
Debug.logVerbose("in updateElectronicText, textData:" + textData, MODULE);
}
try {
electronicText = EntityQuery.use(delegator).from("ElectronicText").where("dataResourceId", dataResourceId).queryOne();
@@ -387,8 +401,8 @@ public class DataServices {
electronicText.create();
}
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentElectronicTextNotFound", locale) + " " + e.getMessage());
Debug.logWarning(e, MODULE);
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "ContentElectronicTextNotFound", locale) + " " + e.getMessage());
}
return result;
@@ -445,53 +459,59 @@ public class DataServices {
// write the data to the file
if (UtilValidate.isNotEmpty(textData)) {
try (
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file),UtilIO.getUtf8());
) {
try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8);) {
out.write(textData);
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(file.getAbsolutePath(), "Text", delegator)) {
String errorMessage = UtilProperties.getMessage("SecurityUiLabels", "SupportedTextFileFormats", locale);
return ServiceUtil.returnError(errorMessage);
}
} catch (IOException | ImageReadException e) {
Debug.logWarning(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentUnableWriteCharacterDataToFile", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale));
Debug.logWarning(e, MODULE);
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "ContentUnableWriteCharacterDataToFile",
UtilMisc.toMap("fileName", file.getAbsolutePath()), locale));
}
} else if (binData != null) {
try {
// Check if a webshell is not uploaded
Path tempFile = Files.createTempFile(null, null);
Files.write(tempFile, binData.array(), StandardOpenOption.APPEND);
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(tempFile.toString(), "Image", delegator)) {
String errorMessage = UtilProperties.getMessage("SecurityUiLabels", "SupportedFileFormatsIncludingSvg", locale);
return ServiceUtil.returnError(errorMessage);
}
Files.delete(tempFile);
RandomAccessFile out = new RandomAccessFile(file, "rw");
out.setLength(binData.array().length);
out.write(binData.array());
out.close();
// Check if a webshell is not uploaded
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(file.getAbsolutePath(), "All", delegator)) {
String errorMessage = UtilProperties.getMessage("SecurityUiLabels", "SupportedFileFormatsIncludingSvg", locale);
return ServiceUtil.returnError(errorMessage);
}
} catch (FileNotFoundException | ImageReadException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentUnableToOpenFileForWriting", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale));
Debug.logError(e, MODULE);
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "ContentUnableToOpenFileForWriting",
UtilMisc.toMap("fileName", file.getAbsolutePath()), locale));
} catch (IOException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentUnableWriteBinaryDataToFile", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale));
Debug.logError(e, MODULE);
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "ContentUnableWriteBinaryDataToFile",
UtilMisc.toMap("fileName", file.getAbsolutePath()), locale));
}
} else {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentNoContentFilePassed", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale));
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "ContentNoContentFilePassed",
UtilMisc.toMap("fileName", file.getAbsolutePath()), locale));
}
} catch (IOException e) {
Debug.logWarning(e, module);
Debug.logWarning(e, MODULE);
throw new GenericServiceException(e.getMessage());
}
return result;
}
public static Map<String, Object> renderDataResourceAsText(DispatchContext dctx, Map<String, ? extends Object> context) throws GeneralException, IOException {
public static Map<String, Object> renderDataResourceAsText(DispatchContext dctx, Map<String, ? extends Object> context)
throws GeneralException, IOException {
Map<String, Object> results = new HashMap<>();
//LocalDispatcher dispatcher = dctx.getDispatcher();
Writer out = (Writer) context.get("outWriter");
Map<String, Object> templateContext = UtilGenerics.checkMap(context.get("templateContext"));
Map<String, Object> templateContext = UtilGenerics.cast(context.get("templateContext"));
//GenericValue userLogin = (GenericValue) context.get("userLogin");
String dataResourceId = (String) context.get("dataResourceId");
if (templateContext != null && UtilValidate.isEmpty(dataResourceId)) {
@@ -514,7 +534,7 @@ public class DataServices {
out.write(outWriter.toString());
results.put("textData", outWriter.toString());
} catch (IOException e) {
Debug.logError(e, "Error rendering sub-content text", module);
Debug.logError(e, "Error rendering sub-content text", MODULE);
return ServiceUtil.returnError(e.toString());
}
return results;
@@ -533,14 +553,15 @@ public class DataServices {
Delegator delegator = dctx.getDelegator();
//Locale locale = (Locale) context.get("locale");
String dataResourceId = (String) context.get("dataResourceId");
ByteBuffer byteBuffer = (ByteBuffer)context.get("imageData");
ByteBuffer byteBuffer = (ByteBuffer) context.get("imageData");
if (byteBuffer != null) {
byte[] imageBytes = byteBuffer.array();
try {
GenericValue imageDataResource = EntityQuery.use(delegator).from("ImageDataResource").where("dataResourceId", dataResourceId).queryOne();
GenericValue imageDataResource = EntityQuery.use(delegator).from("ImageDataResource")
.where("dataResourceId", dataResourceId).queryOne();
if (Debug.infoOn()) {
Debug.logInfo("imageDataResource(U):" + imageDataResource, module);
Debug.logInfo("imageBytes(U):" + Arrays.toString(imageBytes), module);
Debug.logInfo("imageDataResource(U):" + imageDataResource, MODULE);
Debug.logInfo("imageBytes(U):" + Arrays.toString(imageBytes), MODULE);
}
if (imageDataResource == null) {
return createImageMethod(dctx, context);
@@ -566,14 +587,14 @@ public class DataServices {
Map<String, Object> result = new HashMap<>();
Delegator delegator = dctx.getDelegator();
String dataResourceId = (String) context.get("dataResourceId");
ByteBuffer byteBuffer = (ByteBuffer)context.get("imageData");
ByteBuffer byteBuffer = (ByteBuffer) context.get("imageData");
if (byteBuffer != null) {
byte[] imageBytes = byteBuffer.array();
try {
GenericValue imageDataResource = delegator.makeValue("ImageDataResource", UtilMisc.toMap("dataResourceId", dataResourceId));
imageDataResource.setBytes("imageData", imageBytes);
if (Debug.infoOn()) {
Debug.logInfo("imageDataResource(C):" + imageDataResource, module);
Debug.logInfo("imageDataResource(C):" + imageDataResource, MODULE);
}
imageDataResource.create();
} catch (GenericEntityException e) {
@@ -597,35 +618,34 @@ public class DataServices {
return result;
}
public static Map<String, Object> createBinaryFileMethod(DispatchContext dctx, Map<String, ? extends Object> context) throws GenericServiceException {
public static Map<String, Object> createBinaryFileMethod(DispatchContext dctx, Map<String, ? extends Object> context)
throws GenericServiceException {
Delegator delegator = dctx.getDelegator();
Map<String, Object> result = new HashMap<>();
GenericValue dataResource = (GenericValue) context.get("dataResource");
String dataResourceTypeId = (String) dataResource.get("dataResourceTypeId");
String objectInfo = (String) dataResource.get("objectInfo");
byte [] imageData = (byte []) context.get("imageData");
String rootDir = (String)context.get("rootDir");
byte[] imageData = (byte[]) context.get("imageData");
String rootDir = (String) context.get("rootDir");
Locale locale = (Locale) context.get("locale");
File file = null;
if (Debug.infoOn()) {
Debug.logInfo("in createBinaryFileMethod, dataResourceTypeId:" + dataResourceTypeId, module);
Debug.logInfo("in createBinaryFileMethod, objectInfo:" + objectInfo, module);
Debug.logInfo("in createBinaryFileMethod, rootDir:" + rootDir, module);
Debug.logInfo("in createBinaryFileMethod, dataResourceTypeId:" + dataResourceTypeId, MODULE);
Debug.logInfo("in createBinaryFileMethod, objectInfo:" + objectInfo, MODULE);
Debug.logInfo("in createBinaryFileMethod, rootDir:" + rootDir, MODULE);
}
try {
file = DataResourceWorker.getContentFile(dataResourceTypeId, objectInfo, rootDir);
} catch (FileNotFoundException | GeneralException e) {
Debug.logWarning(e, module);
Debug.logWarning(e, MODULE);
throw new GenericServiceException(e.getMessage());
}
if (Debug.infoOn()) {
Debug.logInfo("in createBinaryFileMethod, file:" + file, module);
Debug.logInfo("in createBinaryFileMethod, imageData:" + imageData.length, module);
Debug.logInfo("in createBinaryFileMethod, file:" + file, MODULE);
Debug.logInfo("in createBinaryFileMethod, imageData:" + imageData.length, MODULE);
}
if (imageData != null && imageData.length > 0) {
try (
FileOutputStream out = new FileOutputStream(file);
) {
try (FileOutputStream out = new FileOutputStream(file);) {
out.write(imageData);
// Check if a webshell is not uploaded
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(file.getAbsolutePath(), "All", delegator)) {
@@ -633,10 +653,10 @@ public class DataServices {
return ServiceUtil.returnError(errorMessage);
}
if (Debug.infoOn()) {
Debug.logInfo("in createBinaryFileMethod, length:" + file.length(), module);
Debug.logInfo("in createBinaryFileMethod, length:" + file.length(), MODULE);
}
} catch (IOException | ImageReadException e) {
Debug.logWarning(e, module);
Debug.logWarning(e, MODULE);
throw new GenericServiceException(e.getMessage());
}
}
@@ -657,38 +677,34 @@ public class DataServices {
return result;
}
public static Map<String, Object> updateBinaryFileMethod(DispatchContext dctx, Map<String, ? extends Object> context) throws GenericServiceException {
public static Map<String, Object> updateBinaryFileMethod(DispatchContext dctx, Map<String, ? extends Object> context)
throws GenericServiceException {
Delegator delegator = dctx.getDelegator();
Map<String, Object> result = new HashMap<>();
GenericValue dataResource = (GenericValue) context.get("dataResource");
String dataResourceTypeId = (String) dataResource.get("dataResourceTypeId");
String objectInfo = (String) dataResource.get("objectInfo");
byte [] imageData = (byte []) context.get("imageData");
String rootDir = (String)context.get("rootDir");
byte[] imageData = (byte[]) context.get("imageData");
String rootDir = (String) context.get("rootDir");
Locale locale = (Locale) context.get("locale");
File file = null;
if (Debug.infoOn()) {
Debug.logInfo("in updateBinaryFileMethod, dataResourceTypeId:" + dataResourceTypeId, module);
Debug.logInfo("in updateBinaryFileMethod, objectInfo:" + objectInfo, module);
Debug.logInfo("in updateBinaryFileMethod, rootDir:" + rootDir, module);
Debug.logInfo("in updateBinaryFileMethod, dataResourceTypeId:" + dataResourceTypeId, MODULE);
Debug.logInfo("in updateBinaryFileMethod, objectInfo:" + objectInfo, MODULE);
Debug.logInfo("in updateBinaryFileMethod, rootDir:" + rootDir, MODULE);
}
try {
file = DataResourceWorker.getContentFile(dataResourceTypeId, objectInfo, rootDir);
} catch (FileNotFoundException e) {
Debug.logWarning(e, module);
} catch (FileNotFoundException | GeneralException e) {
Debug.logWarning(e, MODULE);
throw new GenericServiceException(e.getMessage());
} catch (GeneralException e2) {
Debug.logWarning(e2, module);
throw new GenericServiceException(e2.getMessage());
}
if (Debug.infoOn()) {
Debug.logInfo("in updateBinaryFileMethod, file:" + file, module);
Debug.logInfo("in updateBinaryFileMethod, imageData:" + Arrays.toString(imageData), module);
Debug.logInfo("in updateBinaryFileMethod, file:" + file, MODULE);
Debug.logInfo("in updateBinaryFileMethod, imageData:" + Arrays.toString(imageData), MODULE);
}
if (imageData != null && imageData.length > 0) {
try (
FileOutputStream out = new FileOutputStream(file);
){
try (FileOutputStream out = new FileOutputStream(file);) {
out.write(imageData);
// Check if a webshell is not uploaded
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(file.getAbsolutePath(), "All", delegator)) {
@@ -697,10 +713,10 @@ public class DataServices {
}
if (Debug.infoOn()) {
Debug.logInfo("in updateBinaryFileMethod, length:" + file.length(), module);
Debug.logInfo("in updateBinaryFileMethod, length:" + file.length(), MODULE);
}
} catch (IOException | ImageReadException e) {
Debug.logWarning(e, module);
Debug.logWarning(e, MODULE);
throw new GenericServiceException(e.getMessage());
}
}
@@ -31,6 +31,9 @@ import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
@@ -292,14 +295,17 @@ public class FrameImage {
request.setAttribute("_ERROR_MESSAGE_", "There is an existing frame, please select from the existing frame.");
return "error";
}
RandomAccessFile out = new RandomAccessFile(file, "rw");
out.write(imageData.array());
out.close();
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(file.getAbsolutePath(), "Image", delegator)) {
Path tmpFile = Files.createTempFile(null, null);
Files.write(tmpFile, imageData.array(), StandardOpenOption.APPEND);
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(tmpFile.toString(), "Image", delegator)) {
String errorMessage = UtilProperties.getMessage("SecurityUiLabels", "SupportedFileFormatsIncludingSvg", locale);
request.setAttribute("_ERROR_MESSAGE_", errorMessage);
return "error";
}
Files.delete(tmpFile);
RandomAccessFile out = new RandomAccessFile(file, "rw");
out.write(imageData.array());
out.close();
//create dataResource
Map<String, Object> dataResourceCtx = new HashMap<>();
@@ -27,6 +27,9 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -149,15 +152,19 @@ public class ImageManagementServices {
}
if (UtilValidate.isEmpty(imageResize)) {
// Create image file original to folder product id.
// check file content
try {
RandomAccessFile out = new RandomAccessFile(file, "rw");
out.write(imageData.array());
out.close();
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(file.toString(), "Image", delegator)) {
Path tempFile = Files.createTempFile(null, null);
Files.write(tempFile, imageData.array(), StandardOpenOption.APPEND);
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(tempFile.toString(), "Image", delegator)) {
String errorMessage = UtilProperties.getMessage("SecurityUiLabels", "SupportedImageFormats", locale);
return ServiceUtil.returnError(errorMessage);
}
Files.delete(tempFile);
// Create image file original to folder product id.
RandomAccessFile out = new RandomAccessFile(file, "rw");
out.write(imageData.array());
out.close();
} catch (FileNotFoundException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
@@ -175,14 +182,16 @@ public class ImageManagementServices {
fileOriginal = checkExistsImage(fileOriginal);
try {
RandomAccessFile outFile = new RandomAccessFile(fileOriginal, "rw");
outFile.write(imageData.array());
outFile.close();
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(fileOriginal.toString(), "Image", delegator)) {
Path tempFile = Files.createTempFile(null, null);
Files.write(tempFile, imageData.array(), StandardOpenOption.APPEND);
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(tempFile.toString(), "Image", delegator)) {
String errorMessage = UtilProperties.getMessage("SecurityUiLabels", "SupportedImageFormats", locale);
return ServiceUtil.returnError(errorMessage);
}
Files.delete(tempFile);
RandomAccessFile outFile = new RandomAccessFile(fileOriginal, "rw");
outFile.write(imageData.array());
outFile.close();
} catch (FileNotFoundException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
@@ -529,14 +538,16 @@ public class ImageManagementServices {
String fileToCheck = imageServerPath + "/" + productId + "/" + filenameToUseThumb;
File fileOriginalThumb = new File(fileToCheck);
try {
RandomAccessFile outFileThumb = new RandomAccessFile(fileOriginalThumb, "rw");
outFileThumb.write(imageData.array());
outFileThumb.close();
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(fileToCheck, "Image", delegator)) {
Path tempFile = Files.createTempFile(null, null);
Files.write(tempFile, imageData.array(), StandardOpenOption.APPEND);
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(tempFile.toString(), "Image", delegator)) {
String errorMessage = UtilProperties.getMessage("SecurityUiLabels", "SupportedImageFormats", locale);
return ServiceUtil.returnError(errorMessage);
}
Files.delete(tempFile);
RandomAccessFile outFileThumb = new RandomAccessFile(fileOriginalThumb, "rw");
outFileThumb.write(imageData.array());
outFileThumb.close();
} catch (FileNotFoundException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
@@ -24,6 +24,9 @@ import java.io.IOException;
import java.io.RandomAccessFile;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.HashMap;
@@ -1046,13 +1049,16 @@ public class ProductServices {
String fileToCheck = imageServerPath + "/" + fileLocation + "." + extension.getString("fileExtensionId");
File file = new File(fileToCheck);
try {
RandomAccessFile out = new RandomAccessFile(fileToCheck, "rw");
out.write(imageData.array());
out.close();
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(fileToCheck, "Image", delegator)) {
Path tempFile = Files.createTempFile(null, null);
Files.write(tempFile, imageData.array(), StandardOpenOption.APPEND);
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(tempFile.toString(), "Image", delegator)) {
String errorMessage = UtilProperties.getMessage("SecurityUiLabels", "SupportedImageFormats", locale);
return ServiceUtil.returnError(errorMessage);
}
Files.delete(tempFile);
RandomAccessFile out = new RandomAccessFile(fileToCheck, "rw");
out.write(imageData.array());
out.close();
} catch (FileNotFoundException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource,
@@ -1323,14 +1329,16 @@ public class ProductServices {
File file = new File(fileToCheck);
try {
RandomAccessFile out = new RandomAccessFile(file, "rw");
out.write(imageData.array());
out.close();
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(fileToCheck, "Image", delegator)) {
Path tempFile = Files.createTempFile(null, null);
Files.write(tempFile, imageData.array(), StandardOpenOption.APPEND);
if (!org.apache.ofbiz.security.SecuredUpload.isValidFile(tempFile.toString(), "Image", delegator)) {
String errorMessage = UtilProperties.getMessage("SecurityUiLabels", "SupportedImageFormats", locale);
return ServiceUtil.returnError(errorMessage);
}
Files.delete(tempFile);
RandomAccessFile out = new RandomAccessFile(file, "rw");
out.write(imageData.array());
out.close();
} catch (FileNotFoundException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource,
@@ -35,7 +35,7 @@ under the License.
</field>
<field name="primaryProductCategoryId" title="${uiLabelMap.ProductPrimaryCategory}">
<drop-down allow-empty="true">
<entity-options entity-name="ProductCategory" key-field-name="productCategoryId">
<entity-options entity-name="ProductCategory" key-field-name="productCategoryId" description="${description} ${categoryName} [${productCategoryId}]">
<entity-order-by field-name="description"/>
</entity-options>
</drop-down>
@@ -377,4 +377,4 @@ under the License.
<field name="costGlAccountTypeId" title="${uiLabelMap.ProductCostGlAccountTypeId}"><display/></field>
<field name="offsettingGlAccountTypeId" title="${uiLabelMap.ProductOffsettingGlAccountTypeId}"><display/></field>
</form>
</forms>
</forms>
@@ -18,7 +18,7 @@ specific language governing permissions and limitations
under the License.
-->
<forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://ofbiz.apache.org/Widget-Form" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Form http://ofbiz.apache.org/dtds/widget-form.xsd">
<form name="ListProductPromos" type="list" title="" list-name="productPromos"
paginate-target="FindProductPromo" odd-row-style="alternate-row" default-table-style="basic-table">
@@ -42,6 +42,12 @@ under the License.
<alt-target use-when="productPromo==null" target="createProductPromo"/>
<auto-fields-service service-name="updateProductPromo" map-name=""/>
<field name="createdDate"><hidden/></field>
<field name="createdByUserLogin"><hidden/></field>
<field name="lastModifiedDate"><hidden/></field>
<field name="lastModifiedByUserLogin"><hidden/></field>
<field use-when="productPromo!=null" name="productPromoId" title="${uiLabelMap.ProductPromotion}" tooltip=""><display/></field>
<field use-when="productPromo==null&amp;&amp;productPromoId!=null" name="productPromoId" title="${uiLabelMap.ProductPromotion}" tooltip="${uiLabelMap.ProductCouldNotFindProductPromotion} [${productPromoId}]"><display/></field>
<!-- this to be taken care of with auto-fields-service as soon as it uses entity field info too -->
@@ -118,7 +124,7 @@ under the License.
</hyperlink>
</field>
</form>
<form name="EditProductPromoContentImage" type="upload" target="addImageContentForProductPromo" default-map-name="productPromoContent">
<field name="productPromoId"><hidden/></field>
<field use-when="productPromoContent != null" name="contentId"><display/></field>
+16 -18
View File
@@ -106,10 +106,6 @@ allprojects {
artifact()
}
}
maven {
// com.springsource.com.sun.syndication
url "https://repo.spring.io/plugins-release"
}
}
}
@@ -145,7 +141,8 @@ dependencies {
compile 'com.ibm.icu:icu4j:60.2'
compile 'com.lowagie:itext:2.1.7' // Don't update due to license change in newer versions, see OFBIZ-10455
compile 'com.sun.mail:javax.mail:1.6.0'
compile 'com.sun.syndication:com.springsource.com.sun.syndication:1.0.0'
compile 'com.rometools:rome:1.16.0'
compile 'org.jdom:jdom:1.1.3' // don't upgrade above 1.1.3, makes a lot of not obvious and useless complications, see last commits of OFBIZ-12092 for more
compile 'com.thoughtworks.xstream:xstream:1.4.10'
compile 'commons-cli:commons-cli:1.4'
compile 'commons-net:commons-net:3.6'
@@ -169,16 +166,17 @@ dependencies {
compile 'org.apache.geronimo.components:geronimo-transaction:3.1.4'
compile 'org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.1.1'
compile 'org.apache.httpcomponents:httpclient-cache:4.5.4'
compile 'org.apache.logging.log4j:log4j-api:2.10.0' // the API of log4j 2
compile 'org.apache.logging.log4j:log4j-api:2.17.1' // the API of log4j 2
compile 'org.apache.logging.log4j:log4j-web:2.17.1'
compile 'org.apache.shiro:shiro-core:1.4.0'
compile 'org.apache.tika:tika-core:1.26'
compile 'org.apache.tika:tika-parsers:1.26'
compile 'org.apache.tika:tika-core:1.28'
compile 'org.apache.tika:tika-parsers:1.28'
compile 'org.apache.pdfbox:pdfbox:2.0.24'
compile 'org.apache.poi:poi:3.17'
compile 'org.apache.tomcat:tomcat-catalina-ha:9.0.48'
compile 'org.apache.tomcat:tomcat-catalina:9.0.48'
compile 'org.apache.tomcat:tomcat-jasper:9.0.48'
compile 'org.apache.tomcat:tomcat-tribes:9.0.48'
compile 'org.apache.tomcat:tomcat-catalina-ha:9.0.54'
compile 'org.apache.tomcat:tomcat-catalina:9.0.54'
compile 'org.apache.tomcat:tomcat-jasper:9.0.54'
compile 'org.apache.tomcat:tomcat-tribes:9.0.54'
compile 'org.apache.xmlgraphics:fop:2.2'
compile 'org.apache.xmlrpc:xmlrpc-client:3.1.3'
compile 'org.apache.xmlrpc:xmlrpc-server:3.1.3'
@@ -206,11 +204,11 @@ dependencies {
runtime 'org.apache.axis2:axis2-transport-local:1.7.7'
runtime 'org.apache.derby:derby:10.14.1.0'
runtime 'org.apache.geronimo.specs:geronimo-jaxrpc_1.1_spec:1.1'
runtime 'org.apache.logging.log4j:log4j-1.2-api:2.10.0' // for external jars using the old log4j1.2: routes logging to log4j 2
runtime 'org.apache.logging.log4j:log4j-core:2.10.0' // the implementation of the log4j 2 API
runtime 'org.apache.logging.log4j:log4j-jul:2.10.0' // for external jars using the java.util.logging: routes logging to log4j 2
runtime 'org.apache.logging.log4j:log4j-slf4j-impl:2.10.0' // for external jars using slf4j: routes logging to log4j 2
runtime 'org.apache.logging.log4j:log4j-jcl:2.10.0' // need to constrain to version to avoid classpath conflict (ReflectionUtil)
runtime 'org.apache.logging.log4j:log4j-1.2-api:2.17.1' // for external jars using the old log4j1.2: routes logging to log4j 2
runtime 'org.apache.logging.log4j:log4j-core:2.17.1' // the implementation of the log4j 2 API
runtime 'org.apache.logging.log4j:log4j-jul:2.17.1' // for external jars using the java.util.logging: routes logging to log4j 2
runtime 'org.apache.logging.log4j:log4j-slf4j-impl:2.17.1' // for external jars using slf4j: routes logging to log4j 2
runtime 'org.apache.logging.log4j:log4j-jcl:2.17.1' // need to constrain to version to avoid classpath conflict (ReflectionUtil)
runtime 'org.codeartisans.thirdparties.swing:batik-all:1.8pre-r1084380'
// plugin libs
@@ -271,7 +269,7 @@ sourceSets {
resources {
srcDirs = getDirectoryInActiveComponentsIfExists('src/main/java')
srcDirs += getDirectoryInActiveComponentsIfExists('config')
srcDirs += "${rootDir}/framework/base/dtd"
srcDirs += getDirectoryInActiveComponentsIfExists('dtd')
exclude excludedJavaSources
exclude excludedConfigFiles
// Below are necessary for unit tests run by Gradle and integration tests
@@ -0,0 +1,120 @@
/*******************************************************************************
* 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.base.util;
import java.io.IOException;
import java.util.stream.Collectors;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
public class CacheFilter implements Filter {
private FilterConfig filterConfig = null;
/**
* The <code>doFilter</code> method of the Filter is called by the container each time a request/response pair is passed through the chain due to
* a client request for a resource at the end of the chain. The FilterChain passed in to this method allows the Filter to pass on the request and
* response to the next entity in the chain.
* <p>
* A typical implementation of this method would follow the following pattern:- <br>
* 1. Examine the request<br>
* 2. Optionally wrap the request object with a custom implementation to filter content or headers for input filtering <br>
* 3. Optionally wrap the response object with a custom implementation to filter content or headers for output filtering <br>
* 4. a) <strong>Either</strong> invoke the next entity in the chain using the FilterChain object (<code>chain.doFilter()</code>), <br>
* 4. b) <strong>or</strong> not pass on the request/response pair to the next entity in the filter chain to block the request processing<br>
* 5. Directly set headers on the response after invocation of the next entity in the filter chain. <br>
* <br>
* ----------------------------------------------------------------------------------------------------<br>
* Actually its goal in OFBiz is simply to prevent a post-auth security issue described in OFBIZ-12332 <br>
* ----------------------------------------------------------------------------------------------------<br>
* <br>
* @param request The request to process
* @param response The response associated with the request
* @param chain Provides access to the next filter in the chain for this filter to pass the request and response to for further processing
* @throws IOException if an I/O error occurs during this filter's processing of the request
* @throws ServletException if the processing fails for any other reason
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// Get the request URI without the webapp mount point.
String context = ((HttpServletRequest) request).getContextPath();
String uriWithContext = ((HttpServletRequest) request).getRequestURI();
String uri = uriWithContext.substring(context.length());
if ("/control/xmlrpc".equals(uri.toLowerCase())) {
// Read request.getReader() as many time you need
request = new RequestWrapper((HttpServletRequest) request);
String body = request.getReader().lines().collect(Collectors.joining());
if (body.contains("</serializable")) {
Debug.logError("Content not authorised for security reason", "CacheFilter"); // Cf. OFBIZ-12332
return;
}
}
chain.doFilter(request, response);
}
/**
* Called by the web container to indicate to a filter that it is being placed into service. The servlet container calls the init method exactly
* once after instantiating the filter. The init method must complete successfully before the filter is asked to do any filtering work.
* <p>
* The web container cannot place the filter into service if the init method either:
* <ul>
* <li>Throws a ServletException</li>
* <li>Does not return within a time period defined by the web container</li>
* </ul>
* The default implementation is a NO-OP.
* @param filterConfiguration The configuration information associated with the filter instance being initialised
* @throws ServletException if the initialisation fails
*/
public void init(FilterConfig filterConfiguration) throws ServletException {
setFilterConfig(filterConfiguration);
}
/**
* Called by the web container to indicate to a filter that it is being taken out of service. This method is only called once all threads within
* the filter's doFilter method have exited or after a timeout period has passed. After the web container calls this method, it will not call the
* doFilter method again on this instance of the filter. <br>
* <br>
* This method gives the filter an opportunity to clean up any resources that are being held (for example, memory, file handles, threads) and make
* sure that any persistent state is synchronized with the filter's current state in memory. The default implementation is a NO-OP.
*/
public void destroy() {
setFilterConfig(null);
}
/**
* @return the filterConfig
*/
public FilterConfig getFilterConfig() {
return filterConfig;
}
/**
* @param filterConfig the filterConfig to set
*/
public void setFilterConfig(FilterConfig filterConfig) {
this.filterConfig = filterConfig;
}
}
@@ -0,0 +1,184 @@
/*******************************************************************************
* 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.base.util;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
//import java.util.Collections;
//import java.util.Enumeration;
//import java.util.HashMap;
//import java.util.Map;
import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
public class RequestWrapper extends HttpServletRequestWrapper {
private static final int INITIAL_BUFFER_SIZE = 1024;
private HttpServletRequest origRequest;
private byte[] reqBytes;
private boolean firstTime = true;
// private Map<String, String[]> parameterMap = null;
public RequestWrapper(HttpServletRequest arg) {
super(arg);
origRequest = arg;
}
/**
* The default behavior of this method is to return getReader() on the wrapped request object.
*/
public BufferedReader getReader() throws IOException {
getBytes();
InputStreamReader dave = new InputStreamReader(new ByteArrayInputStream(reqBytes));
BufferedReader br = new BufferedReader(dave);
return br;
}
/**
* The default behavior of this method is to return getInputStream() on the wrapped request object.
*/
public ServletInputStream getInputStream() throws IOException {
getBytes();
ServletInputStream sis = new ServletInputStream() {
private int numberOfBytesAlreadyRead;
@Override
public int read() throws IOException {
byte b;
if (reqBytes.length > numberOfBytesAlreadyRead) {
b = reqBytes[numberOfBytesAlreadyRead++];
} else {
b = -1;
}
return b;
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
if (len > (reqBytes.length - numberOfBytesAlreadyRead)) {
len = reqBytes.length - numberOfBytesAlreadyRead;
}
if (len <= 0) {
return -1;
}
System.arraycopy(reqBytes, numberOfBytesAlreadyRead, b, off, len);
numberOfBytesAlreadyRead += len;
return len;
}
/**
* Needed by Servlet 3.1 No worry this is not used in OFBiz code
*/
@Override
public boolean isFinished() {
return false;
}
/**
* Needed by Servlet 3.1 No worry this is not used in OFBiz code
*/
@Override
public boolean isReady() {
return false;
}
/**
* Needed by Servlet 3.1 No worry this is not used in OFBiz code
*/
@Override
public void setReadListener(ReadListener listener) {
}
};
return sis;
}
/**
* Returns the bytes taken from the original request getInputStream
*/
public byte[] getBytes() throws IOException {
if (firstTime) {
firstTime = false;
// Read the parameters first, because they can't be reached after the inputStream is read.
getParameterMap();
int initialSize = origRequest.getContentLength();
if (initialSize < INITIAL_BUFFER_SIZE) {
initialSize = INITIAL_BUFFER_SIZE;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream(initialSize);
byte[] buf = new byte[1024];
InputStream is = origRequest.getInputStream();
int len = 0;
while (len >= 0) {
len = is.read(buf);
if (len > 0) {
baos.write(buf, 0, len);
}
}
reqBytes = baos.toByteArray();
}
return reqBytes;
}
// Those are not used, just kept in case
// @Override
// public String getParameter(String name) {
// parameterMap = UtilMisc.toMap(getParameterMap());
// if (parameterMap != null) {
// String[] a = parameterMap.get(name);
// if (a == null || a.length == 0) {
// return null;
// }
// return a[0];
// }
// return null;
// }
//
// @Override
// public Map<String, String[]> getParameterMap() {
// if (parameterMap == null) {
// parameterMap = new HashMap<String, String[]>();
// parameterMap.putAll(super.getParameterMap());
// }
// return parameterMap;
// }
//
// @SuppressWarnings("unchecked")
// @Override
// public Enumeration getParameterNames() {
// return Collections.enumeration(parameterMap.values());
// }
//
// @Override
// public String[] getParameterValues(String name) {
// return parameterMap.get(name);
// }
}
@@ -146,8 +146,8 @@ public final class UtilURL {
try {
url = new URL(urlString);
} catch (MalformedURLException e) {
// We purposely don't want to do anything here
}
return url;
}
@@ -806,8 +806,9 @@ public final class UtilValidate {
return true;
}
/** isUrl returns true if the string contains ://
* @param s String to validate
/**
* isUrl returns true if the string contains ://
* @param s String to validate Note: this does not handle "component://" specific to OFBiz
* @return true if s contains ://
*/
public static boolean isUrl(String s) {
@@ -820,6 +821,30 @@ public final class UtilValidate {
return false;
}
/**
* URLInString returns true if the string contains :// and not "component://"
* @param s String to validate
* @return true if s contains :// and not "component://"
*/
public static boolean URLInString(String s) {
if (isEmpty(s) || s.contains("component://")) {
return false;
}
return s.indexOf("://") != -1;
}
/**
* urlInString returns true if the string contains :// and not "component://"
* @param s String to validate
* @return true if s contains :// and not "component://"
*/
public static boolean urlInString(String s) {
if (isEmpty(s) || s.contains("component://")) {
return false;
}
return s.indexOf("://") != -1;
}
/**
* isValidUrl returns true if the string is a valid URL (using Commons UrlValidator)
* @param s String to validate
@@ -832,6 +857,7 @@ public final class UtilValidate {
return UrlValidator.getInstance().isValid(s);
}
/** isYear returns true if string s is a valid
* Year number. Must be 2 or 4 digits only.
*
+1 -1
View File
@@ -27,7 +27,7 @@ currency.uom.id.default=USD
# -- the default organizationPartyId for used in dropdowns and reports
ORGANIZATION_PARTY=Company
# ID of the VisualTheme to use if there is no VISUAL_THEME UserPreference record for the current user (ie default value)
VISUAL_THEME=RAINBOWSTONE_SAPHIR
VISUAL_THEME=FLAT_GREY
# -- the default decimal format for currency (used in UtilFormatOut.java)
currency.decimal.format=#,##0.00
+1 -1
View File
@@ -437,7 +437,7 @@ under the License.
<attribute name="feedType" type="String" mode="IN" optional="false"/>
<attribute name="mainLink" type="String" mode="IN" optional="false"/>
<attribute name="entryLink" type="String" mode="IN" optional="false"/>
<attribute name="wireFeed" type="com.sun.syndication.feed.WireFeed" mode="OUT" optional="false"/>
<attribute name="wireFeed" type="com.rometools.rome.feed.WireFeed" mode="OUT" optional="false"/>
</service>
<!-- User preferences services -->
+14 -1
View File
@@ -151,7 +151,7 @@ SameSiteCookieAttribute=
templateClassResolver=
#-- UPLOAD: supported file formats are *safe* PNG, GIF, TIFF, JPEG, PDF, Audio and Video and ZIP
#-- ===== UPLOAD: supported file formats are *safe* PNG, GIF, TIFF, JPEG, PDF, Audio and Video and ZIP
#--
#-- No proprietary file formats (Excel, Word, etc.) are handled OOTB.
#-- They can be handled by custom projects using https://github.com/righettod/document-upload-protection:
@@ -174,10 +174,23 @@ templateClassResolver=
#-- For text files, the philosophy is we can't presume of all possible text contents used for attacks with payloads
#-- At least there is an easy way to prevent them in SecuredUpload::isValidTextFile
#--
#-- List of denied files suffixes to be uploaded
#-- OFBiz of course also check contents...
deniedFileExtensions=html,htm,php,php2,hph3,php4,php5,asp,aspx,ascx,jsp,jspx,cfm,cfc,bat,exe,com,dll,vbs,js,reg,cgi,htaccess,asis,sh,phtm,shtm,inc,asp,cdx,asa,cer,py,pl,shtml,hta,ps1
#--
#-- The upload vulnerability is only a post-auth (needs a credential with suitable permissions),
#-- people may like to allow more than what is allowed OOTB
#-- As it name says, allowAllUploads opens all possibilities
allowAllUploads=
#--
#-- List of denied tokens often part of webshells
#-- TODO.... to be continued with known webshell contents... a complete allow list is impossible anyway...
#-- eg: https://www.acunetix.com/blog/articles/detection-prevention-introduction-web-shells-part-5/
#-- "freemarker" should be OK, should not be used in Freemarker templates, not part of the syntax.
#-- Else "template.utility.Execute" is a good replacement but not as much catching, who knows...
deniedWebShellTokens=freemarker,import=\"java,runtime.getruntime().exec(,<%@ page,<script,<body>,<form,php,\
javascript,%eval,@eval,import os,passthru,exec,shell_exec,assert,str_rot13,system,phpinfo,base64_decode,chmod,mkdir,\
fopen,fclose,new file,import,upload,getfilename,download,getoutputstring,readfile
#-- If you need to use localhost or 127.0.0.1 in textareas URLs then you can uncomment the allowedProtocols property, here given as an example
#-- You may also put other protocols you want to use, instead or with those
@@ -34,6 +34,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -60,8 +61,12 @@ import org.apache.commons.imaging.formats.jpeg.JpegImageParser;
import org.apache.commons.imaging.formats.png.PngImageParser;
import org.apache.commons.imaging.formats.tiff.TiffImageParser;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.ofbiz.base.util.Debug;
import org.apache.ofbiz.base.util.FileUtil;
import org.apache.ofbiz.base.util.StringUtil;
import org.apache.ofbiz.base.util.UtilProperties;
import org.apache.ofbiz.base.util.UtilValidate;
import org.apache.ofbiz.entity.Delegator;
import org.apache.ofbiz.entity.util.EntityUtilProperties;
import org.apache.pdfbox.pdmodel.PDDocument;
@@ -91,6 +96,8 @@ public class SecuredUpload {
// Line #-- UPLOAD: supported file formats are *safe* PNG, GIF, TIFF, JPEG, PDF, Audio and Video and ZIP
private static final String MODULE = SecuredUpload.class.getName();
private static final List<String> DENIEDFILEEXTENSIONS = deniedFileExtensions();
private static final List<String> DENIEDWEBSHELLTOKENS = deniedWebShellTokens();
/**
* @param fileToCheck
@@ -107,28 +114,33 @@ public class SecuredUpload {
String imageServerUrl = EntityUtilProperties.getPropertyValue("catalog", "image.management.url", delegator);
Path p = Paths.get(fileToCheck);
String file = p.getFileName().toString();
String fileName = p.getFileName().toString(); // The file name is the farthest element from the root in the directory hierarchy.
boolean wrongFile = true;
if (DENIEDFILEEXTENSIONS.contains(FilenameUtils.getExtension(fileToCheck))) {
Debug.logError("This file extension is not allowed for security reason", MODULE);
deleteBadFile(fileToCheck);
return false;
}
if (org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS) {
if (fileToCheck.length() > 259) {
if (fileToCheck.length() > 259) { // More about that: https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
Debug.logError("Uploaded file name too long", MODULE);
return false;
} else if (p.toString().contains(imageServerUrl.replaceAll("/", "\\\\"))) {
if (file.matches("[a-zA-Z0-9-_ ()]{1,249}.[a-zA-Z0-9-_ ]{1,10}")) { // "(" and ")" for duplicates files
if (fileName.matches("[a-zA-Z0-9-_ ()]{1,249}.[a-zA-Z0-9-_ ]{1,10}")) { // "(" and ")" for duplicates files
wrongFile = false;
}
} else if (file.matches("[a-zA-Z0-9-_ ]{1,249}.[a-zA-Z0-9-_ ]{1,10}")) {
} else if (fileName.matches("[a-zA-Z0-9-_ ]{1,249}.[a-zA-Z0-9-_ ]{1,10}")) {
wrongFile = false;
}
} else { // Suppose a *nix system
if (fileToCheck.length() > 4096) {
Debug.logError("Uploaded file name too long", MODULE);
return false;
} else if (p.toString().contains(imageServerUrl)) {
if (file.matches("[a-zA-Z0-9-_ ()]{1,4086}.[a-zA-Z0-9-_ ]{1,10}")) { // "(" and ")" for duplicates files
if (fileName.matches("[a-zA-Z0-9-_ ()]{1,4086}.[a-zA-Z0-9-_ ]{1,10}")) { // "(" and ")" for duplicates files
wrongFile = false;
}
} else if (file.matches("[a-zA-Z0-9-_ ]{1,4086}.[a-zA-Z0-9-_ ]{1,10}")) {
} else if (fileName.matches("[a-zA-Z0-9-_ ]{1,4086}.[a-zA-Z0-9-_ ]{1,10}")) {
wrongFile = false;
}
}
@@ -139,10 +151,12 @@ public class SecuredUpload {
+ " only 1 dot as an input for the file name and the extension."
+ "The file name and extension should not be empty at all",
MODULE);
deleteBadFile(fileToCheck);
return false;
}
if (isExecutable(fileToCheck)) {
deleteBadFile(fileToCheck);
return false;
}
@@ -210,11 +224,7 @@ public class SecuredUpload {
}
break;
}
Debug.logError("File :" + fileToCheck + ", can't be uploaded for security reason", MODULE);
File badFile = new File(fileToCheck);
if (!badFile.delete()) {
Debug.logError("File :" + fileToCheck + ", couldn't be deleted", MODULE);
}
deleteBadFile(fileToCheck);
return false;
}
@@ -606,40 +616,33 @@ public class SecuredUpload {
return false;
}
String content = new String(bytesFromFile);
return !(content.toLowerCase().contains("freemarker") // Should be OK, should not be used in Freemarker templates, not part of the syntax.
// Else "template.utility.Execute" is a good replacement but not as much catching, who
// knows...
|| content.toLowerCase().contains("import=\"java")
|| content.toLowerCase().contains("runtime.getruntime().exec(")
|| content.toLowerCase().contains("<%@ page")
|| content.toLowerCase().contains("<script")
|| content.toLowerCase().contains("<body>")
|| content.toLowerCase().contains("<form")
|| content.toLowerCase().contains("php")
|| content.toLowerCase().contains("javascript")
|| content.toLowerCase().contains("%eval")
|| content.toLowerCase().contains("@eval")
|| content.toLowerCase().contains("import os") // Python
|| content.toLowerCase().contains("passthru")
|| content.toLowerCase().contains("exec")
|| content.toLowerCase().contains("shell_exec")
|| content.toLowerCase().contains("assert")
|| content.toLowerCase().contains("str_rot13")
|| content.toLowerCase().contains("system")
|| content.toLowerCase().contains("phpinfo")
|| content.toLowerCase().contains("base64_decode")
|| content.toLowerCase().contains("chmod")
|| content.toLowerCase().contains("mkdir")
|| content.toLowerCase().contains("fopen")
|| content.toLowerCase().contains("fclose")
|| content.toLowerCase().contains("new file")
|| content.toLowerCase().contains("import")
|| content.toLowerCase().contains("upload")
|| content.toLowerCase().contains("getfilename")
|| content.toLowerCase().contains("download")
|| content.toLowerCase().contains("getoutputstring")
|| content.toLowerCase().contains("readfile"));
// TODO.... to be continued with known webshell contents... a complete allow list is impossible anyway...
// eg: https://www.acunetix.com/blog/articles/detection-prevention-introduction-web-shells-part-5/
ArrayList<String> allowed = new ArrayList<>();
return isValidText(content, allowed);
}
public static boolean isValidText(String content, List<String> allowed) throws IOException {
return DENIEDWEBSHELLTOKENS.stream().allMatch(token -> isValid(content, token, allowed));
}
private static boolean isValid(String content, String string, List<String> allowed) {
return !content.toLowerCase().contains(string) || allowed.contains(string);
}
private static void deleteBadFile(String fileToCheck) {
Debug.logError("File :" + fileToCheck + ", can't be uploaded for security reason", MODULE);
File badFile = new File(fileToCheck);
if (!badFile.delete()) {
Debug.logError("File :" + fileToCheck + ", couldn't be deleted", MODULE);
}
}
private static List<String> deniedFileExtensions() {
String deniedExtensions = UtilProperties.getPropertyValue("security", "deniedFileExtensions");
return UtilValidate.isNotEmpty(deniedExtensions) ? StringUtil.split(deniedExtensions, ",") : new ArrayList<>();
}
private static List<String> deniedWebShellTokens() {
String deniedTokens = UtilProperties.getPropertyValue("security", "deniedWebShellTokens");
return UtilValidate.isNotEmpty(deniedTokens) ? StringUtil.split(deniedTokens, ",") : new ArrayList<>();
}
}
+4 -3
View File
@@ -66,11 +66,12 @@ under the License.
<test-case case-name="service-eca-global-event-exec-assert-data">
<entity-xml action="assert" entity-xml-url="component://service/testdef/data/ServiceEcaGlobalEventAssertData.xml"/>
</test-case>
<test-case case-name="service-xml-rpc">
<!-- This alone should allow Buildbot 3.2 to run the integration tests, cf OFBIZ-12456 -->
<!-- <test-case case-name="service-xml-rpc">
<junit-test-suite class-name="org.apache.ofbiz.service.test.XmlRpcTests"/>
</test-case>
<test-case case-name="service-xml-rpc-local-engine">
<service-test service-name="testXmlRpcClientAdd"/>
</test-case>
</test-case!-->
</test-suite>
@@ -134,7 +134,7 @@ public class ContextFilter implements Filter {
if(UtilValidate.isNotEmpty(tenantDomainName)) {
tenantId = tenantDomainName.getString("tenantId");
}
if(UtilValidate.isEmpty(tenantId)) {
tenantId = (String) httpRequest.getAttribute("userTenantId");
}
@@ -173,14 +173,14 @@ public class ContextFilter implements Filter {
request.setAttribute("delegator", delegator);
request.setAttribute("dispatcher", dispatcher);
request.setAttribute("security", security);
request.setAttribute("userTenantId", tenantId);
}
// NOTE DEJ20101130: do NOT always put the delegator name in the user's session because the user may
// have logged in and specified a tenant, and even if no Tenant record with a matching domainName field
// is found this will change the user's delegator back to the base one instead of the one for the
// tenant specified on login
// NOTE DEJ20101130: do NOT always put the delegator name in the user's session because the user may
// have logged in and specified a tenant, and even if no Tenant record with a matching domainName field
// is found this will change the user's delegator back to the base one instead of the one for the
// tenant specified on login
// httpRequest.getSession().setAttribute("delegatorName", delegator.getDelegatorName());
} catch (GenericEntityException e) {
Debug.logWarning(e, "Unable to get Tenant", module);
@@ -30,9 +30,9 @@ import org.apache.ofbiz.webapp.control.ConfigXMLReader.Event;
import org.apache.ofbiz.webapp.control.ConfigXMLReader.RequestMap;
import org.apache.ofbiz.webapp.control.RequestHandler;
import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.WireFeedOutput;
import com.rometools.rome.feed.WireFeed;
import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.WireFeedOutput;
/**
* RomeEventHandler
@@ -17,12 +17,16 @@
* under the License.
*/
import org.apache.ofbiz.entity.Delegator
import org.apache.ofbiz.webtools.artifactinfo.*
import org.apache.ofbiz.base.util.*
import org.apache.ofbiz.base.util.Debug
import org.apache.ofbiz.base.util.UtilURL
import org.apache.ofbiz.webtools.artifactinfo.ArtifactInfoFactory
name = parameters.name
location = parameters.location
if (UtilURL.fromUrlString(location)) {
Debug.logError("For security reason HTTP URLs are not accepted, see OFBIZ-12306", "ArtifactInfo.groovy")
return
}
type = parameters.type
uniqueId = parameters.uniqueId
delegatorName = delegator.getDelegatorName()
@@ -20,6 +20,7 @@ import org.apache.ofbiz.entity.Delegator
import org.apache.ofbiz.entity.GenericValue
import org.apache.ofbiz.entity.model.ModelEntity
import org.apache.ofbiz.base.util.*
import org.w3c.dom.Document
import org.codehaus.groovy.control.customizers.ImportCustomizer
@@ -31,8 +32,7 @@ String groovyProgram = null
recordValues = []
errMsgList = []
if (UtilValidate.isEmpty(parameters.groovyProgram)) {
if (!parameters.groovyProgram) {
groovyProgram = '''
// Use the List variable recordValues to fill it with GenericValue maps.
// full groovy syntaxt is available
@@ -73,10 +73,7 @@ def shell = new GroovyShell(loader, binding, configuration)
if (UtilValidate.isNotEmpty(groovyProgram)) {
try {
// TODO more can be added...
if (groovyProgram.contains("new File")
|| groovyProgram.contains(".jsp")
|| groovyProgram.contains("<%=")) {
if (!org.apache.ofbiz.security.SecuredUpload.isValidText(groovyProgram,["import"])) {
request.setAttribute("_ERROR_MESSAGE_", "Not executed for security reason")
return
}
@@ -143,6 +143,11 @@ public class WebToolsServices {
// #############################
// FM Template
// #############################
if (UtilValidate.urlInString(fulltext)) {
Debug.logError("For security reason HTTP URLs are not accepted, see OFBIZ-12304", module);
Debug.logInfo("Rather load your data from a file", module);
return null;
}
if (UtilValidate.isNotEmpty(fmfilename) && (UtilValidate.isNotEmpty(fulltext) || url != null)) {
File fmFile = new File(fmfilename);
if (!fmFile.exists()) {
@@ -58,6 +58,11 @@ under the License.
<param-value>/control/main</param-value>
</init-param>
</filter>
<filter>
<display-name>CacheFilter</display-name>
<filter-name>CacheFilter</filter-name>
<filter-class>org.apache.ofbiz.base.util.CacheFilter</filter-class>
</filter>
<filter>
<display-name>ContextFilter</display-name>
<filter-name>ContextFilter</filter-name>
@@ -72,6 +77,10 @@ under the License.
<filter-name>ControlFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CacheFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ContextFilter</filter-name>
<url-pattern>/*</url-pattern>