This is an automated email from the ASF dual-hosted git repository. ilgrosso pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/syncope.git
commit 4803236caaea86f5ca8b0fcd661c44fbe75c9f6a Author: Francesco Chicchiriccò <[email protected]> AuthorDate: Thu Nov 12 14:45:38 2026 +0100 Checking flowable:delegateExpression for allowed values --- .../core/flowable/impl/FlowableDeployUtils.java | 38 ++++++++++++++++------ 1 file changed, 28 insertions(+), 10 deletions(-) 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 95acee8a24..ff344f2c6e 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 @@ -18,17 +18,17 @@ */ package org.apache.syncope.core.flowable.impl; -import static org.flowable.bpmn.constants.BpmnXMLConstants.ATTRIBUTE_TASK_SERVICE_EXPRESSION; -import static org.flowable.bpmn.constants.BpmnXMLConstants.FLOWABLE_EXTENSIONS_NAMESPACE; - import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import javax.lang.model.SourceVersion; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; +import org.apache.commons.lang3.StringUtils; import org.apache.syncope.core.workflow.api.WorkflowException; +import org.flowable.bpmn.constants.BpmnXMLConstants; import org.flowable.bpmn.converter.BpmnXMLConverter; import org.flowable.bpmn.model.BpmnModel; import org.flowable.common.engine.api.FlowableException; @@ -38,11 +38,15 @@ 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; import tools.jackson.databind.json.JsonMapper; import tools.jackson.databind.node.ObjectNode; 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(); @@ -52,17 +56,31 @@ public final class FlowableDeployUtils { XML_INPUT_FACTORY.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); } - private static boolean containsExpression(final byte[] xml) throws XMLStreamException, IOException { + private static boolean isInvalid(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 (FLOWABLE_EXTENSIONS_NAMESPACE.equals(xtr.getAttributeNamespace(i)) - && ATTRIBUTE_TASK_SERVICE_EXPRESSION.equals(xtr.getAttributeLocalName(i))) { - - return true; + 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 -> { + } + } } } } @@ -78,8 +96,8 @@ public final class FlowableDeployUtils { final ProcessEngine engine, final String resourceName, final byte[] definition) { try { - if (containsExpression(definition)) { - throw new WorkflowException("Attribute flowable:expression is not allowed"); + if (isInvalid(definition)) { + throw new WorkflowException("The provided XML definition contains elements not allowed"); } } catch (IOException | XMLStreamException e) { throw new WorkflowException("While checking " + resourceName, e);
