diff --git a/applications/accounting/servicedef/services_agreement.xml b/applications/accounting/servicedef/services_agreement.xml index db95685198..a409b7cccc 100644 --- a/applications/accounting/servicedef/services_agreement.xml +++ b/applications/accounting/servicedef/services_agreement.xml @@ -29,14 +29,14 @@ under the License. - + Update an Agreement - + Expire an Agreement @@ -60,7 +60,7 @@ under the License. - + @@ -68,7 +68,7 @@ under the License. - + Remove an AgreementItem @@ -102,14 +102,14 @@ under the License. - + Update an AgreementTerm - + Delete an AgreementTerm diff --git a/applications/accounting/servicedef/services_invoice.xml b/applications/accounting/servicedef/services_invoice.xml index 33cbc32789..90dd66f090 100644 --- a/applications/accounting/servicedef/services_invoice.xml +++ b/applications/accounting/servicedef/services_invoice.xml @@ -56,8 +56,8 @@ under the License. - - + + @@ -80,8 +80,8 @@ under the License. - - + + @@ -117,7 +117,7 @@ under the License. - + @@ -125,7 +125,7 @@ under the License. - + @@ -429,7 +429,7 @@ under the License. - + @@ -439,7 +439,7 @@ under the License. - + diff --git a/applications/content/servicedef/services.xml b/applications/content/servicedef/services.xml index d0f6dd5b90..7b4392e2e4 100644 --- a/applications/content/servicedef/services.xml +++ b/applications/content/servicedef/services.xml @@ -189,7 +189,7 @@ - + @@ -199,7 +199,7 @@ - + @@ -367,7 +367,7 @@ - + - - + + @@ -1121,8 +1121,8 @@ - - + + diff --git a/applications/content/servicedef/services_content.xml b/applications/content/servicedef/services_content.xml index 2aa6be1839..d38165b733 100644 --- a/applications/content/servicedef/services_content.xml +++ b/applications/content/servicedef/services_content.xml @@ -39,8 +39,8 @@ - - + + - - - + + + diff --git a/applications/content/servicedef/services_data.xml b/applications/content/servicedef/services_data.xml index 7c99b47911..46252537cc 100644 --- a/applications/content/servicedef/services_data.xml +++ b/applications/content/servicedef/services_data.xml @@ -37,8 +37,8 @@ - - + + @@ -61,8 +61,8 @@ - - + + Remove DataResource @@ -91,7 +91,7 @@ Create a DataResource and, possibly, ElectronicText or ImageDataResource - + @@ -101,7 +101,7 @@ Create a DataResource and, possibly, ElectronicText or ImageDataResource - + @@ -115,7 +115,7 @@ - + Update a ElectronicText @@ -123,7 +123,7 @@ - + diff --git a/applications/marketing/servicedef/services_opportunity.xml b/applications/marketing/servicedef/services_opportunity.xml index cce2c81fd2..73ce5ab9d8 100644 --- a/applications/marketing/servicedef/services_opportunity.xml +++ b/applications/marketing/servicedef/services_opportunity.xml @@ -72,9 +72,9 @@ under the License. - - - + + + Update an sales opportunity @@ -82,9 +82,9 @@ under the License. - - - + + + Create sales opportunity role diff --git a/applications/order/servicedef/services.xml b/applications/order/servicedef/services.xml index 0429b56cbd..b05d0f24c4 100644 --- a/applications/order/servicedef/services.xml +++ b/applications/order/servicedef/services.xml @@ -438,7 +438,7 @@ under the License. location="org.apache.ofbiz.order.order.OrderServices" invoke="createOrderNote" auth="true"> Create a note item and associate with a order header - + diff --git a/applications/order/servicedef/services_quote.xml b/applications/order/servicedef/services_quote.xml index ed269139fe..0d0f507c98 100644 --- a/applications/order/servicedef/services_quote.xml +++ b/applications/order/servicedef/services_quote.xml @@ -309,7 +309,7 @@ under the License. location="component://order/groovyScripts/quote/QuoteServices.groovy" invoke="createQuoteNote" auth="true"> Create a note item and associate with a quote - + diff --git a/applications/order/servicedef/services_request.xml b/applications/order/servicedef/services_request.xml index b5aaa1b470..24db8efe06 100644 --- a/applications/order/servicedef/services_request.xml +++ b/applications/order/servicedef/services_request.xml @@ -42,9 +42,9 @@ under the License. - - - + + + @@ -52,10 +52,10 @@ under the License. - + - - + + - - + + Update a CustRequestItem record - - + + @@ -134,7 +134,7 @@ under the License. location="component://order/minilang/request/CustRequestServices.xml" invoke="createCustRequestNote" auth="true"> Create a note for a CustRequest - + @@ -143,7 +143,7 @@ under the License. location="component://order/minilang/request/CustRequestServices.xml" invoke="updateCustRequestNote" auth="true"> Update CustRequest Note - + Create a note for a CustRequestItem - + @@ -183,7 +183,7 @@ under the License. Set the Customer Request Status - + @@ -197,8 +197,8 @@ under the License. - - + + diff --git a/applications/party/servicedef/services.xml b/applications/party/servicedef/services.xml index 33576b6bd9..8f91b16aa3 100644 --- a/applications/party/servicedef/services.xml +++ b/applications/party/servicedef/services.xml @@ -114,7 +114,7 @@ under the License. - + @@ -127,7 +127,7 @@ under the License. - + create a company/contact relationship and add the related roles - + @@ -780,7 +780,7 @@ under the License. - + @@ -804,7 +804,7 @@ under the License. - + diff --git a/applications/product/servicedef/services.xml b/applications/product/servicedef/services.xml index bb69a400b2..3458698725 100644 --- a/applications/product/servicedef/services.xml +++ b/applications/product/servicedef/services.xml @@ -34,8 +34,8 @@ under the License. - - + + @@ -70,8 +70,8 @@ under the License. - - + + @@ -387,7 +387,7 @@ under the License. - + - + @@ -426,7 +426,7 @@ under the License. - + @@ -436,13 +436,13 @@ under the License. - + - + @@ -940,7 +940,7 @@ under the License. - + @@ -950,7 +950,7 @@ under the License. - + - + - + diff --git a/applications/product/servicedef/services_pricepromo.xml b/applications/product/servicedef/services_pricepromo.xml index e7ef1838c0..86bbdb8679 100644 --- a/applications/product/servicedef/services_pricepromo.xml +++ b/applications/product/servicedef/services_pricepromo.xml @@ -132,7 +132,7 @@ under the License. - + @@ -140,7 +140,7 @@ under the License. - + diff --git a/applications/workeffort/servicedef/services.xml b/applications/workeffort/servicedef/services.xml index d5b4a26c11..e89cfce35e 100644 --- a/applications/workeffort/servicedef/services.xml +++ b/applications/workeffort/servicedef/services.xml @@ -35,8 +35,8 @@ under the License. - - + + @@ -50,9 +50,9 @@ under the License. - + - + @@ -783,7 +783,7 @@ under the License. - + Deletes a CustRequestWorkEffort diff --git a/framework/base/config/owasp.properties b/framework/base/config/owasp.properties index 5ead4697a4..4bb7fdc716 100644 --- a/framework/base/config/owasp.properties +++ b/framework/base/config/owasp.properties @@ -24,10 +24,14 @@ # By default we use a permissive sanitizer policy # This has a slight impact on the code rendered, see last comments in OFBIZ-6669. # Given as an example based on rendering cmssite, as it was before using the sanitizer. -# You might even want to adapt the PERMISSIVE_POLICY to your needs. +# You might want to adapt the PERMISSIVE_POLICY to your needs. # Be sure to check https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet before... - -# Use sanitizer.permissive.policy=CUSTOM to use your custom PolicyFactory sanitizer.enable=true + +# Use sanitizer.permissive.policy=CUSTOM to use your custom permissive PolicyFactory (see OFBIZ-10187) sanitizer.permissive.policy=DEFAULT -sanitizer.custom.policy.class=org.apache.ofbiz.base.html.CustomPermissivePolicy \ No newline at end of file +sanitizer.custom.permissive.policy.class=org.apache.ofbiz.base.html.CustomPermissivePolicy + +# Use sanitizer.safe.policy=CUSTOM to use your custom safe PolicyFactory (see OFBIZ-5254) +sanitizer.safe.policy=DEFAULT +sanitizer.custom.safe.policy.class=org.apache.ofbiz.base.html.CustomSafePolicy \ No newline at end of file diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/html/CustomSafePolicy.java b/framework/base/src/main/java/org/apache/ofbiz/base/html/CustomSafePolicy.java new file mode 100644 index 0000000000..ba8df515f1 --- /dev/null +++ b/framework/base/src/main/java/org/apache/ofbiz/base/html/CustomSafePolicy.java @@ -0,0 +1,53 @@ +package org.apache.ofbiz.base.html; + +import java.util.regex.Pattern; + +import org.owasp.html.HtmlPolicyBuilder; +import org.owasp.html.PolicyFactory; + +/** + * Based on the + * AntiSamy Slashdot example. + * Slashdot (http://www.slashdot.org/) is a techie news site that allows users + * to respond anonymously to news posts with very limited HTML markup. Now + * Slashdot is not only one of the coolest sites around, it's also one that's + * been subject to many different successful attacks. Even more unfortunate is + * the fact that most of the attacks led users to the infamous goatse.cx picture + * (please don't go look it up). The rules for Slashdot are fairly strict: users + * can only submit the following HTML tags and no CSS: {@code }, {@code }, + * {@code }, {@code }, {@code
}. + * + * Accordingly, we've built a policy file that allows fairly similar + * functionality. All text-formatting tags that operate directly on the font, + * color or emphasis have been allowed. + */ +public class CustomSafePolicy implements SanitizerCustomPolicy { + + /** + * A policy that can be used to produce policies that sanitize to HTML sinks via + * {@link PolicyFactory#apply}. + */ + public static final PolicyFactory POLICY_DEFINITION = new HtmlPolicyBuilder() + .allowStandardUrlProtocols() + // Allow title="..." on any element. + .allowAttributes("title").globally() + // Allow href="..." on elements. + .allowAttributes("href").onElements("a") + // Defeat link spammers. + .requireRelNofollowOnLinks() + // Allow lang= with an alphabetic value on any element. + .allowAttributes("lang").matching(Pattern.compile("[a-zA-Z]{2,20}")) + .globally() + // The align attribute on

elements can have any value below. + .allowAttributes("align") + .matching(true, "center", "left", "right", "justify", "char") + .onElements("p") + // These elements are allowed. + .allowElements("a", "p", "div", "i", "b", "em", "blockquote", "tt", "strong","br", "ul", "ol", "li") + .toFactory(); + + @Override + public PolicyFactory getSanitizerPolicy() { + return POLICY_DEFINITION; + } +} diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilCodec.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilCodec.java index a2272e059d..8ad74ba1ae 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilCodec.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilCodec.java @@ -29,6 +29,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -116,8 +117,8 @@ public class UtilCodec { * This method will start a configurable sanitizing process. The sanitizer can * be turns off through "sanitizer.enable=false", the default value is true. It * is possible to configure a custom policy using the properties - * "sanitizer.permissive.policy" and "sanitizer.custom.policy.class". The custom - * policy has to implement + * "sanitizer.permissive.policy" and "sanitizer.custom.permissive.policy.class". + * The custom policy has to implement * {@link org.apache.ofbiz.base.html.SanitizerCustomPolicy}. * * @param original @@ -143,7 +144,7 @@ public class UtilCodec { PolicyFactory policy = null; try { Class customPolicyClass = Class.forName(UtilProperties.getPropertyValue("owasp", - "sanitizer.custom.policy.class")); + "sanitizer.custom.permissive.policy.class")); Object obj = customPolicyClass.newInstance(); if (SanitizerCustomPolicy.class.isAssignableFrom(customPolicyClass)) { Method meth = customPolicyClass.getMethod("getSanitizerPolicy"); @@ -153,7 +154,7 @@ public class UtilCodec { | InvocationTargetException | NoSuchMethodException | SecurityException | InstantiationException e) { // Just logging the error and falling back to default policy - Debug.logError(e, "Could not find custom sanitizer policy. Using default instead", module); + Debug.logError(e, "Could not find custom permissive sanitizer policy. Using default instead", module); } if (policy != null) { @@ -355,43 +356,67 @@ public class UtilCodec { /** * Uses a black-list approach for necessary characters for HTML. - *

* Does not allow various characters (after canonicalization), including - * "<", ">", "&" (if not followed by a space), and "%" (if not - * followed by a space). + * "<", ">", "&" and "%" (if not followed by a space). * - * @param value - * @param errorMessageList + * @param valueName field name checked + * @param value value checked + * @param errorMessageList an empty list passed by and modified in case of issues + * @param locale */ - public static String checkStringForHtmlStrictNone(String valueName, String value, List errorMessageList) { + public static String checkStringForHtmlStrictNone(String valueName, String value, List errorMessageList, + Locale locale) { if (UtilValidate.isEmpty(value)) { return value; } + // canonicalize, strict (error on double-encoding) try { value = canonicalize(value, true); } catch (IntrusionException e) { // NOTE: using different log and user targeted error messages to allow the end-user message to be less technical - Debug.logError("Canonicalization (format consistency, character escaping that is mixed or double, etc) error for attribute named [" + valueName + "], String [" + value + "]: " + e.toString(), module); - errorMessageList.add("In field [" + valueName + "] found character escaping (mixed or double) that is not allowed or other format consistency error: " + e.toString()); + Debug.logError("Canonicalization (format consistency, character escaping that is mixed or double, etc) " + + "error for attribute named [" + valueName + "], String [" + value + "]: " + e.toString(), module); + String issueMsg = null; + if (locale.equals(new Locale("test"))) { // labels are not available in testClasses Gradle task + issueMsg = "In field [" + valueName + "] found character escaping (mixed or double) " + + "that is not allowed or other format consistency error: "; + } else { + issueMsg = UtilProperties.getMessage("SecurityUiLabels","PolicyNoneMixedOrDouble", + UtilMisc.toMap("valueName", valueName), locale); + } + errorMessageList.add(issueMsg + e.toString()); } // check for "<", ">" if (value.indexOf("<") >= 0 || value.indexOf(">") >= 0) { - errorMessageList.add("In field [" + valueName + "] less-than (<) and greater-than (>) symbols are not allowed."); + String issueMsg = null; + if (locale.equals(new Locale("test"))) { + issueMsg = "In field [" + valueName + "] less-than (<) and greater-than (>) symbols are not allowed."; + } else { + issueMsg = UtilProperties.getMessage("SecurityUiLabels","PolicyNoneLess-thanGreater-than", + UtilMisc.toMap("valueName", valueName), locale); + } + errorMessageList.add(issueMsg); } // check for js events - final String onEvent = "on" + StringUtils.substringBetween(value, " on", "="); - final boolean seekSegmentTime = value.contains("seekSegmentTime"); - if (null != onEvent || seekSegmentTime) { - if (jsEventList.stream().anyMatch(str -> StringUtils.containsIgnoreCase(str, onEvent)) || seekSegmentTime) { - errorMessageList.add("In field [" + valueName + "] js events are not allowed."); + String onEvent = "on" + StringUtils.substringBetween(value, " on", "="); + if (jsEventList.stream().anyMatch(str -> StringUtils.containsIgnoreCase(str, onEvent)) + || value.contains("seekSegmentTime")) { + String issueMsg = null; + if (locale.equals(new Locale("test"))) { + issueMsg = "In field [" + valueName + "] Javascript events are not allowed."; + } else { + issueMsg = UtilProperties.getMessage("SecurityUiLabels","PolicyNoneJsEvents", + UtilMisc.toMap("valueName", valueName), locale); } + errorMessageList.add(issueMsg); } // TODO: anything else to check for that can be used to get HTML or JavaScript going without these characters? + // // Another would be https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#US-ASCII_encoding // But all our Tomcat connectors use UTF-8 // We don't care about Flash now rather deprecated @@ -401,7 +426,59 @@ public class UtilCodec { } /** - * A simple Map wrapper class that will do HTML encoding. To be used for passing a Map to something that will expand Strings with it as a context, etc. + * This method check if the input is safe HTML. + * It is possible to configure a safe policy using the properties + * "sanitizer.safe.policy" and "sanitizer.custom.safe.policy.class". + * The safe policy has to implement + * {@link org.apache.ofbiz.base.html.SanitizerCustomPolicy}. + * + * @param valueName field name checked + * @param value value checked + * @param errorMessageList an empty list passed by and modified in case of issues + * @param locale + */ + public static String checkStringForHtmlSafe(String valueName, String value, List errorMessageList, + Locale locale) { + PolicyFactory policy = null; + try { + Class customPolicyClass = null; + if (locale.equals(new Locale("test"))) { + customPolicyClass = Class.forName("org.apache.ofbiz.base.html.CustomSafePolicy"); + } else { + customPolicyClass = Class.forName(UtilProperties.getPropertyValue("owasp", + "sanitizer.custom.safe.policy.class")); + } + Object obj = customPolicyClass.newInstance(); + if (SanitizerCustomPolicy.class.isAssignableFrom(customPolicyClass)) { + Method meth = customPolicyClass.getMethod("getSanitizerPolicy"); + policy = (PolicyFactory) meth.invoke(obj); + } + } catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException | NoSuchMethodException | SecurityException + | InstantiationException e) { + Debug.logError(e, "Could not find custom safe sanitizer policy. Using default instead." + + "Beware: the result is not rightly checked!", module); + } + + String filtered = policy.sanitize(value); + if (!value.equals(filtered)) { + String issueMsg = null; + if (locale.equals(new Locale("test"))) { + issueMsg = "In field [" + valueName + "] by our input policy, your input has not been accepted " + + "for security reason. Please check and modify accordingly, thanks."; + } else { + issueMsg = UtilProperties.getMessage("SecurityUiLabels","PolicySafe", + UtilMisc.toMap("valueName", valueName), locale); + } + errorMessageList.add(issueMsg); + } + + return value; + } + + /** + * A simple Map wrapper class that will do HTML encoding. + * To be used for passing a Map to something that will expand Strings with it as a context, etc. */ public static class HtmlEncodingMapWrapper implements Map { public static HtmlEncodingMapWrapper getHtmlEncodingMapWrapper(Map mapToWrap, SimpleEncoder encoder) { diff --git a/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilCodecTests.java b/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilCodecTests.java index d59a0fa0bd..4eea54f2b6 100644 --- a/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilCodecTests.java +++ b/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilCodecTests.java @@ -24,6 +24,7 @@ import static org.junit.Assert.assertNull; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Locale; import org.junit.Test; @@ -40,7 +41,7 @@ public class UtilCodecTests { public void checkStringForHtmlStrictNoneDetectsXSS() { String xssVector = "<script>alert(\"XSS vector\");</script>"; List errorList = new ArrayList<>(); - String canonicalizedXssVector = UtilCodec.checkStringForHtmlStrictNone("fieldName", xssVector, errorList); + String canonicalizedXssVector = UtilCodec.checkStringForHtmlStrictNone("fieldName", xssVector, errorList, new Locale("test")); assertEquals("", canonicalizedXssVector); assertEquals(1, errorList.size()); assertEquals("In field [fieldName] less-than (<) and greater-than (>) symbols are not allowed.", errorList.get(0)); @@ -70,6 +71,7 @@ public class UtilCodecTests { // jacopoc: temporarily commented because this test is failing after the upgrade of owasp-esapi (still investigating) //checkStringForHtmlStrictNone_test("double-ampersand", "f\";oo", "f%26quot%3boo"); checkStringForHtmlStrictNone_test("double-encoding", "%2%353Cscript", "%2%353Cscript", "In field [double-encoding] found character escaping (mixed or double) that is not allowed or other format consistency error: org.apache.ofbiz.base.util.UtilCodec$IntrusionException: Input validation failure"); + checkStringForHtmlStrictNone_test("js_event", "non_existent.foo\" onerror=\"alert('Hi!');", "non_existent.foo\" onerror=\"alert('Hi!');", "In field [js_event] Javascript events are not allowed."); } private static void encoderTest(String label, UtilCodec.SimpleEncoder encoder, String wanted, String toEncode) { @@ -78,8 +80,21 @@ public class UtilCodecTests { } private static void checkStringForHtmlStrictNone_test(String label, String fixed, String input, String... wantedMessages) { List gottenMessages = new ArrayList(); - assertEquals(label, fixed, UtilCodec.checkStringForHtmlStrictNone(label, input, gottenMessages)); + assertEquals(label, fixed, UtilCodec.checkStringForHtmlStrictNone(label, input, gottenMessages, new Locale("test"))); assertEquals(label, Arrays.asList(wantedMessages), gottenMessages); } + + @Test + public void testCheckStringForHtmlSafe() { + String xssVector = ""; + List errorList = new ArrayList<>(); + String canonicalizedXssVector = UtilCodec.checkStringForHtmlSafe("fieldName", xssVector, errorList, new Locale("test")); + assertEquals("", canonicalizedXssVector); + assertEquals(1, errorList.size()); + assertEquals("In field [fieldName] by our input policy, your input has not been accepted for security reason. " + + "Please check and modify accordingly, thanks.", errorList.get(0)); + } + + } diff --git a/framework/common/config/SecurityUiLabels.xml b/framework/common/config/SecurityUiLabels.xml index 1b3999a9f7..3a7a6d8da5 100644 --- a/framework/common/config/SecurityUiLabels.xml +++ b/framework/common/config/SecurityUiLabels.xml @@ -695,6 +695,22 @@ 受保护的视图 受保護的檢視 + + In field [${valueName}] found character escaping (mixed or double) that is not allowed or other format consistency error: + Le champ "${valueName}" contient un caractère d'échappement (mixte ou double) qui n'est pas autorisé ou une autre erreur de cohérence de format : + + + In field [${valueName}] less-than (<) and greater-than (>) symbols are not allowed. + Dans le champ "${valueName}" les symboles inférieurs (<) et supérieurs (>) ne sont pas autorisés. + + + In field [${valueName}] Javascript events are not allowed. + Dans le champ "${valueName}" les événements Javascript ne sont pas autorisés. + + + In field [${valueName}] by our input policy, your input has not been accepted for security reason. Please check and modify accordingly, thanks. + Dans le champ "${valueName}", conformément à notre politique de saisie, votre saisie n'a pas été acceptée pour des raisons de sécurité. Veuillez vérifier et modifier en conséquence, merci. + Click Here To Reset Password Cliquez ici pour créer un nouveau mot de passe diff --git a/framework/common/servicedef/services.xml b/framework/common/servicedef/services.xml index 083f81d5d5..22efa9ea55 100644 --- a/framework/common/servicedef/services.xml +++ b/framework/common/servicedef/services.xml @@ -63,7 +63,7 @@ under the License. Create a new note record - + @@ -71,7 +71,7 @@ under the License. Update a note record - + - + Update a Enumeration @@ -108,7 +108,7 @@ under the License. - + Delete a Enumeration diff --git a/framework/common/servicedef/services_email.xml b/framework/common/servicedef/services_email.xml index 90cc33d972..eb1845353b 100644 --- a/framework/common/servicedef/services_email.xml +++ b/framework/common/servicedef/services_email.xml @@ -42,7 +42,7 @@ under the License. - + @@ -52,12 +52,12 @@ under the License. - + Interface service for sendMail* services. - + @@ -122,7 +122,7 @@ under the License. location="org.apache.ofbiz.common.email.EmailServices" invoke="sendMailFromScreen"> Send E-Mail From Screen Widget Service - + @@ -147,7 +147,7 @@ under the License. Send Template Based Notification Service - + diff --git a/framework/service/dtd/services.xsd b/framework/service/dtd/services.xsd index 8bf0f143b0..910eeb0216 100644 --- a/framework/service/dtd/services.xsd +++ b/framework/service/dtd/services.xsd @@ -291,16 +291,13 @@ under the License. - Applies only to String fields. - Only checked for incoming parameters/attributes (could change in the future, but this is meant for validating input from users, other systems, etc). - Defaults to "none" meaning no HTML is allowed (will result in an error message). - If some HTML is desired then use "any". - There was previously "safe" but it's deprecated + See the documentation on the allow-html attribute of the "attribute" element. + @@ -358,12 +355,14 @@ under the License. Applies only to String fields. Only checked for incoming parameters/attributes (could change in the future, but this is meant for validating input from users, other systems, etc). Defaults to "none" meaning no HTML is allowed (will result in an error message). - If some HTML is desired then use "any". - There was previously "safe" but it's deprecated + If some HTML is desired then use "safe" which will follow the rules in the default custom safe policy file (CustomSafePolicy.java, see also owasp.properties). + This should be safe for both internal and public users. You may want to provide your own custom safe policy file to adapt to you needs. + In rare cases when users are trusted or it is not a sensitive field the "any" option may be used to not check the HTML content at all. + @@ -411,16 +410,14 @@ under the License. - Applies only to String fields. - Only checked for incoming parameters/attributes (could change in the future, but this is meant for validating input from users, other systems, etc). - There is no default, "none" means no HTML is allowed (will result in an error message). - If some HTML is desired then use "any". - There was previously "safe" but it's deprecated + See the documentation on the allow-html attribute of the "attribute" element. + Note that it is slightly different here as there is no default. + diff --git a/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java b/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java index b9b636717e..26e326f17f 100644 --- a/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java +++ b/framework/service/src/main/java/org/apache/ofbiz/service/ModelService.java @@ -608,7 +608,11 @@ public class ModelService extends AbstractMap implements Seriali if (context.get(modelParam.name) != null && ("String".equals(modelParam.type) || "java.lang.String".equals(modelParam.type)) && !"any".equals(modelParam.allowHtml) && (IN_OUT_PARAM.equals(modelParam.mode) || IN_PARAM.equals(modelParam.mode))) { String value = (String) context.get(modelParam.name); - UtilCodec.checkStringForHtmlStrictNone(modelParam.name, value, errorMessageList); + if ("none".equals(modelParam.allowHtml)) { + UtilCodec.checkStringForHtmlStrictNone(modelParam.name, value, errorMessageList, (Locale) context.get("locale")); + } else if ("safe".equals(modelParam.allowHtml)) { + UtilCodec.checkStringForHtmlSafe(modelParam.name, value, errorMessageList, (Locale) context.get("locale")); + } } } if (errorMessageList.size() > 0) {