You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2026/08/21 23:32:42 UTC

(freemarker-online-tester) branch java17 updated (9c2d0ca -> 4b76e1f)

This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a change to branch java17
in repository https://gitbox.apache.org/repos/asf/freemarker-online-tester.git


    from 9c2d0ca  Gradle: Replaced Rat Ant task wrapping with actual Rat Gradle plugin
     new 7f1d046  Gradle: Disabled -Werror for now... we got lots of deprecated warnings.
     new a524ca5  Blocked XXE attack possibility
     new 4b76e1f  (README update)

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 README.md                                          |  2 +-
 build.gradle.kts                                   |  2 +-
 .../onlinetester/util/DataModelParser.java         | 37 +++++++------
 .../freemarker/onlinetester/util/DomUtils.java     | 62 ++++++++++++++++++++++
 .../onlinetester/util/DataModelParserTest.java     | 24 ++++++++-
 5 files changed, 108 insertions(+), 19 deletions(-)
 create mode 100644 src/main/java/org/apache/freemarker/onlinetester/util/DomUtils.java


(freemarker-online-tester) 01/03: Gradle: Disabled -Werror for now... we got lots of deprecated warnings.

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

asf-gitbox-commits pushed a commit to branch java17
in repository https://gitbox.apache.org/repos/asf/freemarker-online-tester.git

commit 7f1d0466db5487fc5cea86ea1a7360fa12d2d3c0
Author: ddekany <dd...@apache.org>
AuthorDate: Sat Aug 22 00:52:53 2026 +0200

    Gradle: Disabled -Werror for now... we got lots of deprecated warnings.
---
 build.gradle.kts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/build.gradle.kts b/build.gradle.kts
index b7555fe..acddaa0 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -58,7 +58,7 @@ dependencies {
 }
 
 tasks.withType<JavaCompile>().configureEach {
-    options.compilerArgs.add("-Werror")
+    // options.compilerArgs.add("-Werror")
 }
 
 tasks.jar {


(freemarker-online-tester) 03/03: (README update)

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

asf-gitbox-commits pushed a commit to branch java17
in repository https://gitbox.apache.org/repos/asf/freemarker-online-tester.git

commit 4b76e1f7ea10aba572405ae1f32c21104b22bf3b
Author: ddekany <dd...@apache.org>
AuthorDate: Sat Aug 22 01:31:37 2026 +0200

    (README update)
---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 6d8ce83..7037da4 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@ Development Instructions
 * If you want to run it using IDEA run `./gradlew cleanidea idea`; this will generate the IDEA project for you.
 * To run the service:
   - From command line: build `shadowJar` (not `jar`) and then issue
-    `java -jar build/libs/freemarker-online-<VERSION>.jar server src/main/resources/freemarker-online.yml`
+    `java -jar build/libs/freemarker-online-all.jar server src/main/resources/freemarker-online.yml`
   - From IDE: run class `org.apache.freemarker.onlinetester.dropwizard.FreeMarkerOnlineTester` with arguments
     `server src/main/resources/freemarker-online.yml`
 * Then, to try the service locally, visit <http://localhost:8080/>


(freemarker-online-tester) 02/03: Blocked XXE attack possibility

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

asf-gitbox-commits pushed a commit to branch java17
in repository https://gitbox.apache.org/repos/asf/freemarker-online-tester.git

commit a524ca5d60d804a20624ae19d18e3d2dd8ada330
Author: ddekany <dd...@apache.org>
AuthorDate: Sat Aug 22 00:53:25 2026 +0200

    Blocked XXE attack possibility
---
 .../onlinetester/util/DataModelParser.java         | 37 +++++++------
 .../freemarker/onlinetester/util/DomUtils.java     | 62 ++++++++++++++++++++++
 .../onlinetester/util/DataModelParserTest.java     | 24 ++++++++-
 3 files changed, 106 insertions(+), 17 deletions(-)

diff --git a/src/main/java/org/apache/freemarker/onlinetester/util/DataModelParser.java b/src/main/java/org/apache/freemarker/onlinetester/util/DataModelParser.java
index 4f203db..06da37a 100644
--- a/src/main/java/org/apache/freemarker/onlinetester/util/DataModelParser.java
+++ b/src/main/java/org/apache/freemarker/onlinetester/util/DataModelParser.java
@@ -68,16 +68,20 @@ public final class DataModelParser {
 
     private static final String KEYWORD_NAN = "NaN";
 
-    /** Matches a line starting like "someVariable=". */
+    /**
+     * Matches a line starting like "someVariable=".
+     */
     private static final Pattern ASSIGNMENT_START = Pattern.compile(
             "^\\s*"
-            + "(\\p{L}[\\p{L}\\p{N}\\.:\\-_$@]*)" // name
-            + "[ \t]*=\\s*",
+                    + "(\\p{L}[\\p{L}\\p{N}\\.:\\-_$@]*)" // name
+                    + "[ \t]*=\\s*",
             Pattern.MULTILINE);
 
-    /** Matches a value that starts like a number, or probably meant to be number at least. */
+    /**
+     * Matches a value that starts like a number, or probably meant to be number at least.
+     */
     private static final Pattern NUMBER_LIKE = Pattern.compile("[+-]?[\\.,]?[0-9].*", Pattern.DOTALL);
-    
+
     private static final ObjectMapper JSON_MAPPER = new ObjectMapper();
 
     private DataModelParser() {
@@ -94,12 +98,13 @@ public final class DataModelParser {
         String lastName = null;
         int lastAssignmentStartEnd = 0;
         final Matcher assignmentStart = ASSIGNMENT_START.matcher(src);
-        findAssignments: while (true) {
+        findAssignments:
+        while (true) {
             boolean hasNextAssignment = assignmentStart.find(lastAssignmentStartEnd);
 
             if (lastName != null) {
                 String value = src.substring(
-                        lastAssignmentStartEnd, hasNextAssignment ? assignmentStart.start() : src.length())
+                                lastAssignmentStartEnd, hasNextAssignment ? assignmentStart.start() : src.length())
                         .trim();
                 final Object parsedValue;
                 try {
@@ -126,25 +131,25 @@ public final class DataModelParser {
 
         return dataModel;
     }
-    
+
     private static Object parseValue(String value, TimeZone timeZone) throws DataModelParsingException {
         // Note: Because we fall back to interpret the input as a literal string value when it doesn't look like
         // anything else (like a number, boolean, etc.), it's important to avoid misunderstandings, and throw exception
         // in suspicious situations. The user can always quote the string value if we are "too smart". But he will
         // be confused about the rules of FreeMarker if what he believes to be a non-string is misinterpreted by this
         // parser as a string. Getting sometimes an error and then quoting the string is better than that.
-        
+
         if (value.endsWith(";")) {  // Tolerate this habit of Java and JavaScript programmers
             value = value.substring(value.length() - 1).trim();
         }
-        
+
         if (NUMBER_LIKE.matcher(value).matches()) {
             try {
                 return new BigDecimal(value);
             } catch (NumberFormatException e) {
                 // Maybe it's a ISO 8601 Date/time/datetime
                 CalendarFieldsToDateConverter calToDateConverter = new TrivialCalendarFieldsToDateConverter();
-                
+
                 DateParseException attemptedTemportalPExc = null;
                 String attemptedTemporalType = null;
                 final int dashIdx = value.indexOf('-');
@@ -165,7 +170,7 @@ public final class DataModelParser {
                         attemptedTemporalType = "date";
                         attemptedTemportalPExc = pExc;
                     }
-                } else if (colonIdx > 1) { 
+                } else if (colonIdx > 1) {
                     try {
                         return new Time(
                                 DateUtil.parseISO8601Time(value, timeZone, calToDateConverter).getTime());
@@ -178,8 +183,8 @@ public final class DataModelParser {
                     throw new DataModelParsingException("Malformed number: " + value, e);
                 } else {
                     throw new DataModelParsingException(
-                            "Malformed ISO 8601 " + attemptedTemporalType + " (or malformed number): " + 
-                            attemptedTemportalPExc.getMessage(), e.getCause());
+                            "Malformed ISO 8601 " + attemptedTemporalType + " (or malformed number): " +
+                                    attemptedTemportalPExc.getMessage(), e.getCause());
                 }
             }
         } else if (value.startsWith("\"")) {
@@ -211,7 +216,7 @@ public final class DataModelParser {
             }
         } else if (value.startsWith("<")) {
             try {
-                DocumentBuilder builder = NodeModel.getDocumentBuilderFactory().newDocumentBuilder();
+                DocumentBuilder builder = DomUtils.newSecureDocumentBuilder();
                 ErrorHandler errorHandler = NodeModel.getErrorHandler();
                 if (errorHandler != null) builder.setErrorHandler(errorHandler);
                 final Document doc = builder.parse(new InputSource(new StringReader(value)));
@@ -244,7 +249,7 @@ public final class DataModelParser {
         } else if (value.equalsIgnoreCase(KEYWORD_NEGATIVE_INFINITY)) {
             checkKeywordCase(value, KEYWORD_NEGATIVE_INFINITY);
             return Double.NEGATIVE_INFINITY;
-        } else if (value.length() == 0) {
+        } else if (value.isEmpty()) {
             throw new DataModelParsingException(
                     "Empty value. (If you indeed wanted a 0 length string, quote it, like \"\".)");
         } else {
diff --git a/src/main/java/org/apache/freemarker/onlinetester/util/DomUtils.java b/src/main/java/org/apache/freemarker/onlinetester/util/DomUtils.java
new file mode 100644
index 0000000..dc0a6bf
--- /dev/null
+++ b/src/main/java/org/apache/freemarker/onlinetester/util/DomUtils.java
@@ -0,0 +1,62 @@
+/*
+ * 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.freemarker.onlinetester.util;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+public class DomUtils {
+    /**
+     * Creates a {@link DocumentBuilder} that's hardened for parsing XML coming from an untrusted user: {@code DOCTYPE}
+     * declarations are disallowed, so no external entities can be resolved (XXE: local file disclosure, SSRF from the
+     * server), nor internal entities expanded (entity-expansion DoS).
+     */
+    public static DocumentBuilder newSecureDocumentBuilder() throws ParserConfigurationException {
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        // Same settings as in NodeModel.getDocumentBuilderFactory(), which the wrapped Document-s expect:
+        factory.setNamespaceAware(true);
+        factory.setIgnoringElementContentWhitespace(true);
+        // Primary defense; this failing (very old or exotic JAXP implementation) must fail the parsing:
+        factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
+        // Defense in depth follows; not supported by all JAXP implementations, hence only set if possible:
+        trySetFeature(factory, "http://xml.org/sax/features/external-general-entities", false);
+        trySetFeature(factory, "http://xml.org/sax/features/external-parameter-entities", false);
+        trySetFeature(factory, "http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
+        factory.setXIncludeAware(false);
+        factory.setExpandEntityReferences(false);
+        try {
+            factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+            factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
+        } catch (IllegalArgumentException e) {
+            // Pre-JAXP-1.5 implementation; the disallowed DOCTYPE-s already prevent external access.
+        }
+        return factory.newDocumentBuilder();
+    }
+
+    private static void trySetFeature(DocumentBuilderFactory factory, String feature, boolean value) {
+        try {
+            factory.setFeature(feature, value);
+        } catch (ParserConfigurationException e) {
+            // The implementation doesn't know this feature; the mandatory disallow-doctype-decl still protects.
+        }
+    }
+}
diff --git a/src/test/java/org/apache/freemarker/onlinetester/util/DataModelParserTest.java b/src/test/java/org/apache/freemarker/onlinetester/util/DataModelParserTest.java
index 468b2b5..2ab2adc 100644
--- a/src/test/java/org/apache/freemarker/onlinetester/util/DataModelParserTest.java
+++ b/src/test/java/org/apache/freemarker/onlinetester/util/DataModelParserTest.java
@@ -254,7 +254,29 @@ public class DataModelParserTest {
             assertThat(e.getMessage(), containsString("XML"));
         }
     }
-    
+
+    @Test
+    public void testXMLWithDoctypeRejected() throws DataModelParsingException {
+        // XXE prevention: an external entity must never be resolved (local file disclosure, SSRF), so DOCTYPE-s
+        // are rejected altogether:
+        try {
+            DataModelParser.parse(
+                    "n=<!DOCTYPE r [<!ENTITY x SYSTEM \"file:///etc/passwd\">]><r>&x;</r>", DateUtil.UTC);
+            fail();
+        } catch (DataModelParsingException e) {
+            assertThat(e.getMessage(), containsString("XML"));
+        }
+        // Internal entities (entity-expansion DoS) are rejected with the DOCTYPE too:
+        try {
+            DataModelParser.parse("n=<!DOCTYPE r [<!ENTITY x \"v\">]><r>&x;</r>", DateUtil.UTC);
+            fail();
+        } catch (DataModelParsingException e) {
+            assertThat(e.getMessage(), containsString("XML"));
+        }
+        // But DOCTYPE-less XML still works:
+        assertThat(DataModelParser.parse("n=<r>v</r>", DateUtil.UTC).get("n"), instanceOf(Document.class));
+    }
+
     @Test
     public void testNull() throws DataModelParsingException {
         assertNull(DataModelParser.parse("n=null", DateUtil.UTC).get("n"));