@Component(value="blMvelExpressionValidator") public class MvelExpressionValidator extends Object
MvelHelper compiles them. MVEL has no
sandbox of its own, so an expression is rejected if it uses new, a reflection method
(BLOCKED_REFLECTION_METHODS), a method that can run commands or change the server or its data
(BLOCKED_METHODS), or a statement separator (;). Methods are
blocked whether they are called with parentheses or accessed like a property, since MVEL calls no argument methods
for both.
MVEL.eval can evaluate any expression, so only the legacy MVEL.eval("toUpperCase()", value) form
generated by older versions of the rule builder is allowed.
String literals are removed before the check, read the same way MVEL reads them, so their contents are never mistaken for code.
The validation can be turned off with the mvel.expression.validation.enabled property. Methods can be
blocked in addition to the built-in ones with the mvel.expression.validation.blocked.methods property, and
built-in ones can be allowed with the mvel.expression.validation.allowed.methods property, e.g. for custom
fields with the same name as a blocked method. This class is a bean only so that the properties can be injected.
| Modifier | Constructor and Description |
|---|---|
protected |
MvelExpressionValidator() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
isAllowed(String expression)
Checks the expression and logs a warning if it is not allowed.
|
void |
setAllowedMethods(String allowedMethods) |
void |
setBlockedMethods(String blockedMethods) |
void |
setEnabled(boolean enabled) |
@Value(value="${mvel.expression.validation.enabled:true}")
public void setEnabled(boolean enabled)
@Value(value="${mvel.expression.validation.blocked.methods:}")
public void setBlockedMethods(String blockedMethods)
blockedMethods - comma separated method names to block in addition to the built-in ones@Value(value="${mvel.expression.validation.allowed.methods:}")
public void setAllowedMethods(String allowedMethods)
allowedMethods - comma separated built-in blocked method names to allow, e.g. for custom fields that have
the same name as a blocked methodpublic static boolean isAllowed(String expression)
expression - the MVEL expression exactly as it will be compiledCopyright © 2026. All rights reserved.