Skip to content

Commit d71bcb5

Browse files
committed
Kusal experimental
1 parent e9a1668 commit d71bcb5

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

core/src/main/java/com/opensymphony/xwork2/config/providers/XmlDocConfigurationProvider.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ public void setValueSubstitutor(ValueSubstitutor valueSubstitutor) {
109109
this.valueSubstitutor = valueSubstitutor;
110110
}
111111

112+
@Inject
113+
public void setProviderAllowlist(ProviderAllowlist providerAllowlist) {
114+
this.providerAllowlist = providerAllowlist;
115+
}
116+
112117
public XmlDocConfigurationProvider(Document... documents) {
113118
this.documents = Arrays.asList(documents);
114119
}
@@ -135,11 +140,6 @@ public void init(Configuration configuration) {
135140
this.configuration = configuration;
136141
}
137142

138-
private void registerAllowlist() {
139-
providerAllowlist = configuration.getContainer().getInstance(ProviderAllowlist.class);
140-
providerAllowlist.registerAllowlist(this, allowlistClasses);
141-
}
142-
143143
@Override
144144
public void destroy() {
145145
if (providerAllowlist != null) {
@@ -152,6 +152,7 @@ protected Class<?> allowAndLoadClass(String className) throws ClassNotFoundExcep
152152
allowlistClasses.add(clazz);
153153
allowlistClasses.addAll(ClassUtils.getAllSuperclasses(clazz));
154154
allowlistClasses.addAll(ClassUtils.getAllInterfaces(clazz));
155+
providerAllowlist.registerAllowlist(this, allowlistClasses);
155156
return clazz;
156157
}
157158

@@ -333,7 +334,6 @@ public void loadPackages() throws ConfigurationException {
333334
}
334335

335336
declaredPackages.clear();
336-
registerAllowlist();
337337
configuration = null;
338338
}
339339

core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -859,23 +859,14 @@ protected Map<String, Object> createDefaultContext(Object root) {
859859
return createDefaultContext(root, null);
860860
}
861861

862-
/**
863-
* Note that the allowlist capability is not enforced by the {@link OgnlContext} returned by this method. Currently,
864-
* this context is only leveraged by some public methods on {@link OgnlUtil} which are called by
865-
* {@link OgnlReflectionProvider}.
866-
*/
867862
protected Map<String, Object> createDefaultContext(Object root, ClassResolver resolver) {
868863
if (resolver == null) {
869864
resolver = container.getInstance(RootAccessor.class);
870865
if (resolver == null) {
871866
throw new IllegalStateException("Cannot find ClassResolver");
872867
}
873868
}
874-
875-
SecurityMemberAccess memberAccess = container.getInstance(SecurityMemberAccess.class);
876-
memberAccess.useEnforceAllowlistEnabled(Boolean.FALSE.toString());
877-
878-
return Ognl.createDefaultContext(root, memberAccess, resolver, defaultConverter);
869+
return Ognl.createDefaultContext(root, container.getInstance(SecurityMemberAccess.class), resolver, defaultConverter);
879870
}
880871

881872
@FunctionalInterface

core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,12 @@ public void useExcludedPackageExemptClasses(String commaDelimitedClasses) {
479479
@Inject(value = StrutsConstants.STRUTS_ALLOWLIST_ENABLE, required = false)
480480
public void useEnforceAllowlistEnabled(String enforceAllowlistEnabled) {
481481
this.enforceAllowlistEnabled = BooleanUtils.toBoolean(enforceAllowlistEnabled);
482+
if (!this.enforceAllowlistEnabled) {
483+
String msg = "OGNL allowlist is disabled!" +
484+
" We strongly recommend keeping it enabled to protect against critical vulnerabilities." +
485+
" Set the configuration `{}=true` to enable it.";
486+
LOG.warn(msg, StrutsConstants.STRUTS_ALLOWLIST_ENABLE);
487+
}
482488
}
483489

484490
@Inject(value = STRUTS_ALLOWLIST_CLASSES, required = false)

0 commit comments

Comments
 (0)