Skip to content

Commit

Permalink
Applies better exclude patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed May 3, 2015
1 parent 8ab3272 commit d832747
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
18 changes: 5 additions & 13 deletions core/src/main/resources/struts-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
ognl.TypeConverter,
com.opensymphony.xwork2.ActionContext" />
<!-- this must be valid regex, each '.' in package name must be escaped! -->
<constant name="struts.excludedPackageNamePatterns" value="^java\.lang\..*,^ognl.*,^javax.*" />
<constant name="struts.excludedPackageNamePatterns" value="^java\.lang\..*,^ognl.*,^(?!javax\.servlet\..+)(javax\..+)" />

<bean class="com.opensymphony.xwork2.ObjectFactory" name="struts"/>
<bean type="com.opensymphony.xwork2.factory.ResultFactory" name="struts" class="org.apache.struts2.factory.StrutsResultFactory" />
Expand Down Expand Up @@ -224,9 +224,7 @@
<interceptor-ref name="datetime"/>
<interceptor-ref name="multiselect"/>
<interceptor-ref name="actionMappingParams"/>
<interceptor-ref name="params">
<param name="excludeParams">^action:.*,^method:.*</param>
</interceptor-ref>
<interceptor-ref name="params"/>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="deprecation"/>
</interceptor-stack>
Expand Down Expand Up @@ -281,19 +279,15 @@
<interceptor-ref name="checkbox"/>
<interceptor-ref name="datetime"/>
<interceptor-ref name="multiselect"/>
<interceptor-ref name="params">
<param name="excludeParams">^action:.*,^method:.*</param>
</interceptor-ref>
<interceptor-ref name="params"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="chain"/>
<interceptor-ref name="modelDriven"/>
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="staticParams"/>
<interceptor-ref name="actionMappingParams"/>
<interceptor-ref name="params">
<param name="excludeParams">^action:.*,^method:.*</param>
</interceptor-ref>
<interceptor-ref name="params"/>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
Expand Down Expand Up @@ -329,9 +323,7 @@
<interceptor-ref name="multiselect"/>
<interceptor-ref name="staticParams"/>
<interceptor-ref name="actionMappingParams"/>
<interceptor-ref name="params">
<param name="excludeParams">^action:.*,^method:.*</param>
</interceptor-ref>
<interceptor-ref name="params"/>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import javax.servlet.http.Cookie;

import com.opensymphony.xwork2.security.DefaultAcceptedPatternsChecker;
import com.opensymphony.xwork2.security.DefaultExcludedPatternsChecker;
import com.opensymphony.xwork2.mock.MockActionInvocation;
import org.easymock.MockControl;
Expand Down Expand Up @@ -370,7 +371,9 @@ protected boolean isAcceptableValue(String value) {
return accepted;
}
};
interceptor.setExcludedPatternsChecker(new DefaultExcludedPatternsChecker());
DefaultExcludedPatternsChecker excludedPatternsChecker = new DefaultExcludedPatternsChecker();
excludedPatternsChecker.setAdditionalExcludePatterns(".*(^|\\.|\\[|'|\")class(\\.|\\[|'|\").*");
interceptor.setExcludedPatternsChecker(excludedPatternsChecker);
interceptor.setCookiesName("*");

MockActionInvocation invocation = new MockActionInvocation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,8 @@ public class DefaultExcludedPatternsChecker implements ExcludedPatternsChecker {
private static final Logger LOG = LoggerFactory.getLogger(DefaultExcludedPatternsChecker.class);

public static final String[] EXCLUDED_PATTERNS = {
"(.*\\.|^|.*|\\[('|\"))\\bclass(\\.|('|\")]|\\[).*",
"(^|.*#)dojo(\\.|\\[).*",
"(^|.*#)struts(\\.|\\[).*",
"(^|.*#)session(\\.|\\[).*",
"(^|.*#)request(\\.|\\[).*",
"(^|.*#)application(\\.|\\[).*",
"(^|.*#)servlet(Request|Response)(\\.|\\[).*",
"(^|.*#)parameters(\\.|\\[).*",
"(^|.*#)context(\\.|\\[).*",
"(^|.*#)_memberAccess(\\.|\\[).*"
"(^|.*#)(dojo|struts|session|request|application|servlet(Request|Response)|parameters|context|_memberAccess)(\\.|\\[).*",
"^(action|method):.*"
};

private Set<Pattern> excludedPatterns;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public void testHardcodedPatterns() throws Exception {
}
};

ExcludedPatternsChecker checker = new DefaultExcludedPatternsChecker();
DefaultExcludedPatternsChecker checker = new DefaultExcludedPatternsChecker();
checker.setAdditionalExcludePatterns(".*(^|\\.|\\[|'|\")class(\\.|\\[|'|\").*");

for (String param : params) {
// when
Expand All @@ -71,6 +72,8 @@ public void testParamWithClassInName() throws Exception {
properParams.add("form.eventClass");
properParams.add("form[\"eventClass\"]");
properParams.add("form['eventClass']");
properParams.add("class.super@demo.com");
properParams.add("super.class@demo.com");

ExcludedPatternsChecker checker = new DefaultExcludedPatternsChecker();

Expand Down Expand Up @@ -100,4 +103,4 @@ public void testStrutsTokenIsExcluded() throws Exception {
}
}

}
}
3 changes: 2 additions & 1 deletion xwork-core/src/test/resources/xwork-param-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
<xwork>
<constant name="devMode" value="true" />
<constant name="ognlExcludedClasses" value="java.lang.Object,java.lang.Runtime" />
</xwork>
<constant name="additionalExcludedPatterns" value=".*(^|\.|\[|\'|&quot;)class(\.|\[|\'|&quot;).*" />
</xwork>

0 comments on commit d832747

Please sign in to comment.