Skip to content

Commit

Permalink
Throws away methods that doesn't match pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed May 12, 2016
1 parent 8b688cc commit 27ca165
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.struts2.RequestUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.StrutsException;
import org.apache.struts2.util.PrefixTrie;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -385,14 +386,7 @@ protected String cleanupActionName(final String rawActionName) {
if (allowedActionNames.matcher(rawActionName).matches()) {
return rawActionName;
} else {
LOG.warn("Action [{}] does not match allowed action names pattern [{}], cleaning it up!",
rawActionName, allowedActionNames);
String cleanActionName = rawActionName;
for (String chunk : allowedActionNames.split(rawActionName)) {
cleanActionName = cleanActionName.replace(chunk, "");
}
LOG.debug("Cleaned action name [{}]", cleanActionName);
return cleanActionName;
throw new StrutsException("Action [" + rawActionName + "] does not match allowed action names pattern [" + allowedActionNames + "]!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.opensymphony.xwork2.config.entities.PackageConfig;
import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsException;
import org.apache.struts2.StrutsInternalTestCase;
import org.apache.struts2.result.StrutsResultSupport;
import org.apache.struts2.views.jsp.StrutsMockHttpServletRequest;
Expand Down Expand Up @@ -844,14 +845,37 @@ public void testAllowedActionNames() throws Exception {
String actionName = "action";
assertEquals(actionName, mapper.cleanupActionName(actionName));

Throwable expected = null;

actionName = "${action}";
assertEquals("action", mapper.cleanupActionName(actionName));
try {
mapper.cleanupActionName(actionName);
fail();
} catch (Throwable t) {
expected = t;
}
assertTrue(expected instanceof StrutsException);
assertEquals("Action [${action}] does not match allowed action names pattern [[a-zA-Z0-9._!/\\-]*]!", expected.getMessage());

actionName = "${${%{action}}}";
assertEquals("action", mapper.cleanupActionName(actionName));
try {
mapper.cleanupActionName(actionName);
fail();
} catch (Throwable t) {
expected = t;
}
assertTrue(expected instanceof StrutsException);
assertEquals("Action [${${%{action}}}] does not match allowed action names pattern [[a-zA-Z0-9._!/\\-]*]!", expected.getMessage());

actionName = "${#foo='action',#foo}";
assertEquals("fooactionfoo", mapper.cleanupActionName(actionName));
try {
mapper.cleanupActionName(actionName);
fail();
} catch (Throwable t) {
expected = t;
}
assertTrue(expected instanceof StrutsException);
assertEquals("Action [${#foo='action',#foo}] does not match allowed action names pattern [[a-zA-Z0-9._!/\\-]*]!", expected.getMessage());

actionName = "test-action";
assertEquals("test-action", mapper.cleanupActionName(actionName));
Expand Down

0 comments on commit 27ca165

Please sign in to comment.