33
33
import org .apache .commons .lang3 .BooleanUtils ;
34
34
import org .apache .logging .log4j .LogManager ;
35
35
import org .apache .logging .log4j .Logger ;
36
+ import org .apache .struts2 .StrutsConstants ;
36
37
import org .apache .struts2 .dispatcher .HttpParameters ;
37
38
import org .apache .struts2 .dispatcher .Parameter ;
38
39
39
40
import java .util .Collection ;
40
41
import java .util .Comparator ;
41
42
import java .util .Map ;
42
43
import java .util .TreeMap ;
44
+ import java .util .regex .Pattern ;
43
45
44
46
/**
45
47
* This interceptor sets all parameters on the value stack.
@@ -49,9 +51,11 @@ public class ParametersInterceptor extends MethodFilterInterceptor {
49
51
private static final Logger LOG = LogManager .getLogger (ParametersInterceptor .class );
50
52
51
53
protected static final int PARAM_NAME_MAX_LENGTH = 100 ;
54
+ private static final Pattern DMI_IGNORED_PATTERN = Pattern .compile ("^(action|method):.*" , Pattern .CASE_INSENSITIVE );
52
55
53
56
private int paramNameMaxLength = PARAM_NAME_MAX_LENGTH ;
54
57
private boolean devMode = false ;
58
+ private boolean dmiEnabled = false ;
55
59
56
60
protected boolean ordered = false ;
57
61
@@ -79,6 +83,11 @@ public void setAcceptedPatterns(AcceptedPatternsChecker acceptedPatterns) {
79
83
this .acceptedPatterns = acceptedPatterns ;
80
84
}
81
85
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
+
82
91
/**
83
92
* If the param name exceeds the configured maximum length it will not be
84
93
* accepted.
@@ -285,13 +294,25 @@ protected String getParameterLogMap(HttpParameters parameters) {
285
294
}
286
295
287
296
protected boolean acceptableName (String name ) {
297
+ if (isIgnoredDMI (name )) {
298
+ LOG .trace ("DMI is enabled, ignoring DMI method: {}" , name );
299
+ return false ;
300
+ }
288
301
boolean accepted = isWithinLengthLimit (name ) && !isExcluded (name ) && isAccepted (name );
289
302
if (devMode && accepted ) { // notify only when in devMode
290
303
LOG .debug ("Parameter [{}] was accepted and will be appended to action!" , name );
291
304
}
292
305
return accepted ;
293
306
}
294
307
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
+
295
316
protected boolean isWithinLengthLimit (String name ) {
296
317
boolean matchLength = name .length () <= paramNameMaxLength ;
297
318
if (!matchLength ) {
0 commit comments