-
Notifications
You must be signed in to change notification settings - Fork 834
WW-5534 Allow @StrutsParameter recognition and OGNL allowlist for Spring proxies #1237
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -212,16 +212,17 @@ protected boolean checkAllowlist(Object target, Member member) { | |
| return true; | ||
| } | ||
|
|
||
| Class<?> targetClass = target != null ? target.getClass() : null; | ||
|
|
||
| if (!disallowProxyObjectAccess && ProxyUtil.isProxy(target)) { | ||
| // If `disallowProxyObjectAccess` is not set, allow resolving Hibernate entities to their underlying | ||
| // classes/members. This allows the allowlist capability to continue working and offer some level of | ||
| // If `disallowProxyObjectAccess` is not set, allow resolving Hibernate entities and Spring proxies to their | ||
| // underlying classes/members. This allows the allowlist capability to continue working and still offer | ||
| // protection in applications where the developer has accepted the risk of allowing OGNL access to Hibernate | ||
| // entities. This is preferred to having to disable the allowlist capability entirely. | ||
| Object newTarget = ProxyUtil.getHibernateProxyTarget(target); | ||
| if (newTarget != target) { | ||
| logAllowlistHibernateEntity(target, newTarget); | ||
| target = newTarget; | ||
| member = ProxyUtil.resolveTargetMember(member, newTarget); | ||
| // entities and Spring proxies. This is preferred to having to disable the allowlist capability entirely. | ||
| Class<?> newTargetClass = ProxyUtil.ultimateTargetClass(target); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We replaced |
||
| if (newTargetClass != targetClass) { | ||
| targetClass = newTargetClass; | ||
| member = ProxyUtil.resolveTargetMember(member, newTargetClass); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -231,10 +232,10 @@ protected boolean checkAllowlist(Object target, Member member) { | |
| memberClass, member, STRUTS_ALLOWLIST_CLASSES, STRUTS_ALLOWLIST_PACKAGE_NAMES); | ||
| return false; | ||
| } | ||
| if (target == null || target.getClass() == memberClass) { | ||
|
|
||
| if (targetClass == null || targetClass == memberClass) { | ||
| return true; | ||
| } | ||
| Class<?> targetClass = target.getClass(); | ||
| if (!isClassAllowlisted(targetClass)) { | ||
| LOG.warn("Target class [{}] of target [{}] is not allowlisted! Add to '{}' or '{}' configuration.", | ||
| targetClass, target, STRUTS_ALLOWLIST_CLASSES, STRUTS_ALLOWLIST_PACKAGE_NAMES); | ||
|
|
@@ -243,20 +244,6 @@ protected boolean checkAllowlist(Object target, Member member) { | |
| return true; | ||
| } | ||
|
|
||
| private void logAllowlistHibernateEntity(Object original, Object resolved) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've decided to remove this warning as it's a tad aggressive. We've documented best practices in the migration guide and if users wish to still utilise Hibernate entities then that's up to them |
||
| if (!isDevMode && !LOG.isDebugEnabled()) { | ||
| return; | ||
| } | ||
| String msg = "Hibernate entity [{}] resolved to [{}] for purpose of OGNL allowlisting." + | ||
| " We don't recommend executing OGNL expressions against Hibernate entities, you may disallow this behaviour using the configuration `{}=true`."; | ||
| Object[] args = {original, resolved, StrutsConstants.STRUTS_DISALLOW_PROXY_OBJECT_ACCESS}; | ||
| if (isDevMode) { | ||
| LOG.warn(msg, args); | ||
| } else { | ||
| LOG.debug(msg, args); | ||
| } | ||
| } | ||
|
|
||
| protected boolean isClassAllowlisted(Class<?> clazz) { | ||
| return allowlistClasses.contains(clazz) | ||
| || ALLOWLIST_REQUIRED_CLASSES.contains(clazz) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I implemented this class, I forgot
OgnlUtilalready had a cached variant of this capability. We are now using that, and resolving any proxies to ensure annotation detection works as expected.