Skip to content

Commit adf648d

Browse files
authored
Merge 0f69c3b into b2580e1
2 parents b2580e1 + 0f69c3b commit adf648d

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@
3333
import org.apache.commons.lang3.BooleanUtils;
3434
import org.apache.logging.log4j.LogManager;
3535
import org.apache.logging.log4j.Logger;
36+
import org.apache.struts2.StrutsConstants;
3637
import org.apache.struts2.dispatcher.HttpParameters;
3738
import org.apache.struts2.dispatcher.Parameter;
3839

3940
import java.util.Collection;
4041
import java.util.Comparator;
4142
import java.util.Map;
4243
import java.util.TreeMap;
44+
import java.util.regex.Pattern;
4345

4446
/**
4547
* This interceptor sets all parameters on the value stack.
@@ -49,9 +51,11 @@ public class ParametersInterceptor extends MethodFilterInterceptor {
4951
private static final Logger LOG = LogManager.getLogger(ParametersInterceptor.class);
5052

5153
protected static final int PARAM_NAME_MAX_LENGTH = 100;
54+
private static final Pattern DMI_IGNORED_PATTERN = Pattern.compile("^(action|method):.*", Pattern.CASE_INSENSITIVE);
5255

5356
private int paramNameMaxLength = PARAM_NAME_MAX_LENGTH;
5457
private boolean devMode = false;
58+
private boolean dmiEnabled = false;
5559

5660
protected boolean ordered = false;
5761

@@ -79,6 +83,11 @@ public void setAcceptedPatterns(AcceptedPatternsChecker acceptedPatterns) {
7983
this.acceptedPatterns = acceptedPatterns;
8084
}
8185

86+
@Inject(value = StrutsConstants.STRUTS_ENABLE_DYNAMIC_METHOD_INVOCATION, required = false)
87+
public void setDmiEnabled(String dmiEnabled) {
88+
this.dmiEnabled = Boolean.parseBoolean(dmiEnabled);
89+
}
90+
8291
/**
8392
* If the param name exceeds the configured maximum length it will not be
8493
* accepted.
@@ -285,13 +294,25 @@ protected String getParameterLogMap(HttpParameters parameters) {
285294
}
286295

287296
protected boolean acceptableName(String name) {
297+
if (isIgnoredDMI(name)) {
298+
LOG.trace("DMI is enabled, ignoring DMI method: {}", name);
299+
return false;
300+
}
288301
boolean accepted = isWithinLengthLimit(name) && !isExcluded(name) && isAccepted(name);
289302
if (devMode && accepted) { // notify only when in devMode
290303
LOG.debug("Parameter [{}] was accepted and will be appended to action!", name);
291304
}
292305
return accepted;
293306
}
294307

308+
private boolean isIgnoredDMI(String name) {
309+
if (dmiEnabled) {
310+
return DMI_IGNORED_PATTERN.matcher(name).matches();
311+
} else {
312+
return false;
313+
}
314+
}
315+
295316
protected boolean isWithinLengthLimit(String name) {
296317
boolean matchLength = name.length() <= paramNameMaxLength;
297318
if (!matchLength) {

core/src/test/java/com/opensymphony/xwork2/interceptor/ParametersInterceptorTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,33 @@ public void testInternalParametersAreIgnored() throws Exception {
715715
assertEquals(expected, actual);
716716
}
717717

718+
public void testDMIMethodsAreIgnored() throws Exception {
719+
// given
720+
ParametersInterceptor interceptor = createParametersInterceptor();
721+
final Map<String, Object> actual = injectValueStackFactory(interceptor);
722+
ValueStack stack = injectValueStack(actual);
723+
724+
final Map<String, Object> expected = new HashMap<String, Object>() {
725+
{
726+
put("ordinary.bean", "value");
727+
}
728+
};
729+
730+
Map<String, Object> parameters = new HashMap<String, Object>() {
731+
{
732+
put("ordinary.bean", "value");
733+
put("action:", "myAction");
734+
put("method:", "doExecute");
735+
}
736+
};
737+
738+
// when
739+
interceptor.setParameters(new NoParametersAction(), stack, HttpParameters.create(parameters).build());
740+
741+
// then
742+
assertEquals(expected, actual);
743+
}
744+
718745
public void testBeanListSingleValue() throws Exception {
719746
Map<String, Object> params = new HashMap<>();
720747
params.put("beanList.name", new String[] { "Superman" });

0 commit comments

Comments
 (0)