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

ilgrosso pushed a commit to branch 4_1_X
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/4_1_X by this push:
     new 06080cdcdc Flowable: check UEL expressions in BPMN definitions with 
whitelist sandbox validation
06080cdcdc is described below

commit 06080cdcdcfe51a7d8b62cb1821d4077feeb88ac
Author: Francesco Chicchiriccò <[email protected]>
AuthorDate: Mon Nov 23 10:49:21 2026 +0100

    Flowable: check UEL expressions in BPMN definitions with whitelist sandbox 
validation
---
 ext/flowable/flowable-bpmn/pom.xml                 |  14 +-
 .../core/flowable/impl/FlowableDeployUtils.java    | 140 ++++++++++++----
 .../syncope/core/flowable/impl/UELSandbox.java     | 106 ++++++++++++
 .../flowable/impl/FlowableDeployUtilsTest.java     | 185 +++++++++++++++++++++
 .../syncope/core/flowable/impl/UELSandboxTest.java |  77 +++++++++
 5 files changed, 490 insertions(+), 32 deletions(-)

diff --git a/ext/flowable/flowable-bpmn/pom.xml 
b/ext/flowable/flowable-bpmn/pom.xml
index 28d4fd3b6c..534d91248e 100644
--- a/ext/flowable/flowable-bpmn/pom.xml
+++ b/ext/flowable/flowable-bpmn/pom.xml
@@ -32,7 +32,7 @@ under the License.
   <groupId>org.apache.syncope.ext.flowable</groupId>
   <artifactId>syncope-ext-flowable-bpmn</artifactId>
   <packaging>jar</packaging>
-  
+
   <properties>
     <rootpom.basedir>${basedir}/../../..</rootpom.basedir>
   </properties>
@@ -70,6 +70,18 @@ under the License.
       <artifactId>syncope-core-workflow-java</artifactId>
       <version>${project.version}</version>
     </dependency>
+
+    <!-- TEST -->
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-junit-jupiter</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
diff --git 
a/ext/flowable/flowable-bpmn/src/main/java/org/apache/syncope/core/flowable/impl/FlowableDeployUtils.java
 
b/ext/flowable/flowable-bpmn/src/main/java/org/apache/syncope/core/flowable/impl/FlowableDeployUtils.java
index 2c47c3e090..561fe1ffe1 100644
--- 
a/ext/flowable/flowable-bpmn/src/main/java/org/apache/syncope/core/flowable/impl/FlowableDeployUtils.java
+++ 
b/ext/flowable/flowable-bpmn/src/main/java/org/apache/syncope/core/flowable/impl/FlowableDeployUtils.java
@@ -23,7 +23,10 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import javax.lang.model.SourceVersion;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
@@ -40,13 +43,9 @@ import org.flowable.engine.ProcessEngine;
 import org.flowable.engine.repository.Deployment;
 import org.flowable.engine.repository.Model;
 import org.flowable.engine.repository.ProcessDefinition;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public final class FlowableDeployUtils {
 
-    private static final Logger LOG = 
LoggerFactory.getLogger(FlowableDeployUtils.class);
-
     private static final JsonMapper MAPPER = 
JsonMapper.builder().findAndAddModules().build();
 
     private static final XMLInputFactory XML_INPUT_FACTORY = 
XMLInputFactory.newInstance();
@@ -56,36 +55,117 @@ public final class FlowableDeployUtils {
         XML_INPUT_FACTORY.setProperty(XMLInputFactory.SUPPORT_DTD, 
Boolean.FALSE);
     }
 
-    private static boolean isInvalid(final byte[] xml) throws 
XMLStreamException, IOException {
+    /**
+     * Element texts that Flowable's BPMN converter reads as (UEL) expressions.
+     */
+    private static final Set<String> UEL_TEXT_ELEMENTS = Set.of(
+            BpmnXMLConstants.ELEMENT_FLOW_CONDITION,
+            BpmnXMLConstants.ELEMENT_CONDITION,
+            BpmnXMLConstants.ELEMENT_COMPLETION_CONDITION,
+            BpmnXMLConstants.ELEMENT_MULTIINSTANCE_CARDINALITY,
+            BpmnXMLConstants.ELEMENT_MULTIINSTANCE_DATAINPUT,
+            BpmnXMLConstants.ATTRIBUTE_TIMER_DATE,
+            BpmnXMLConstants.ATTRIBUTE_TIMER_DURATION,
+            BpmnXMLConstants.ATTRIBUTE_TIMER_CYCLE);
+
+    /**
+     * Attributes in the Flowable extensions namespace carrying (UEL) 
expressions.
+     */
+    private static final Set<String> FLOWABLE_EXPRESSION_ATTRIBUTES = Set.of(
+            BpmnXMLConstants.ATTRIBUTE_TASK_SERVICE_EXPRESSION,
+            BpmnXMLConstants.ATTRIBUTE_TASK_SERVICE_DELEGATEEXPRESSION,
+            BpmnXMLConstants.ATTRIBUTE_TASK_SERVICE_SKIP_EXPRESSION,
+            BpmnXMLConstants.ATTRIBUTE_MESSAGE_EXPRESSION,
+            BpmnXMLConstants.ATTRIBUTE_SIGNAL_EXPRESSION);
+
+    private static final Set<String> LISTENER_ATTRIBUTES = Set.of(
+            BpmnXMLConstants.ATTRIBUTE_LISTENER_EXPRESSION,
+            BpmnXMLConstants.ATTRIBUTE_LISTENER_DELEGATEEXPRESSION,
+            
BpmnXMLConstants.ATTRIBUTE_LISTENER_CUSTOM_PROPERTIES_RESOLVER_EXPRESSION,
+            
BpmnXMLConstants.ATTRIBUTE_LISTENER_CUSTOM_PROPERTIES_RESOLVER_DELEGATEEXPRESSION);
+
+    private static final Set<String> IO_ATTRIBUTES = Set.of(
+            BpmnXMLConstants.ATTRIBUTE_IOPARAMETER_SOURCE_EXPRESSION,
+            BpmnXMLConstants.ATTRIBUTE_IOPARAMETER_TARGET_EXPRESSION);
+
+    /**
+     * Unqualified attributes carrying (UEL) expressions, keyed by the 
Flowable extension element they belong to.
+     */
+    private static final Map<String, Set<String>> FLOWABLE_ELEMENT_ATTRIBUTES 
= Map.of(
+            BpmnXMLConstants.ELEMENT_EXECUTION_LISTENER, LISTENER_ATTRIBUTES,
+            BpmnXMLConstants.ELEMENT_TASK_LISTENER, LISTENER_ATTRIBUTES,
+            BpmnXMLConstants.ELEMENT_EVENT_LISTENER, LISTENER_ATTRIBUTES,
+            BpmnXMLConstants.ELEMENT_FIELD, 
Set.of(BpmnXMLConstants.ATTRIBUTE_FIELD_EXPRESSION),
+            BpmnXMLConstants.ELEMENT_FORMPROPERTY, Set.of(
+                    BpmnXMLConstants.ATTRIBUTE_FORM_EXPRESSION, 
BpmnXMLConstants.ATTRIBUTE_FORM_DEFAULT),
+            BpmnXMLConstants.ELEMENT_IN_PARAMETERS, IO_ATTRIBUTES,
+            BpmnXMLConstants.ELEMENT_OUT_PARAMETERS, IO_ATTRIBUTES,
+            BpmnXMLConstants.ELEMENT_MULTIINSTANCE_COLLECTION, Set.of(
+                    
BpmnXMLConstants.ATTRIBUTE_MULTIINSTANCE_COLLECTION_DELEGATEEXPRESSION),
+            BpmnXMLConstants.ELEMENT_VARIABLE_AGGREGATION, IO_ATTRIBUTES,
+            BpmnXMLConstants.ATTRIBUTE_VARIABLE_AGGREGATION_VARIABLE, 
IO_ATTRIBUTES);
+
+    private static final Pattern UEL_SEGMENT = Pattern.compile("\\$\\{.*?}", 
Pattern.DOTALL);
+
+    private static void checkExpression(final String expression, final String 
reference) {
+        if (!UELSandbox.isAllowed(expression)) {
+            throw new WorkflowException("UEL expression not allowed in " + 
reference + ": " + expression);
+        }
+    }
+
+    /**
+     * A formalExpression can be a plain assignment (e.g. {@code 
group(admin)}) as well as a UEL expression;
+     * only the embedded {@code ${...}} segments are validated.
+     */
+    private static void checkFormalExpression(final String text, final String 
reference) {
+        Matcher matcher = UEL_SEGMENT.matcher(text);
+        while (matcher.find()) {
+            checkExpression(matcher.group(), reference);
+        }
+    }
+
+    private static void checkAttributes(final XMLStreamReader xtr) {
+        Set<String> unqualifiedAttributes = 
BpmnXMLConstants.FLOWABLE_EXTENSIONS_NAMESPACE.equals(xtr.getNamespaceURI())
+                ? FLOWABLE_ELEMENT_ATTRIBUTES.get(xtr.getLocalName())
+                : Set.of();
+
+        for (int i = 0; i < xtr.getAttributeCount(); i++) {
+            String attributeNamespace = xtr.getAttributeNamespace(i);
+            String attributeName = xtr.getAttributeLocalName(i);
+            String reference = xtr.getLocalName() + "/@" + attributeName;
+
+            if 
(BpmnXMLConstants.FLOWABLE_EXTENSIONS_NAMESPACE.equals(attributeNamespace)) {
+                if (FLOWABLE_EXPRESSION_ATTRIBUTES.contains(attributeName)) {
+                    checkExpression(xtr.getAttributeValue(i), reference);
+                }
+            } else if (StringUtils.isBlank(attributeNamespace) && 
unqualifiedAttributes.contains(attributeName)) {
+                checkExpression(xtr.getAttributeValue(i), reference);
+            }
+        }
+    }
+
+    static void checkDefinition(final byte[] xml) throws XMLStreamException, 
IOException {
         try (ByteArrayInputStream in = new ByteArrayInputStream(xml)) {
             XMLStreamReader xtr = XML_INPUT_FACTORY.createXMLStreamReader(in);
             try {
                 while (xtr.hasNext()) {
-                    if (xtr.next() == XMLStreamConstants.START_ELEMENT) {
-                        for (int i = 0; i < xtr.getAttributeCount(); i++) {
-                            if 
(BpmnXMLConstants.FLOWABLE_EXTENSIONS_NAMESPACE.equals(xtr.getAttributeNamespace(i)))
 {
-                                switch (xtr.getAttributeLocalName(i)) {
-                                    case 
BpmnXMLConstants.ATTRIBUTE_TASK_SERVICE_EXPRESSION -> {
-                                        LOG.error("expression not allowed");
-                                        return true;
-                                    }
-
-                                    case 
BpmnXMLConstants.ATTRIBUTE_TASK_SERVICE_DELEGATEEXPRESSION -> {
-                                        String name = 
StringUtils.substringBetween(xtr.getAttributeValue(i), "${", "}");
-                                        if (!SourceVersion.isIdentifier(name) 
|| SourceVersion.isKeyword(name)) {
-                                            LOG.error("delegateExpression 
shall contain only Spring Beans name");
-                                            return true;
-                                        }
-                                    }
-
-                                    default -> {
-                                    }
-                                }
-                            }
+                    if (xtr.next() != XMLStreamConstants.START_ELEMENT) {
+                        continue;
+                    }
+
+                    checkAttributes(xtr);
+
+                    String localName = xtr.getLocalName();
+                    if 
(BpmnXMLConstants.FLOWABLE_EXTENSIONS_NAMESPACE.equals(xtr.getNamespaceURI())) {
+                        if 
(BpmnXMLConstants.ATTRIBUTE_LISTENER_EXPRESSION.equals(localName)) {
+                            checkExpression(xtr.getElementText(), localName);
                         }
+                    } else if (UEL_TEXT_ELEMENTS.contains(localName)) {
+                        checkExpression(xtr.getElementText(), localName);
+                    } else if 
(BpmnXMLConstants.ELEMENT_FORMAL_EXPRESSION.equals(localName)) {
+                        checkFormalExpression(xtr.getElementText(), localName);
                     }
                 }
-                return false;
             } finally {
                 xtr.close();
             }
@@ -96,9 +176,7 @@ public final class FlowableDeployUtils {
             final ProcessEngine engine, final String resourceName, final 
byte[] definition) {
 
         try {
-            if (isInvalid(definition)) {
-                throw new WorkflowException("The provided XML definition 
contains elements not allowed");
-            }
+            checkDefinition(definition);
         } catch (IOException | XMLStreamException e) {
             throw new WorkflowException("While checking " + resourceName, e);
         }
diff --git 
a/ext/flowable/flowable-bpmn/src/main/java/org/apache/syncope/core/flowable/impl/UELSandbox.java
 
b/ext/flowable/flowable-bpmn/src/main/java/org/apache/syncope/core/flowable/impl/UELSandbox.java
new file mode 100644
index 0000000000..989acfe4ce
--- /dev/null
+++ 
b/ext/flowable/flowable-bpmn/src/main/java/org/apache/syncope/core/flowable/impl/UELSandbox.java
@@ -0,0 +1,106 @@
+package org.apache.syncope.core.flowable.impl;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.common.lib.request.UserCR;
+import org.apache.syncope.common.lib.request.UserUR;
+import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.core.persistence.api.entity.user.User;
+
+/**
+ * Simple sandbox for validating JUEL expressions used in BPMN 
conditionExpressions.
+ * The validator allows only a whitelisted set of beans and methods that are 
known to
+ * be safe in current Syncope deployments.
+ */
+public final class UELSandbox {
+
+    /**
+     * Matches any method invocation, i.e. an identifier immediately followed 
by an opening parenthesis.
+     */
+    private static final Pattern METHOD_CALL = 
Pattern.compile("([a-zA-Z_$][a-zA-Z\\d_$]*)\\s*\\(");
+
+    /**
+     * Matches the reference on which a method is invoked, capturing the bean 
name (the identifier
+     * immediately preceding the last dot). DOTALL is required because BPMN 
expressions may span
+     * multiple lines.
+     */
+    private static final Pattern BEAN_REF =
+            Pattern.compile(".*\\b([a-zA-Z_$][a-zA-Z\\d_$]*)\\s*\\.\\s*$", 
Pattern.DOTALL);
+
+    private static final Map<String, Set<String>> WHITELIST = new HashMap<>();
+
+    static {
+        Set<String> flowableUtils = 
Stream.of(FlowableWorkflowUtils.class.getMethods()).
+                map(Method::getName).
+                collect(Collectors.toSet());
+        WHITELIST.put("flowableUtils", flowableUtils);
+
+        Set<String> user = Stream.of(User.class.getMethods()).
+                map(Method::getName).
+                collect(Collectors.toSet());
+        WHITELIST.put("user", user);
+
+        Set<String> userCR = Stream.of(UserCR.class.getMethods()).
+                map(Method::getName).
+                collect(Collectors.toSet());
+        WHITELIST.put("userCR", userCR);
+
+        Set<String> userUR = Stream.of(UserUR.class.getMethods()).
+                map(Method::getName).
+                collect(Collectors.toSet());
+        WHITELIST.put("userUR", userUR);
+
+        Set<String> userTO = Stream.of(UserTO.class.getMethods()).
+                map(Method::getName).
+                collect(Collectors.toSet());
+        WHITELIST.put("userTO", userTO);
+    }
+
+    /**
+     * Determines whether the supplied expression string is allowed by the 
sandbox.
+     * Only a very small set of bean method calls are permitted; anything else 
results in a rejection.
+     *
+     * @param expr UEL expression
+     * @return whether the supplied expression string is allowed by the sandbox
+     */
+    public static boolean isAllowed(final String expr) {
+        if (StringUtils.isBlank(expr)) {
+            return true;
+        }
+
+        // Strip leading ${...}
+        String body = expr.startsWith("${") && expr.endsWith("}")
+                ? expr.substring(2, expr.length() - 1).trim()
+                : expr.trim();
+
+        Matcher m = METHOD_CALL.matcher(body);
+        while (m.find()) {
+            String method = m.group(1);
+
+            // The method must be invoked on one of the whitelisted beans.
+            Matcher beanMatcher = BEAN_REF.matcher(body.substring(0, 
m.start(1)));
+            if (!beanMatcher.matches()) {
+                return false;
+            }
+            String bean = beanMatcher.group(1);
+
+            Set<String> methods = WHITELIST.get(bean);
+            if (methods == null || !methods.contains(method)) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    private UELSandbox() {
+        // private constructor for static utility class
+    }
+}
diff --git 
a/ext/flowable/flowable-bpmn/src/test/java/org/apache/syncope/core/flowable/impl/FlowableDeployUtilsTest.java
 
b/ext/flowable/flowable-bpmn/src/test/java/org/apache/syncope/core/flowable/impl/FlowableDeployUtilsTest.java
new file mode 100644
index 0000000000..99a0cb9193
--- /dev/null
+++ 
b/ext/flowable/flowable-bpmn/src/test/java/org/apache/syncope/core/flowable/impl/FlowableDeployUtilsTest.java
@@ -0,0 +1,185 @@
+/*
+ * 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.syncope.core.flowable.impl;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.InputStream;
+import org.apache.syncope.core.workflow.api.WorkflowException;
+import org.flowable.engine.ProcessEngine;
+import org.flowable.engine.RepositoryService;
+import org.flowable.engine.repository.DeploymentBuilder;
+import org.junit.jupiter.api.Test;
+
+class FlowableDeployUtilsTest {
+
+    private static final String BPMN_HEADER =
+            "<definitions 
xmlns=\"http://www.omg.org/spec/BPMN/20100524/MODEL\"; "
+            + "xmlns:flowable=\"http://flowable.org/bpmn\"; 
targetNamespace=\"test\">";
+
+    private static final String MALICIOUS = 
"${''.getClass().forName('java.io.File')}";
+
+    private static ProcessEngine mockEngine() {
+        ProcessEngine processEngine = mock(ProcessEngine.class);
+        when(processEngine.getRepositoryService()).then(ic -> {
+            DeploymentBuilder deploymentBuilder = 
mock(DeploymentBuilder.class);
+            when(deploymentBuilder.addBytes(anyString(), 
any(byte[].class))).thenReturn(deploymentBuilder);
+
+            RepositoryService service = mock(RepositoryService.class);
+            when(service.createDeployment()).thenReturn(deploymentBuilder);
+
+            return service;
+        });
+        return processEngine;
+    }
+
+    private static String bpmn(final String body) {
+        return BPMN_HEADER + "<process id=\"p\">" + body + 
"</process></definitions>";
+    }
+
+    @Test
+    void shippedWorkflowAllowed() throws Exception {
+        try (InputStream in = 
getClass().getResourceAsStream("/userWorkflow.bpmn20.xml")) {
+            assertNotNull(in, "Shipped workflow definition not found on 
classpath");
+            FlowableDeployUtils.deployDefinition(mockEngine(), "", 
in.readAllBytes());
+        }
+    }
+
+    @Test
+    void maliciousConditionExpressionRejected() {
+        String bpmn = bpmn(
+                "<sequenceFlow id=\"f\" sourceRef=\"a\" targetRef=\"b\">"
+                + "<conditionExpression><![CDATA[" + MALICIOUS + 
"]]></conditionExpression>"
+                + "</sequenceFlow>");
+
+        assertThrows(
+                WorkflowException.class,
+                () -> 
FlowableDeployUtils.deployDefinition(mock(ProcessEngine.class), "", 
bpmn.getBytes()));
+    }
+
+    @Test
+    void maliciousDelegateExpressionRejected() {
+        String bpmn = bpmn(
+                "<serviceTask id=\"t\" "
+                + 
"flowable:delegateExpression=\"${java.lang.Runtime.getRuntime().exec('whoami')}\"/>");
+
+        assertThrows(
+                WorkflowException.class,
+                () -> 
FlowableDeployUtils.deployDefinition(mock(ProcessEngine.class), "", 
bpmn.getBytes()));
+    }
+
+    @Test
+    void maliciousListenerExpressionRejected() {
+        String bpmn = bpmn(
+                "<extensionElements>"
+                + "<flowable:executionListener event=\"start\" expression=\"" 
+ MALICIOUS + "\"/>"
+                + "</extensionElements>");
+
+        assertThrows(
+                WorkflowException.class,
+                () -> 
FlowableDeployUtils.deployDefinition(mock(ProcessEngine.class), "", 
bpmn.getBytes()));
+    }
+
+    @Test
+    void maliciousConditionalEventRejected() {
+        String bpmn = bpmn(
+                "<intermediateCatchEvent id=\"e\"><conditionalEventDefinition>"
+                + "<condition><![CDATA[" + MALICIOUS + "]]></condition>"
+                + "</conditionalEventDefinition></intermediateCatchEvent>");
+
+        assertThrows(
+                WorkflowException.class,
+                () -> 
FlowableDeployUtils.deployDefinition(mock(ProcessEngine.class), "", 
bpmn.getBytes()));
+    }
+
+    @Test
+    void maliciousMultiInstanceCompletionConditionRejected() {
+        String bpmn = bpmn(
+                "<userTask id=\"t\"><multiInstanceLoopCharacteristics>"
+                + "<completionCondition><![CDATA[" + MALICIOUS + 
"]]></completionCondition>"
+                + "</multiInstanceLoopCharacteristics></userTask>");
+
+        assertThrows(
+                WorkflowException.class,
+                () -> 
FlowableDeployUtils.deployDefinition(mock(ProcessEngine.class), "", 
bpmn.getBytes()));
+    }
+
+    @Test
+    void maliciousTimerExpressionRejected() {
+        String bpmn = bpmn(
+                "<intermediateCatchEvent id=\"e\"><timerEventDefinition>"
+                + "<timeDate><![CDATA[" + MALICIOUS + "]]></timeDate>"
+                + "</timerEventDefinition></intermediateCatchEvent>");
+
+        assertThrows(
+                WorkflowException.class,
+                () -> 
FlowableDeployUtils.deployDefinition(mock(ProcessEngine.class), "", 
bpmn.getBytes()));
+    }
+
+    @Test
+    void maliciousFieldExpressionRejected() {
+        String bpmn = bpmn(
+                "<serviceTask id=\"s\"><extensionElements><flowable:field 
name=\"f\">"
+                + "<flowable:expression><![CDATA[" + MALICIOUS + 
"]]></flowable:expression>"
+                + "</flowable:field></extensionElements></serviceTask>");
+
+        assertThrows(
+                WorkflowException.class,
+                () -> 
FlowableDeployUtils.deployDefinition(mock(ProcessEngine.class), "", 
bpmn.getBytes()));
+    }
+
+    @Test
+    void allowedUelFormalExpression() {
+        String bpmn = bpmn(
+                "<userTask 
id=\"t\"><humanPerformer><resourceAssignmentExpression>"
+                + "<formalExpression>${user.getUsername()}</formalExpression>"
+                + 
"</resourceAssignmentExpression></humanPerformer></userTask>");
+
+        assertDoesNotThrow(() -> 
FlowableDeployUtils.deployDefinition(mockEngine(), "", bpmn.getBytes()));
+    }
+
+    @Test
+    void allowedPlainFormalExpressionAssignment() {
+        String bpmn = bpmn(
+                "<userTask 
id=\"t\"><potentialOwner><resourceAssignmentExpression>"
+                + 
"<formalExpression>group(admin),user(john)</formalExpression>"
+                + 
"</resourceAssignmentExpression></potentialOwner></userTask>");
+
+        assertDoesNotThrow(() -> 
FlowableDeployUtils.deployDefinition(mockEngine(), "", bpmn.getBytes()));
+    }
+
+    @Test
+    void allowedLiteralElementTexts() {
+        String bpmn = bpmn(
+                "<userTask id=\"t\"><multiInstanceLoopCharacteristics>"
+                + "<loopCardinality>3</loopCardinality>"
+                + "</multiInstanceLoopCharacteristics></userTask>"
+                + "<intermediateCatchEvent id=\"e\"><timerEventDefinition>"
+                + "<timeDuration>PT1H</timeDuration>"
+                + "</timerEventDefinition></intermediateCatchEvent>");
+
+        assertDoesNotThrow(() -> 
FlowableDeployUtils.deployDefinition(mockEngine(), "", bpmn.getBytes()));
+    }
+}
diff --git 
a/ext/flowable/flowable-bpmn/src/test/java/org/apache/syncope/core/flowable/impl/UELSandboxTest.java
 
b/ext/flowable/flowable-bpmn/src/test/java/org/apache/syncope/core/flowable/impl/UELSandboxTest.java
new file mode 100644
index 0000000000..a9320f1f90
--- /dev/null
+++ 
b/ext/flowable/flowable-bpmn/src/test/java/org/apache/syncope/core/flowable/impl/UELSandboxTest.java
@@ -0,0 +1,77 @@
+package org.apache.syncope.core.flowable.impl;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.lang.reflect.Field;
+import java.util.Map;
+import java.util.Set;
+import org.apache.syncope.common.lib.request.UserCR;
+import org.apache.syncope.common.lib.request.UserUR;
+import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.core.persistence.api.entity.user.User;
+import org.junit.jupiter.api.Test;
+
+class UELSandboxTest {
+
+    @Test
+    void allowedExpressions() {
+        String[] allowed = new String[] {
+            "${user.checkToken(token)}",
+            "${wfExecutor == user.getUsername() and task == 'update' and 
userUR.requiresApproval()}",
+            "${flowableUtils.isUserIngroup(userTO, 'groupForWorkflowOptIn')}"
+        };
+        for (String expr : allowed) {
+            assertTrue(UELSandbox.isAllowed(expr), () -> "Expression should be 
allowed: " + expr);
+        }
+    }
+
+    @Test
+    void blockedExpressions() {
+        String[] blocked = new String[] {
+            
"${''.getClass().forName('java.io.File').getConstructor(''.getClass())."
+            + "newInstance('/tmp/syncope_conditionexpression_check.txt')}",
+            "${java.lang.Runtime.getRuntime().exec('whoami')}"
+        };
+        for (String expr : blocked) {
+            assertFalse(UELSandbox.isAllowed(expr), () -> "Expression should 
be blocked: " + expr);
+        }
+    }
+
+    @Test
+    void allWhitelistedMethods() throws Exception {
+        Field whitelistField = UELSandbox.class.getDeclaredField("WHITELIST");
+        whitelistField.setAccessible(true);
+        @SuppressWarnings("unchecked")
+        Map<String, Set<String>> whitelist = (Map<String, Set<String>>) 
whitelistField.get(null);
+        for (Map.Entry<String, Set<String>> entry : whitelist.entrySet()) {
+            String bean = entry.getKey();
+            Class<?> cls = switch (bean) {
+                case "user" ->
+                    User.class;
+                case "userCR" ->
+                    UserCR.class;
+                case "userUR" ->
+                    UserUR.class;
+                case "userTO" ->
+                    UserTO.class;
+                case "flowableUtils" ->
+                    FlowableWorkflowUtils.class;
+                default ->
+                    Object.class;
+            };
+
+            for (String method : entry.getValue()) {
+                // Skip methods that require parameters
+                try {
+                    if (cls.getMethod(method).getParameterCount() == 0) {
+                        String expr = "${" + bean + "." + method + "()}";
+                        assertTrue(UELSandbox.isAllowed(expr), () -> 
"Expression should be allowed: " + expr);
+                    }
+                } catch (NoSuchMethodException ignored) {
+                    // method not found or non‑public; ignore
+                }
+            }
+        }
+    }
+}

Reply via email to