Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WW-5364 Automatically populate OGNL allowlist #800

Merged
merged 16 commits into from
Dec 5, 2023

Conversation

kusalk
Copy link
Member

@kusalk kusalk commented Nov 23, 2023

WW-5364

We automatically populate the allowlist from interceptors, actions and result types defined in XML configuration.
This will allow most applications to turn on the OGNL allowlist with no or limited additional configuration.
We can then consider turning this security option on by default in Struts 7.0.

Documentation: apache/struts-site#213

@kusalk kusalk force-pushed the WW-5364-populate-allowlist branch 3 times, most recently from 6a47136 to 324f825 Compare November 24, 2023 09:55
# Conflicts:
#	core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java
Base automatically changed from WW-5343-sec-extend to master November 26, 2023 08:36
@kusalk
Copy link
Member Author

kusalk commented Nov 26, 2023

WIP: Need to add more unit test coverage for this one

@@ -34,6 +34,19 @@
<constant name="struts.custom.i18n.resources" value="globalMessages" />
<constant name="struts.action.extension" value="action,," />

<constant name="struts.allowlist.enable" value="true" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this here so that we can utilise it for tests in core

@@ -395,6 +359,57 @@ protected Container createBootstrapContainer(List<ContainerProvider> providers)
return builder.create(true);
}

public static ContainerBuilder bootstrapFactories(ContainerBuilder builder) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted code into this method for reuse by the StrutsDefaultConfigurationProvider

@@ -57,6 +59,19 @@ public class SecurityMemberAccess implements MemberAccess {

private static final Logger LOG = LogManager.getLogger(SecurityMemberAccess.class);

private static final Set<String> ALLOWLIST_REQUIRED_PACKAGES = unmodifiableSet(new HashSet<>(Arrays.asList(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required system allowlist defined here - it's possible I've missed some packages/classes, can add as needed

@@ -65,12 +80,14 @@ public class SecurityMemberAccess implements MemberAccess {
private Set<String> excludedPackageNames = emptySet();
private Set<String> excludedPackageExemptClasses = emptySet();
private boolean enforceAllowlistEnabled = false;
private Set<String> allowlistClasses = emptySet();
private Set<Class<?>> allowlistClasses = emptySet();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we use String comparison for the exclusion list, we use Class comparison for the allowlist to prevent accidentally allowing through another Class with the same name (in applications with multiple classloaders)

Class.forName("com.opensymphony.xwork2.TextProvider"),
Class.forName("org.apache.struts2.interceptor.NoOpInterceptor"),
Class.forName("com.opensymphony.xwork2.interceptor.Interceptor"),
Class.forName("java.lang.Object"),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though java.lang.Object is added to the allowlist as it is a superclass, the exclusion list always takes precedence and so this class will not be allowed in practice

});
}

public abstract class XWorkJUnit4TestCase extends com.opensymphony.xwork2.XWorkJUnit4TestCase {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extended the moved class for compat

*/
package org.apache.struts2.junit;

public abstract class XWorkTestCase extends com.opensymphony.xwork2.XWorkTestCase {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this for consistency

@@ -44,8 +44,6 @@

<interceptors>
<interceptor name="alias" class="com.opensymphony.xwork2.interceptor.AliasInterceptor"/>
<interceptor name="autowiring"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class isn't provided by core

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made some changes to this file to attempt to load every class defined in a package and add it to the allowlist

@kusalk kusalk marked this pull request as ready for review December 4, 2023 11:45
Copy link

sonarcloud bot commented Dec 4, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 10 Code Smells

84.4% 84.4% Coverage
2.2% 2.2% Duplication

@kusalk kusalk merged commit 80e8361 into master Dec 5, 2023
10 checks passed
@kusalk kusalk deleted the WW-5364-populate-allowlist branch December 5, 2023 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants