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-5442 Enforce allowlist for OgnlReflectionProvider #988

Merged
merged 1 commit into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public void setValueSubstitutor(ValueSubstitutor valueSubstitutor) {
this.valueSubstitutor = valueSubstitutor;
}

@Inject
public void setProviderAllowlist(ProviderAllowlist providerAllowlist) {
this.providerAllowlist = providerAllowlist;
}

public XmlDocConfigurationProvider(Document... documents) {
this.documents = Arrays.asList(documents);
}
Expand All @@ -135,11 +140,6 @@ public void init(Configuration configuration) {
this.configuration = configuration;
}

private void registerAllowlist() {
providerAllowlist = configuration.getContainer().getInstance(ProviderAllowlist.class);
providerAllowlist.registerAllowlist(this, allowlistClasses);
}

@Override
public void destroy() {
if (providerAllowlist != null) {
Expand All @@ -152,6 +152,7 @@ protected Class<?> allowAndLoadClass(String className) throws ClassNotFoundExcep
allowlistClasses.add(clazz);
allowlistClasses.addAll(ClassUtils.getAllSuperclasses(clazz));
allowlistClasses.addAll(ClassUtils.getAllInterfaces(clazz));
providerAllowlist.registerAllowlist(this, allowlistClasses);
return clazz;
}

Expand Down Expand Up @@ -333,7 +334,6 @@ public void loadPackages() throws ConfigurationException {
}

declaredPackages.clear();
registerAllowlist();
configuration = null;
}

Expand Down
11 changes: 1 addition & 10 deletions core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -859,23 +859,14 @@ protected Map<String, Object> createDefaultContext(Object root) {
return createDefaultContext(root, null);
}

/**
* Note that the allowlist capability is not enforced by the {@link OgnlContext} returned by this method. Currently,
* this context is only leveraged by some public methods on {@link OgnlUtil} which are called by
* {@link OgnlReflectionProvider}.
*/
protected Map<String, Object> createDefaultContext(Object root, ClassResolver resolver) {
if (resolver == null) {
resolver = container.getInstance(RootAccessor.class);
if (resolver == null) {
throw new IllegalStateException("Cannot find ClassResolver");
}
}

SecurityMemberAccess memberAccess = container.getInstance(SecurityMemberAccess.class);
memberAccess.useEnforceAllowlistEnabled(Boolean.FALSE.toString());

return Ognl.createDefaultContext(root, memberAccess, resolver, defaultConverter);
return Ognl.createDefaultContext(root, container.getInstance(SecurityMemberAccess.class), resolver, defaultConverter);
}

@FunctionalInterface
Expand Down