[ofbiz-framework] branch trunk updated: Improved: Prevent FreeMarker Template Injection (SSTI)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] branch trunk updated: Improved: Prevent FreeMarker Template Injection (SSTI)

jleroux@apache.org
This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 09baa55  Improved: Prevent FreeMarker Template Injection (SSTI)
09baa55 is described below

commit 09baa5537e160fdf00450aedd2bd69ff9776ccaa
Author: Jacques Le Roux <[hidden email]>
AuthorDate: Mon May 18 14:03:33 2020 +0200

    Improved: Prevent FreeMarker Template Injection (SSTI)
   
    (OFBIZ-11709)
   
    Previous code compiled but SAFER_RESOLVER is not a class but a field, better KISS
---
 .../ofbiz/base/util/template/FreeMarkerWorker.java | 23 +++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/template/FreeMarkerWorker.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/template/FreeMarkerWorker.java
index 56b2eee..c7bf317 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/template/FreeMarkerWorker.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/template/FreeMarkerWorker.java
@@ -65,7 +65,6 @@ import freemarker.template.TemplateHashModel;
 import freemarker.template.TemplateModel;
 import freemarker.template.TemplateModelException;
 import freemarker.template.Version;
-import freemarker.template.utility.ClassUtil;
 
 /**
  * FreeMarkerWorker - Freemarker Template Engine Utilities.
@@ -127,14 +126,20 @@ public final class FreeMarkerWorker {
         } catch (TemplateException e) {
             Debug.logError("Unable to set date/time and number formats in FreeMarker: " + e, MODULE);
         }
-        String templateClassResolver = UtilProperties.getPropertyValue("security", "templateClassResolver",
-                "SAFER_RESOLVER");
-        try {
-            newConfig.setNewBuiltinClassResolver((TemplateClassResolver)
-                    ClassUtil.forName("freemarker.core.TemplateClassResolver" + templateClassResolver)
-                    .cast(templateClassResolver));
-        } catch (ClassNotFoundException e) {
-            Debug.logError("No TemplateClassResolver." + templateClassResolver, MODULE);
+        String templateClassResolver = UtilProperties.getPropertyValue("security", "templateClassResolver", "SAFER_RESOLVER");
+        switch (templateClassResolver) {
+            case "UNRESTRICTED_RESOLVER":
+                newConfig.setNewBuiltinClassResolver(TemplateClassResolver.UNRESTRICTED_RESOLVER);
+                break;
+            case "SAFER_RESOLVER":
+                newConfig.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);
+                break;
+            case "ALLOWS_NOTHING_RESOLVER":
+                newConfig.setNewBuiltinClassResolver(TemplateClassResolver.ALLOWS_NOTHING_RESOLVER);
+                break;
+            default:
+                Debug.logError("Not a TemplateClassResolver.", MODULE);
+                break;
         }
         // Transforms properties file set up as key=transform name, property=transform class name
         ClassLoader loader = Thread.currentThread().getContextClassLoader();