-
Notifications
You must be signed in to change notification settings - Fork 811
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-5468 Exempt ModelDriven Actions from @StrutsParameter requirement #1072
Conversation
if (action instanceof ModelDriven<?> && !ActionContext.getContext().getValueStack().peek().equals(action)) { | ||
LOG.debug("Model driven Action detected, exempting from @StrutsParameter annotation requirement and OGNL allowlisting model type"); | ||
// (Exempted by annotation on com.opensymphony.xwork2.ModelDriven#getModel) | ||
return hasValidAnnotatedMember("model", action, paramDepth + 1); |
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.
This conditional block and the added annotation on the ModelDriven
interface comprise the core fix
if (paramDepth >= 1) { | ||
allowlistClass(relevantMethod.getReturnType()); | ||
allowlistClass(propDesc.getPropertyType()); |
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.
Minor fix here to ensure the specific model type is allowlisted rather than the type declared in the interface (Object.class
) - thanks @lukaszlenart
@@ -44,7 +44,6 @@ public String getFoo() { | |||
/** | |||
* @return the model to be pushed onto the ValueStack after the Action itself | |||
*/ | |||
@StrutsParameter(depth = 2) |
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.
I removed all these annotations on ModelDriven
Action model getters as they are no longer required (not that they were being detected correctly previously)
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.
Replaced tabs with spaces to fix the janky formatting
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.
LGTM 👍
@@ -343,6 +360,14 @@ public Map<String, Pojo> getPublicPojoMapDepthTwo() { | |||
} | |||
} | |||
|
|||
class Pojo { | |||
static class ModelAction implements ModelDriven<Pojo> { |
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.
There is one more case where ModelDriven<Object>
is used and then getModel()
can return conditional model, either a List<Pojo>
or Pojo
itself. See that example
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.
Ah interesting, let me test this
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.
I think in such cases, the app developer should manually OGNL allowlist any required types, I'm not confident of a secure way to auto allowlist in this case
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.
Yeah, it can be tricky, but having such a note should be enough 👍
9a5080d
to
f6c17e9
Compare
Quality Gate passedIssues Measures |
WW-5468 Exempt ModelDriven Actions from @StrutsParameter requirement
WW-5468
The
@StrutsParameter
requirement was designed to protect against arbitrary getters and setters on the Action class from being invoked by users and/or attackers. However, if an Action is using a dedicated model object alongside theModelDrivenInterceptor
(which ensures the Action is not on the root of the value stack) much of this risk is mitigated. I suggest we exempt this specific scenario from requiring the@StrutsParameter
annotation.Closes #1071