fix(json-plugin): enforce @StrutsParameter in JSONPopulator.populateObject()#1651
Open
tranquac wants to merge 1 commit intoapache:mainfrom
Open
fix(json-plugin): enforce @StrutsParameter in JSONPopulator.populateObject()#1651tranquac wants to merge 1 commit intoapache:mainfrom
tranquac wants to merge 1 commit intoapache:mainfrom
Conversation
…bject() JSONPopulator.populateObject() uses Method.invoke() to set action properties from JSON input, bypassing the @StrutsParameter annotation check that ParametersInterceptor enforces for URL parameters. This allows mass assignment of unannotated properties via JSON request body. Add @StrutsParameter annotation check before Method.invoke() in JSONPopulator, gated by the existing struts.parameters.requireAnnotations setting. When enabled, only setters annotated with @StrutsParameter are populated from JSON input, consistent with ParametersInterceptor. Wire the requireAnnotations setting from StrutsConstants into JSONInterceptor -> JSONPopulator via @Inject.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
JSONPopulator.populateObject()in the struts2-json-plugin sets action properties via direct Java reflection (Method.invoke()) without checking the@StrutsParameterannotation. This bypasses the parameter allowlisting thatParametersInterceptorenforces for URL parameters, enabling mass assignment of unannotated properties via JSON request body.Changes
@StrutsParameterannotation check beforeMethod.invoke(). Whenstruts.parameters.requireAnnotationsis enabled and the setter lacks the annotation, the property is skipped with a debug log message.struts.parameters.requireAnnotationssetting via@InjectintoJSONPopulator.setRequireAnnotations().Impact
Without this fix:
With this fix, both pathways consistently enforce
@StrutsParameter.Test
A PoC application with 8 test cases demonstrates the bypass and fix. An action with
@StrutsParameter-annotated setter (setUsername) and unannotated setters (setRole,setAdmin) shows that JSON body sets unannotated fields before the fix, and blocks them after.