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-5288 Make excluded package exemption logic more strict #664

Merged
merged 3 commits into from
Mar 21, 2023

Conversation

kusalk
Copy link
Member

@kusalk kusalk commented Mar 2, 2023

WW-5288

See Jira card description then PR comments below.

for (Pattern pattern : excludedPackageNamePatterns) {
if (pattern.matcher(targetPackageName).matches() || pattern.matcher(memberPackageName).matches()) {
for (Class<?> clazz : classesToCheck) {
if (!isExcludedPackageExempt(clazz) && (isExcludedPackageNamePatterns(clazz) || isExcludedPackageNames(clazz))) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Exemption must now exist for both classes (target and member) if they both match a banned package

}

protected boolean isExcludedPackageExempt(Class<?> clazz) {
return excludedPackageExemptClasses.stream().anyMatch(clazz::equals);
Copy link
Member Author

@kusalk kusalk Mar 2, 2023

Choose a reason for hiding this comment

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

Do not exempt superclasses (use #equals instead of #isAssignableFrom)

final Class<?> memberClass = member.getDeclaringClass();
// target can be null in case of accessing static fields, since OGNL 3.2.8
final Class<?> targetClass = Modifier.isStatic(memberModifiers) ? memberClass : target.getClass();
if (!memberClass.isAssignableFrom(targetClass)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Added some validation here and in #isPackageExcluded to ensure unit tests made sense

@@ -413,10 +413,13 @@ public final class StrutsConstants {
/** Allows override default DispatcherErrorHandler */
public static final String STRUTS_DISPATCHER_ERROR_HANDLER = "struts.dispatcher.errorHandler";

/** Comma delimited set of excluded classes and package names which cannot be accessed via expressions */
/** Comma delimited set of excluded classes which cannot be accessed via OGNL expressions. Matching is done on both target and member classes of OGNL expression. Note that superclasses of listed classes are also used for matching. */
Copy link
Member Author

Choose a reason for hiding this comment

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

Tried my best to describe the code logic in words for all these options.


@Override
protected void assignNewSma(boolean allowStaticFieldAccess) {
sma = new ExternalSecurityMemberAccess(allowStaticFieldAccess);
Copy link
Member Author

Choose a reason for hiding this comment

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

We have two SecurityMemberAccessTest in two different packages to test two different behaviours. One test is in the package com.opensymphony.xwork2.ognl which is excluded.

@lukaszlenart Do you think this is an okay solution?

Copy link
Member

@lukaszlenart lukaszlenart Mar 11, 2023

Choose a reason for hiding this comment

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

Nope :) Yet testing the MemberAccess behaviour for different settings makes sense, this is the last line of defence :)

@lukaszlenart
Copy link
Member

@yasserzamani @JCgH4164838Gh792C124B5 any thoughts?

Copy link
Member

@lukaszlenart lukaszlenart left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@lukaszlenart
Copy link
Member

Do you plan to document this option?

@lukaszlenart lukaszlenart merged commit 960682a into apache:master Mar 21, 2023
@kusalk
Copy link
Member Author

kusalk commented Mar 22, 2023

Do you plan to document this option?

I'll create a PR :)

@kusalk kusalk deleted the WW-5288-exemption-strict branch March 22, 2023 02:02
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