Skip to content

Introduce @FromModel as substitute to @ModelAttribute(binding=false) [SPR-15267] #19832

@spring-projects-issues

Description

@spring-projects-issues

Jochen Pier opened SPR-15267 and commented

Dear Spring-Team,

we often use @ModelAttribute to fetch Model-Attributes from the model in controller actions.

Example:

@RequestMapping("/testAtrribute")
public @ResponseBody String action(@ModelAttribute(name = "attr", binding=false) String attr) {
     return "Received from Model:" + attr;
}

The problem: If we forget the "binding=false" attribute, we get a really heavy security risk. Additionally, I think that getting something from the existing Model (which was constructed from former processing) or binding data to request are very different things, that should get different names.

So I suggest to introduce a new name and deprecate the "binding=false" attribute.
Name-suggestion: @FromModel(name="xyz")

Example:

@RequestMapping("/testAtrribute")
public @ResponseBody String action(@FromModel(name = "attr") String attr) {
     return "Received from Model:" + attr;
}

And maybe another suggestion:
Rename the parameter-binding annotation too.
So

@RequestMapping("/testAtrribute")
public @ResponseBody String action(@FromRequest("Book") Book book) {
     return "Received from Request:" + book.getTitle();
}

Thank you for spring!


Issue Links:

Metadata

Metadata

Assignees

Labels

status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions