Skip to content

WW-5534 Allow @StrutsParameter recognition and OGNL allowlist for Spring proxies#1237

Merged
kusalk merged 2 commits into
mainfrom
WW-5534-annotation-allowlist-proxy
Mar 6, 2025
Merged

WW-5534 Allow @StrutsParameter recognition and OGNL allowlist for Spring proxies#1237
kusalk merged 2 commits into
mainfrom
WW-5534-annotation-allowlist-proxy

Conversation

@kusalk

@kusalk kusalk commented Feb 27, 2025

Copy link
Copy Markdown
Member

WW-5534

This change fixes @StrutsParameter detection for Spring proxied Actions. It additionally adds optional support for resolving Spring proxies when enforcing the OGNL allowlist, alongside the existing support for resolving Hibernate proxies.

@kusalk kusalk force-pushed the WW-5534-annotation-allowlist-proxy branch 2 times, most recently from 2df54ea to b075b67 Compare February 27, 2025 19:22
return true;
}

private void logAllowlistHibernateEntity(Object original, Object resolved) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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

@kusalk kusalk force-pushed the WW-5534-annotation-allowlist-proxy branch from 24d6242 to edda3e4 Compare March 3, 2025 10:50
protected BeanInfo getBeanInfo(Object action) {
try {
return Introspector.getBeanInfo(action.getClass());
return ognlUtil.getBeanInfo(ultimateClass(action));

Copy link
Copy Markdown
Member Author

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 OgnlUtil already had a cached variant of this capability. We are now using that, and resolving any proxies to ensure annotation detection works as expected.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added comments for all the other tests in this class as I realised I didn't name them very well initially

*/
@Test
public void publicModelPojo_proxied() {
var proxyFactory = new ProxyFactory(new ModelAction());

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We use the Spring proxy factory to create a CGLIB proxy like would occur when a transactional proxy is applied to a concrete Action class (like in the original bug report)

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);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We replaced #getHibernateProxyTarget with #ultimateTargetClass which can also resolve Spring proxies. This allows the OGNL allowlist to function in the presence of Spring proxies in applications where struts.disallowProxyObjectAccess has been reverted to false.

Base automatically changed from WW-5534-proxyutil to main March 5, 2025 10:48
@kusalk kusalk force-pushed the WW-5534-annotation-allowlist-proxy branch from edda3e4 to 85d69c5 Compare March 5, 2025 10:50
@kusalk kusalk marked this pull request as ready for review March 5, 2025 10:50
Comment on lines +972 to +987
/**
* When the allowlist is enabled and proxy object access is allowed, Spring proxies should be allowlisted based
* on their underlying target object. Class allowlisting should work as expected.
*/
@Test
public void classInclusion_springProxy_allowProxyObjectAccess() throws Exception {
SpringService proxyObject = newSpringService();
Method proxyMethod = proxyObject.getClass().getMethod("doSomething");

sma.useEnforceAllowlistEnabled(Boolean.TRUE.toString());
sma.useDisallowProxyObjectAccess(Boolean.FALSE.toString());
sma.useAllowlistClasses(SpringServiceImpl.class.getName());

assertTrue(sma.checkAllowlist(proxyObject, proxyMethod));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is a dedicated SecurityMemberAccessProxyTest and maybe it would be good to move proxy related test cases there as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done!

@lukaszlenart lukaszlenart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Left one comment, looks good!

@kusalk kusalk force-pushed the WW-5534-annotation-allowlist-proxy branch from 85d69c5 to 433c483 Compare March 6, 2025 01:14
@sonarqubecloud

sonarqubecloud Bot commented Mar 6, 2025

Copy link
Copy Markdown

@kusalk kusalk merged commit 747859b into main Mar 6, 2025
@kusalk kusalk deleted the WW-5534-annotation-allowlist-proxy branch March 6, 2025 01:24
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