Skip to content

fix(json-plugin): enforce @StrutsParameter in JSONPopulator.populateObject()#1651

Open
tranquac wants to merge 1 commit intoapache:mainfrom
tranquac:fix/json-plugin-strutsparameter-bypass
Open

fix(json-plugin): enforce @StrutsParameter in JSONPopulator.populateObject()#1651
tranquac wants to merge 1 commit intoapache:mainfrom
tranquac:fix/json-plugin-strutsparameter-bypass

Conversation

@tranquac
Copy link
Copy Markdown

@tranquac tranquac commented Apr 6, 2026

Summary

JSONPopulator.populateObject() in the struts2-json-plugin sets action properties via direct Java reflection (Method.invoke()) without checking the @StrutsParameter annotation. This bypasses the parameter allowlisting that ParametersInterceptor enforces for URL parameters, enabling mass assignment of unannotated properties via JSON request body.

Changes

  • JSONPopulator.java: Add @StrutsParameter annotation check before Method.invoke(). When struts.parameters.requireAnnotations is enabled and the setter lacks the annotation, the property is skipped with a debug log message.
  • JSONInterceptor.java: Wire the struts.parameters.requireAnnotations setting via @Inject into JSONPopulator.setRequireAnnotations().

Impact

Without this fix:

  • URL params to unannotated setters: BLOCKED (ParametersInterceptor enforces)
  • JSON body to same unannotated setters: BYPASSES (JSONPopulator ignores annotation)

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.

…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.
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.

1 participant