Skip to content

Commit

Permalink
Merge pull request #988 from apache/kusal-experimental
Browse files Browse the repository at this point in the history
WW-5442 Enforce allowlist for OgnlReflectionProvider
  • Loading branch information
kusalk authored Jul 14, 2024
2 parents 9ea9d56 + b7b5bff commit 085471b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
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

0 comments on commit 085471b

Please sign in to comment.