fix: OGNL Expression Language statement with user-controlled input #1340
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix the problem must ensure that OGNL expressions resolved and evaluated by Struts cannot originate from untrusted user input (i.e., header names, attribute names, etc.) unless robust validation is applied. The best way is to validate the OGNL expression specifically before parsing and evaluating, according to a whitelist of allowed expression patterns or types. This can be achieved by enhancing the OGNL guard with additional logic: if the expression is derived from a request header or attribute name, block its evaluation unless it passes strict validation (such as allowing only property lookup, no method calls, no reflection, and so forth).
To implement this:
OgnlUtil.ognlGet
, or, better, in the OgnlGuard itself), invoke this validation and block the expression if not safe.OgnlGuard
(isRawExpressionBlocked(String expr)
) and called during parsing as designed (but ensure its implementation), and possibly inOgnlUtil
to catch unsafe situations not covered by configuration.^\w+$
) and blocks expressions containing(
,)
, method calls, array access, or reflection (@
,#
,.
except for single property), etc.Only modify snippets from files you're shown, notably the interface and wherever its implementation is likely (within interface itself for default, but ideally in a concrete implementing class; add a strong default if none exists).
Refferences
Apache Commons OGNL
Proactively protect from OGNL Expression Injections attacks