From 0bd172fafc8a052ae7b1305f4bee752ee8aa863a Mon Sep 17 00:00:00 2001 From: Jacques Le Roux Date: Tue, 10 Nov 2015 13:40:22 +0000 Subject: [PATCH] Completes r1709882 for <> https://issues.apache.org/jira/browse/OFBIZ-6669 As explained in OFBIZ-6669 last comments, contrary to what I did in ContentWorker class, when I before did the work on *ContentWrapper classes I did not use the sanitizer but only an encoder (either HTML or URL). Because I wrongly supposed that only plain text was used there and certainly my lazy mind thought it was easier because of the URL encoderType to also handle. When the encoderType is HTML, we now use the sanitizer in *ContentWrapper classes, and ContentWorker.java has also been adapted. For that I enhanced the UtilCodec class. The sanitizer is only used when HTML is requested, else the sanitize() method simply calls the encode() method. I removed the content.sanitize property in content.properties and added a sanitizer.permissive.policy property in the new owasp.properties (in base config) with some explanations. This allows for more configuration. I changed the line 85 in productsummary.ftl to use an HTML content wrapper, same in minilastviewedcategories.ftl. To be totally complete, we should change *lines like* in productsummary.ftl line 85 to use an HTML content wrapper. Not easy to spot but anyway those not done will simply not totally show well, without any security impacts. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1713634 13f79535-47bb-0310-9956-ffa450edef68 --- .../content/config/content.properties | 6 +- .../ofbiz/content/content/ContentWorker.java | 13 ++--- .../order/order/OrderContentWrapper.java | 2 +- .../ordermgr/entry/catalog/productsummary.ftl | 2 +- .../party/content/PartyContentWrapper.java | 6 +- .../category/CategoryContentWrapper.java | 2 +- .../ProductConfigItemContentWrapper.java | 6 +- .../product/ProductContentWrapper.java | 6 +- .../product/ProductPromoContentWrapper.java | 6 +- .../content/WorkEffortContentWrapper.java | 6 +- framework/base/config/owasp.properties | 28 ++++++++++ .../src/org/ofbiz/base/util/UtilCodec.java | 56 +++++++++++++++---- .../catalog/minilastviewedcategories.ftl | 2 +- 13 files changed, 98 insertions(+), 43 deletions(-) create mode 100644 framework/base/config/owasp.properties diff --git a/applications/content/config/content.properties b/applications/content/config/content.properties index ae6da3868b..18851787fe 100644 --- a/applications/content/config/content.properties +++ b/applications/content/config/content.properties @@ -34,8 +34,4 @@ content.upload.max.files=250 content.upload.always.local.file=true # content output folder (relative to ofbiz.home) -content.output.path=runtime/output - -#Should we sanitize generic content by default (specific contents - order, party, category, product, configured product, product promo and work effort - are always encoded) -# This has a slightly impact on the code rendered, see OFBIZ-6669. True By default! -content.sanitize=true +content.output.path=runtime/output \ No newline at end of file diff --git a/applications/content/src/org/ofbiz/content/content/ContentWorker.java b/applications/content/src/org/ofbiz/content/content/ContentWorker.java index 2e6e35b5e6..57abf94625 100644 --- a/applications/content/src/org/ofbiz/content/content/ContentWorker.java +++ b/applications/content/src/org/ofbiz/content/content/ContentWorker.java @@ -35,6 +35,7 @@ import org.ofbiz.base.util.BshUtil; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.StringUtil; +import org.ofbiz.base.util.UtilCodec; import org.ofbiz.base.util.UtilDateTime; import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilMisc; @@ -52,7 +53,6 @@ import org.ofbiz.entity.condition.EntityExpr; import org.ofbiz.entity.condition.EntityOperator; import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; -import org.ofbiz.entity.util.EntityUtilProperties; import org.ofbiz.minilang.MiniLangException; import org.ofbiz.minilang.SimpleMapProcessor; import org.ofbiz.service.DispatchContext; @@ -60,8 +60,6 @@ import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ModelService; import org.ofbiz.service.ServiceUtil; -import org.owasp.html.PolicyFactory; -import org.owasp.html.Sanitizers; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -74,6 +72,7 @@ import freemarker.ext.dom.NodeModel; public class ContentWorker implements org.ofbiz.widget.content.ContentWorkerInterface { public static final String module = ContentWorker.class.getName(); + static final UtilCodec.SimpleEncoder encoder = UtilCodec.getEncoder("html"); public ContentWorker() { } @@ -339,8 +338,7 @@ public class ContentWorker implements org.ofbiz.widget.content.ContentWorkerInte String rendered = writer.toString(); // According to https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet#XSS_Prevention_Rules_Summary // Normally head should be protected by X-XSS-Protection Response Header by default - if (EntityUtilProperties.propertyValueEqualsIgnoreCase("content.properties", "content.sanitize", "true", delegator) - && (rendered.contains("