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

add expression max length functionality for security enhancement #82

Merged

Conversation

yasserzamani
Copy link
Contributor

No description provided.

Copy link
Contributor

@JCgH4164838Gh792C124B5 JCgH4164838Gh792C124B5 left a comment

Choose a reason for hiding this comment

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

Hi Yasser.

This PR seems like a reasonable approach to me, and it provides an opt-in/opt-out mechanism (:smile:).

Beyond the two suggestions provided, it LGTM. 👍


/**
* Applies a maximum allowed length on OGNL expressions for security reasons.
*
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe helpful to identify when the feature was added:

 *
 * @since 3.1.26
 *

@@ -90,6 +91,23 @@
public abstract class Ognl
{

private static Integer expressionMaxLength;
Copy link
Contributor

Choose a reason for hiding this comment

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

You might want to declare it volatile, to ensure visibility of any change to all threads:
private static volatile Integer expressionMaxLength;

@yasserzamani
Copy link
Contributor Author

yasserzamani commented Oct 1, 2019 via email

@lukaszlenart
Copy link
Collaborator

I wonder if we should add this into OGNL 3.1.x, 3.2.x contains large changes around security.

@yasserzamani
Copy link
Contributor Author

Yes please because I would import this functionality into Struts 2.5 which uses OGNL 3.1 series. We need it in Struts to fix our security list recent last reports. We can think about this functionality and OGNL 3.2 relationship in future though.

@lukaszlenart
Copy link
Collaborator

The case is that those changes can impact users, also introducing a lot of those improvements in 2.5 can confuse users - that's why I wanted push them into 2.6

@yasserzamani
Copy link
Contributor Author

yasserzamani commented Oct 3, 2019 via email

@lukaszlenart
Copy link
Collaborator

It's not the case with changes itself but with versioning schema which doesn't reflect those changes - it's like having major improvements and still using inappropriate version number eg.: instead of Struts 2.5 use Struts 2.0.250 ;)

I'm ok with the current change but in the future I would opt to target the latest version for new improvements instead :)

@lukaszlenart lukaszlenart merged commit 11bc199 into orphan-oss:ognl-3-1-x Oct 3, 2019
@JCgH4164838Gh792C124B5
Copy link
Contributor

Hello @yasserzamani and @lukaszlenart .

It looks like this change was already merged before I was not to respond back concerning the "call once on application startup" considerations.

Even if the expressionMaxLength is only planned to be set once (during application startup), since the setter is public it will be valid to call it at any time (e.g. from a framework or an application calling a framework). If that happens then different threads could behave differently if it is just a "plain Integer" due to seeing different state for expressionMaxLength.

Here are some ways we could avoid that condition:

  1. Remove the applyExpressionMaxLength() method and make expressionMaxLength final and assign it's value using a static initializer block (less flexible but no synchronized or volatile required).
  2. Make expressionMaxLength volatile.
  3. Make expressionMaxLength an AtomicInteger.
  4. Make applyExpressionMaxLength() synchronized and use a synchronized getter for expressionMaxLength.

There's trade-offs for any of those, but 1) is similar to strategies used in OgnlRuntime to perform a "once-only" initialization of state.

What do you think ?

@yasserzamani
Copy link
Contributor Author

yasserzamani commented Oct 4, 2019 via email

@yasserzamani yasserzamani deleted the ognl_3_1_expressionMaxLength branch December 16, 2019 10:03
lukaszlenart added a commit that referenced this pull request Dec 16, 2019
cherry pick #79 and #82 and related commits
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.

3 participants