Skip to content

Commit

Permalink
WW-5354 Ensure ActionSupport fields are not parameter injectable
Browse files Browse the repository at this point in the history
  • Loading branch information
kusalk committed Oct 12, 2023
1 parent 23feab6 commit 0432205
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public class DefaultExcludedPatternsChecker implements ExcludedPatternsChecker {
private static final Logger LOG = LogManager.getLogger(DefaultExcludedPatternsChecker.class);

public static final String[] EXCLUDED_PATTERNS = {
"(^|\\%\\{)((#?)(top(\\.|\\['|\\[\")|\\[\\d\\]\\.)?)(dojo|struts|session|request|response|application|servlet(Request|Response|Context)|parameters|context|_memberAccess)(\\.|\\[).*",
".*(^|\\.|\\[|\\'|\"|get)class(\\(\\.|\\[|\\'|\").*"
"(^|\\%\\{)((#?)(top(\\.|\\['|\\[\")|\\[\\d\\]\\.)?)(dojo|struts|session|request|response|application|servlet(Request|Response|Context)|parameters|context|_memberAccess)(\\.|\\[).*",
".*(^|\\.|\\[|\\'|\"|get)class(\\(\\.|\\[|\\'|\").*",
"actionErrors|actionMessages|fieldErrors"
};

private Set<Pattern> excludedPatterns;
Expand All @@ -48,21 +49,7 @@ public DefaultExcludedPatternsChecker() {

@Inject(value = StrutsConstants.STRUTS_OVERRIDE_EXCLUDED_PATTERNS, required = false)
protected void setOverrideExcludePatterns(String excludePatterns) {
if (excludedPatterns != null && excludedPatterns.size() > 0) {
LOG.warn("Overriding excluded patterns [{}] with [{}], be aware that this affects all instances and safety of your application!",
excludedPatterns, excludePatterns);
} else {
// Limit unwanted log entries (when excludedPatterns null/empty - usually 1st call)
LOG.debug("Overriding excluded patterns with [{}]", excludePatterns);
}
excludedPatterns = new HashSet<>();
try {
for (String pattern : TextParseUtil.commaDelimitedStringToSet(excludePatterns)) {
excludedPatterns.add(Pattern.compile(pattern, Pattern.CASE_INSENSITIVE));
}
} finally {
excludedPatterns = Collections.unmodifiableSet(excludedPatterns);
}
setExcludedPatterns(excludePatterns);
}

@Inject(value = StrutsConstants.STRUTS_ADDITIONAL_EXCLUDED_PATTERNS, required = false)
Expand Down Expand Up @@ -98,7 +85,7 @@ public void setExcludedPatterns(String[] patterns) {

@Override
public void setExcludedPatterns(Set<String> patterns) {
if (excludedPatterns != null && excludedPatterns.size() > 0) {
if (excludedPatterns != null && !excludedPatterns.isEmpty()) {
LOG.warn("Replacing excluded patterns [{}] with [{}], be aware that this affects all instances and safety of your application!",
excludedPatterns, patterns);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDrivenAction;
import com.opensymphony.xwork2.SimpleAction;
import com.opensymphony.xwork2.TestBean;
Expand Down Expand Up @@ -300,7 +301,7 @@ public void testArrayClassPollutionBlockedByPattern() throws Exception {
}
};

final Map<String, Boolean> excluded = new HashMap<String, Boolean>();
final Map<String, Boolean> excluded = new HashMap<>();
ParametersInterceptor pi = new ParametersInterceptor() {

@Override
Expand Down Expand Up @@ -364,6 +365,19 @@ public void testParameters() throws Exception {
assertEquals("This is blah", ((SimpleAction) proxy.getAction()).getBlah());
}

public void testActionSupportParametersBlocked() throws Exception {
Map<String, Object> params = new HashMap<>();
params.put("actionErrors", "fakeError");
params.put("actionMessages", "fakeMessage");

ActionContext extraContext = ActionContext.of().withParameters(HttpParameters.create(params).build());

ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, null, extraContext.getContextMap());
proxy.execute();
assertEquals(0, ((ActionSupport) proxy.getAction()).getActionMessages().size());
assertEquals(0, ((ActionSupport) proxy.getAction()).getActionErrors().size());
}

public void testParametersWithSpacesInTheName() throws Exception {
Map<String, Object> params = new HashMap<>();
params.put("theProtectedMap['p0 p1']", "test1");
Expand Down

0 comments on commit 0432205

Please sign in to comment.